How to generate a GUID in VBScript?

后端 未结 4 523
小蘑菇
小蘑菇 2020-12-08 14:28

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 the

相关标签:
4条回答
  • 2020-12-08 14:46

    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
    
    0 讨论(0)
  • 2020-12-08 14:54
    Set tlib = Server.CreateObject("Scriptlet.TypeLib")
    strGuid = tlib.Guid
    
    0 讨论(0)
  • 2020-12-08 14:56
    ' Returns a unique Guid on every call. Removes any cruft.
    Function CreateGuid()
        CreateGuid = Left(CreateObject("Scriptlet.TypeLib").Guid,38)
    End Function
    
    0 讨论(0)
  • 2020-12-08 15:00
    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)
    
    0 讨论(0)
提交回复
热议问题