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?
+4
A:
Hey, Scripting Guy! How can I create a GUID using a script? says this:
Set TypeLib = CreateObject("Scriptlet.TypeLib")
Wscript.Echo TypeLib.Guid
...but also see this question for a potential problem with that.
Roger Lipscombe
2009-06-09 08:05:57
Thanks! I like the "Hey, Scripting Guy!" link!
vividos
2009-06-09 21:50:24
+2
A:
Set tlib = Server.CreateObject("Scriptlet.TypeLib")
strGuid = tlib.Guid
BobbyShaftoe
2009-06-09 08:07:35
+4
A:
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)
Helen
2009-06-09 08:12:16