GUID - Generate in Windows

How to Generate a New GUID or UUID in Windows

information   Information
GUID (or UUID) is an acronym for 'Globally Unique Identifier' (or 'Universally Unique Identifier'). The term GUID is generally used by developers working with Microsoft technologies, while UUID is used everywhere else.

A GUID is represented as a 32-character hexadecimal string, such as {dcab32b8-e5ec-4f09-af89-44634bc7a04d}, and is usually stored in the form of a 128bit integer. It's nearly impossible for the numbers generated for the GUID to have two numbers repeated making them unique.

For more information about GUID, see:

This tutorial will show you how to quickly generate a new GUID (UUID) in XP, Vista, Windows 7, and Windows 8.

Note   Note
Windows 7 and Windows 8 comes with the PowerShell feature included.

In XP and Vista, you will need to download and install PowerShell.





OPTION ONE

To Generate a New GUID in PowerShell


1. Open PowerShell, copy and paste either command below, and press Enter.​
[guid]::NewGuid()
OR
[guid]::NewGuid().ToString()
2. The generated 32-character number will be the new GUID.​
PowerShell_GUID.png
PowerShell_GUID-2.png






OPTION TWO

To Generate a New GUID in Command Prompt



Note   Note
This option uses a PowerShell command in a command prompt, so you will still need to have PowerShell installed (XP and Vista).

If you like, you can also use the command below in a .bat or .cmd file.


1. Open a command prompt, copy and paste either command below, and press Enter.​
powershell -Command "[guid]::NewGuid()"
OR
powershell -Command "[guid]::NewGuid().ToString()"
2. The generated 32-character number will be the new GUID.​
Command_GUID-1.png
Command_GUID-2.png


That's it,
Shawn


 

Attachments

  • Services.png
    Services.png
    2.7 KB · Views: 292
Last edited:
Why would you want to do this though? Just for VMs?

Programmers use Guids much more than users. It avoids name collisions. For example I can create a named memory mapped file, or mutex, or semaphore. Programmers used to do stuff like make up names they thought would be unique. Example, MyVeryOwnUniqueSeamaphoreNamexxxxx. If someone else just happened to come up with the same name you could have 2 programs fighting over the resource. But if I use a Guid generator to make this name, MySemaphore88c1f6a9-e063-4e5c-8161-c824ac987896 then no other generated guid should produce the part after MySemaphore. I just stuck MySemaphore on there because kernel object names, iirc, are not supposed to start with a number but a character.
 
OK thanks - I was thinking of the HDD GUID which you have to change for VMs. This is more like a random number generator for the strings we see in DCOM etc then if I understand you correctly.

EDIT: I am a programmer actually but on IBM i not windows. There you make up names for objects and are confined to 10 characters and only one directory level (well sort of). Guess what - you do get duplicates. Think how many programmers when writing a payroll program and confined to 10 characters will call it "PAYROLL". Almost all of them do.
 
Yeah, Guid was created for COM/DCOM stuff. Depending how they are used sometimes they are called CLSID or whatnot. ActiveX is a good example. In Windows there's an associative array object for scripting named Scripting.Dictionary. But in the registry the name is associated with a CLSID.

And yeah I can believe over 90% named it PAYROLL. :) That's like the old unix linkers that only had 6 character names. Linux is still burdened with the short program names for standard commands as a legacy.
 
Hello Dragon Drop,

Yes, you could assign a GUID to open a folder when referenced. For example, you would reference the GUID when adding a folder or item to This PC or Control Panel.

What did you have in mind? :)
 
I mean, if I've created a new GUID and I want it to represent a certain folder, how do I TELL Windows which folder I want it to represent? Do I have to create a new Registry key or something?
 
Yep, it would involve manually adding the GUID and other keys to the registry for this.

What were you wanting to do this for the folder with the GUID? It all depends for what you may need to do in the registry. There may also be an alternative for the folder.
 
In all my experimenting with Windows, I've had occasion to use GUID's in several ways. But what I was thinking of at the moment was the special kind of shortcut links that you can create by using a GUID in the folder name. They create "expanding menus" when used in a toolbar. But you can only do that with a folder that has a GUID. An ordinary folder shortcut won't expand into a menu.
 
Well, here's an example of my E:\Images folder being referenced to a GUID in the registry to help. This would be the .reg file to add it for this.

Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{bcf54cb8-7ae3-4fa6-9ec5-573ef99f9912}]
@="[COLOR=#ff0000][B]Folder Name[/B][/COLOR]"

[HKEY_CLASSES_ROOT\CLSID\{bcf54cb8-7ae3-4fa6-9ec5-573ef99f9912}\Shell\Open\Command]
@="explorer [COLOR=#ff0000][B]E:\\Images[/B][/COLOR]"


Once added, here's an example of a shortcut target using the GUID to open the folder.


explorer.exe shell:::{bcf54cb8-7ae3-4fa6-9ec5-573ef99f9912}
 
For some reason, the "Command" subkey wasn't getting any value. I fixed it by typing the value into the Registry myself, and now the GUID works when used as in your example.

Unfortunately, it still doesn't work the way I hoped it would -- i.e. when used in a folder's name to create a link. I've noted before that some GUID's work that way and some don't, though I still don't understand why. Anyway, thanks for your assistance. :)
 
Anytime. Is there any way to use the normal full path of the folder as the target of a shortcut for what you were wanting to do?
 
In general, regular shortcuts are fine. But when you have a toolbar, like that one I designed with many items in it for that other tutorial, a shortcut won't open into a cascading sub-menu in the toolbar, unless it's the special kind of shortcut that I used there, made with a folder name like "AdminTools.{d20ea4e1-3957-11d2-a40b-0c5020524153}" and so on. I was hoping that kind of folder name would work with a GUID that I created, but it apparently doesn't.
 
Back
Top