Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate GUID in Windows with batch file

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

like image 956
Pratik Avatar asked Nov 30 '10 11:11

Pratik


People also ask

How do I create a GUID file?

Open Visual Studio->Tools->Create GUID->Registry Format->New GUID. It will create a new GUID every time you click New GUID.

How do I generate a new GUID in PowerShell?

To Generate a GUID in Windows 10 with PowerShell, Type or copy-paste the following command: [guid]::NewGuid() . This will produce a new GUID in the output. Alternatively, you can run the command '{'+[guid]::NewGuid(). ToString()+'}' to get a new GUID in the traditional Registry format.

How do I make a global unique identifier?

Users do not need to rely on a centralized authority to administer GUIDs, as anyone can use a generation algorithm to create a GUID. Individuals and organizations can create GUIDs using a free GUID generator that is available online. An online generator constructs a unique GUID according to RFC 4122.


2 Answers

The Windows SDK comes with a tool called uuidgen (if you have Visual Studio, you'll have the Windows SDK, and you need to run the Visual Studio Command Prompt to set proper paths).

C:\>uuidgen 

This will output a new GUID, e.g.

cc23b318-156e-473f-aa6e-517bf091a0f0

like image 145
Tim Robinson Avatar answered Sep 27 '22 02:09

Tim Robinson


Try this if you have powershell environment.

FOR /F %a IN ('POWERSHELL -COMMAND "$([guid]::NewGuid().ToString())"') DO ( SET NEWGUID=%a ) 

Then ready Guid value from %NEWGUID%

like image 22
user2441603 Avatar answered Sep 23 '22 02:09

user2441603