cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Raharrelson
Level 3

InstallScript generate GUID's?

Is it possible to write an Installscript function to generate a GUID/Uniqueidentifier?
Labels (1)
0 Kudos
(6) Replies
RobertDickau
Flexera Alumni

There's nothing built in, but please search these forums for "generate GUID installscript" to see several code samples...
0 Kudos
Raharrelson
Level 3

Maybe I am just blind, but I searched these forums for code/suggestions to do this, and was unable to figure it out. If I used some of the old code, it would not compile in version 14. I also found where in around version 6, someone submitted a help idea to Macrovision, and supposedly they came up with an object "InstallShield.GUID" that would create a guid. Yet I try this and have no luck either.
0 Kudos
RobertDickau
Flexera Alumni

I haven't tried it, but does the code in [thread=171334]this thread[/thread] work? Or could you post the code that fails?

(There is a GenerateGUID method of the ISWiProject object, but that's available only at design/build time, and not run time.)
0 Kudos
Raharrelson
Level 3

Here are the error messages when it compiles...

C:\HelloWorld\InstallShield\HelloWorldInstall\script files\setup.rul(116) : error C8025: 'S_OK' : undefined identifier
C:\HelloWorld\InstallShield\HelloWorldInstall\script files\setup.rul(145) : error C8025: 'WideCharToMultiByte' : undefined identifier
C:\HelloWorld\InstallShield\HelloWorldInstall\script files\setup.rul(146) : error C8025: 'CP_ACP' : undefined identifier
C:\HelloWorld\InstallShield\HelloWorldInstall\script files\setup.rul(145) : error C8041: '(' : function type required
0 Kudos
RobertDickau
Flexera Alumni

Needs fine-tuning, error-checking, etc., but perhaps try:
[code]prototype OLE32.CoCreateGuid(POINTER);
prototype OLE32.StringFromGUID2(POINTER, BYREF STRING, LONG);

typedef GUID
begin
LONG Data1;
SHORT Data2;
SHORT Data3;
STRING Data4[8];
end;

GUID guid;
GUID POINTER pGuid;
WSTRING wszGuid[40];
STRING szGuid[40];

INT i;
NUMBER n;

function OnBegin( )
begin

guid.Data1 = 0;
guid.Data2 = 0;
guid.Data3 = 0;

pGuid = &guid;

// UseDLL("OLE32.dll");

CoCreateGuid(pGuid);
n = StringFromGUID2(pGuid, wszGuid, 40);

for i = 0 to (n - 1)
szGuid = wszGuid[i * 2];
endfor;

MessageBox("Try this one: " + szGuid, INFORMATION);

// UnUseDLL("OLE32.dll");

end;[/code]
0 Kudos
Raharrelson
Level 3

That worked just fine. I changed the function name and parameters based on what I was doing, so I am reposting the code here in case there are others trying to do the same thing. The ultimate goal was to set the 'MachineID' property to a guid.

Thanks!

export prototype SetMachineID(HWND);
export prototype CreateStringGUID(HWND);
prototype OLE32.CoCreateGuid(POINTER);
prototype OLE32.StringFromGUID2(POINTER, BYREF STRING, LONG);

typedef GUID
begin
LONG Data1;
SHORT Data2;
SHORT Data3;
STRING Data4[8];
end;



GUID guid;
GUID POINTER pGuid;
WSTRING wszGuid[40];
STRING szGuid[40];

INT i;
NUMBER n;

function SetMachineID(hWnd)
begin

guid.Data1 = 0;
guid.Data2 = 0;
guid.Data3 = 0;

pGuid = &guid;

UseDLL("OLE32.dll");

CoCreateGuid(pGuid);
n = StringFromGUID2(pGuid, wszGuid, 40);

for i = 0 to (n - 1)
szGuid = wszGuid[i * 2];
endfor;
MsiSetProperty(hWnd,"MACHINEID",szGuid);
//MessageBox("Try this one: " + szGuid, INFORMATION);

UnUseDLL("OLE32.dll");

end;
0 Kudos