I want to generate GUID strings in VBScript. I know that there's no built-in function in VBScript for generating one. I don't want to use random-generated GUIDs. Maybe there is an ActiveX object that can be created using CreateObject() that is sure to be installed on (newer) Windows versions that can generate a GUID?
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.
A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required.
It's possible to generate an identical guid over and over. However, the chances of it happening are so low that you can assume they are unique.
Insert a new GUID by invoking the command under the Edit top-level menu or hit CTRL+K,Space . If Visual Studio is unable to insert the GUID, it will be copied to the clipboard so you can easily paste it in manually. When a GUID is copied to the clipboard, a notification will be displayed in the status bar.
Function CreateGUID Dim TypeLib Set TypeLib = CreateObject("Scriptlet.TypeLib") CreateGUID = Mid(TypeLib.Guid, 2, 36) End Function
This function will return a plain GUID, e.g., 47BC69BD-06A5-4617-B730-B644DBCD40A9
.
If you want a GUID in a registry format, e.g., {47BC69BD-06A5-4617-B730-B644DBCD40A9}
, change the function's last line to
CreateGUID = Left(TypeLib.Guid, 38)
How Can I Create a GUID Using a Script? (in: Hey, Scripting Guy! Blog) says this:
Set TypeLib = CreateObject("Scriptlet.TypeLib") Wscript.Echo TypeLib.Guid
However, note that Scriptlet.TypeLib.Guid returns a null-terminated string, which can cause some things to ignore everything after the GUID. To fix that, you might need to use:
Set TypeLib = CreateObject("Scriptlet.TypeLib") myGuid = TypeLib.Guid myGuid = Left(myGuid, Len(myGuid)-2) Wscript.Echo myGuid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With