Alex Rivera | Logout

Generate GUID in Windows with batch file

Asked 2010-11-30T11:54:54.137
71

How can I generate a GUID in a batch file running using the commandline in Windows?

Edit
Report

1 Answer

11

There is no built-in command available that does that. Either write your own, or get an existing one.

A simple program that outputs a GUID to the console could be written using C#:

class Program
{
    static void Main(string[] args)
    {
        System.Console.WriteLine(System.Guid.NewGuid().ToString());
    }
}

Place the above snippet in a file name guidgen.cs and then compile it using the following command line (.NET Framework 2.0 would have to be installed on your system):

%WINDIR%\Microsoft.NET\Framework\v2.0.50727\csc.exe guidgen.cs 

This will create an executable named guidgen.exe.

answered 2010-11-30T12:00:07.450

Your Answer