Windows Server

Quickly Create a Text File from the Windows Command Prompt

How do I quickly create a text file from the Windows Command Prompt?

Old, used, boring, but still a nice tip. This article explains how to easily create a text file from the Command Prompt (CMD) in Windows 2000/XP/2003/Vista.

One of the things I usually do with my own machines is to burn a file called SN.txt on the root of the installation CD, with the right CD Key inside. Then, whenever I need to install Windows from that CD I have the CD Key readily available.

Sponsored Content

Passwords Haven’t Disappeared Yet

123456. Qwerty. Iloveyou. No, these are not exercises for people who are brand new to typing. Shockingly, they are among the most common passwords that end users choose in 2021. Research has found that the average business user must manually type out, or copy/paste, the credentials to 154 websites per month. We repeatedly got one question that surprised us: “Why would I ever trust a third party with control of my network?

However, this time, when I installed Windows Vista, I used an ISO image (How to Write ISO Files to CD) that I obtained from Microsoft. I had the CD Key on a separate file, but I didn’t think to write it into the ISO file.

So last night, when I installed the latest build of Windows Vista on a Virtual Machine, I had to manually enter the CD Key during the installation process. Typing this CD Key wasn’t hard to do, but because it was past midnight I kept missing a letter or entering an “8” instead of a “B” and so I found myself typing the CD Key of the machine over and over again.

What I needed was a way to create a text file inside the VM, with the CD Key in it, and put it on the root of the VM’s hard disk, then to be able to just copy the file’s contents (the CD Key) to the installation prompt.

There are several methods of creating text files from the CMD without using any 3rd-party tools, and I thought it was a good time to remind you of some of them:

Lamer note: The CD Key in all of the following examples is bogus, false, not true, don’t try to use it.

Method #1 – Using COPY command:

​C:'>copy con SN.txt
Product Key: TJQAW-VG29Y-G194Y-E7KRT-BYH9G

 1 file(s) copied.

Simple, easy, works also in DOS.

Method #2 – Using ECHO command:

​C:'>echo Product Key: TJQAW-VG29Y-G194Y-E7KRT-BYH9G > SN.txt

Usually works under most conditions.

Note the “>” sign after the required text and before the filename. This is very useful whenever you want to pipe any command output to a file.

Method #3 – Using NOTEPAD (if available):

​C:'>notepad SN.txt

Simple, doesn’t work if you’re in an environment where no GUI tools are available.

You will get an error saying that the file does not exist (if it’s a new one it won’t), and would you like to create it. Say Yes.

In the new Notepad window just type or paste the required information, and save the file.

Method #4 – Using COPY and NOTEPAD (if available):

​C:'>copy NUL SN.txt

 1 file(s) copied.

Like the previous option, here too you must have access to Notepad.

From there, use the same command as found in method #3 to open Notepad with the text file. Since it’s already there it won’t say that the file is not found.

In the new Notepad window just type or paste the required information, and save the file.


There are probably a zillion other methods, if you know of any simple, one line, easy method of creating a simple text file in case you need it right here and right now, please do drop me a line and I’ll gladly feature it here.


Related articles

You might also want to read the following related articles:

Related Topics:


Don't have a login but want to join the conversation? Sign up for a Petri Account

Comments (0)

Leave a Reply

13 Email Threat Types to Know About Right Now

As email threats evolve and multiply, keeping track of them all—and staying protected against the many different types—becomes a complex challenge. Today, that requires more than just the traditional email gateway solution that used to be good enough.

In this eBook you will learn:

  • What are the most common and challenging email attacks for organizations?
  • How to defend against sophisticated email threats, such as spoofing, social engineering, and fraud
  • How to protect employees at the inbox level with the right technologies and security-awareness training
  • How to use a multilayered protection strategy to reduce susceptibility to email attacks and better defend your business and employees

Sponsored by: