Quickly Create a Text File from the Windows Command Prompt

Posted on January 8, 2009 by Daniel Petri in Windows Server with

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.

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:

Simple, easy, works also in DOS.

Method #2 – Using ECHO command:

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):

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):



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:

Register for this Webinar

Real World Solutions with Virtual Reality
Free Whitepaper Download

VR is being utilized for a surprising number of vital business functions today. In this white paper, you’ll get an overview of VR technology and see how it’s a vital part of many industries today.

Download the free whitepaper!