A geek on his way to IT pragmatism

Main menu

Post navigation

4 ways to generate a GUID

GUIDs have a lot of common uses : primary keys in distributed databases and caches, temporary file and directory names, identifiers for types in the COM world…

You can generate them using a wealth of tools, depending on your situation.

1) With GuidGen

GuidGen is an interactive tool bundled with Visual Studio and the Windows SDK : on my computer I’ve one located in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools and another in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin.

You can run GuidGen directly or you can run it from Visual Studio :

Visual Studio 2010 Create GUID

Both will display the same small UI with commands for generating new GUIDs in different formats and copying them to the clipboard.

GuidGen in action

2) With Guidgen Console

If you want a non-interactive (ie without UI) tool to be used in your batch scripts for instance you can use GuidgenConsole.

Here is a sample :

C:\>C:\opt\GuidGen\GuidGen.exe
f78f217c-8efc-4974-abae-ffb3bce4d6c8

3) With online tools

If you need interactive generation from anywhere you can use an online generator like :

4) With the .Net library

The most powerful tool is of course the .Net library itself, where GUIDs are represented by the Guid value-type, which is often used by the aforementioned tools.
If you need to generate GUIDs from .Net code this is the way to go.