Home » Development, Other Languages, Snippets » Generate Random GUID by script

Generate Random GUID by script

I had a task in hand to read and update a few registry settings. Since the registry keys might change in future and some more changes might be required on the fly, I decided to go with script instead of a config driven executable. Also, one compelling reason was that it has been some time since I did some good amount of scripting so I wanted to brush my scripting skills again.

Initially I wanted to use Windows Powershell but I couldn’t proceed far with it as the scripts require special privilege and security certificates to run. I don’t want to trouble my client with these hassles and ask him to install PowerShell. I am still exploring easy ways to allow a PS script to run without previliges and certificate/signing frustrations. Finally I settled with JScript which I have used extensively for my own purpose.

One of the requirement was to generate unique GUIDs. I looked around for generating unique GUID values using JScript or VBScript but couldn’t find something useful. I am not looking for re-writing a logic to generate a GUID with a specified pattern with all the scemantics. I just want a simple object which exposes the functionality to generate a new unique GUID and the object must be natively supported so that my client won’t require to install something additionally.

As usual after exploring all the way I stumbled across Microsoft Scripting Guy and the solution was a piece of cake ! Following is the answer

var typeLib = new ActiveXObject("Scriptlet.TypeLib");
var newGuid = typeLib.Guid;

Isn’t it easy ?

Bookmark and Share

Development, Other Languages, Snippets , , , , , ,

No Comments to “Generate Random GUID by script”

Leave a Reply

(required)

(required)