Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Generating a GUID in VBScript

220 views
Skip to first unread message

Ernesto Marquina

unread,
Nov 18, 1999, 3:00:00 AM11/18/99
to
Hi there, anyone knows how to generate a GUID (Global Unique IDentifier) in
VBScript?, i want to generate those kinds of ids to assure that it will be
unique (like CLSIDs)

thanks!!

Ernesto Marquina.
OSMOS S.A
------------------------------------------------------------
Beware of low-flying butterflies.
------------------------------------------------------------


Adrian Forbes

unread,
Nov 18, 1999, 3:00:00 AM11/18/99
to
You can't. There is an API to create a GUID but you can't call APIs from
VBScript.

Michael Harris

unread,
Nov 18, 1999, 3:00:00 AM11/18/99
to
Here's a rather strange looking solution, but it works.  It takes advantage of the fact an instance of a Windows Script Component that does _not_ have an id attribute on it's <component> element can be queried with VBScript's TypeName function.  This will return the formatted IID of that instance of the component (which is dynamically generated by scrobj.dll for every new instance of a WSC component).  If it had an id attribute then that's what TypeName would return for every instance.
 
For example, create and register the following...
 
==== uuid.wsc ====
 
<?xml version="1.0"?>
<component>
<registration
 description="UUID"
 progid="UUID.WSC"
 version="1.00"
>
</registration>
</component>
 
Now create and run the following test script.  Note that a reference to the instance of uuid.wsc created is never kept - you have to create a new instance for each GUID you want.
 
==== uuid.vbs ====
 
guid = typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
guid = guid & vbcrlf & typename(createobject("uuid.wsc"))
msgbox guid


--
Michael Harris
Ernesto Marquina <emar...@osmos.com> wrote in message news:OIVxD4dM$GA.248@cppssbbsa05...
0 new messages