Sunday, October 26, 2008

Creating a Windows Registry entry in InstallShield script

Hi,

Now we will try to create a Registry entry from Installshield script. Here I am giving a function which I have used in my projects and its worked fine.

function CreateRegistry(sKey, sKeyName, sKeyValue)

int iResult;

STRING sClass;

begin

Disable(LOGGING);

WriteLog("Trying to create registry. Reg Key: "+sKey+ " ,KeyName: "+sKeyName+" ,KeyValue: "+sKeyValue);

try

sKey="SOFTWARE\\"+sKey;

RegDBSetDefaultRoot( HKEY_LOCAL_MACHINE );

sClass = "FPClass";

if( RegDBCreateKeyEx(sKey,sClass)< 0 ) then

WriteLog("Failed to create registry key.");

MessageBox("Fail to create key for application",INFORMATION);

else

WriteLog("Registry Key successfully created. Trying to create Registry Value.");

iResult = RegDBSetKeyValueEx(sKey,sKeyName,REGDB_STRING_EXPAND,sKeyValue,-1);

if(iResult > 0) then

WriteLog("Failed to creat Registry value");

MessageBox("Unable to create Registry",INFORMATION);

else

WriteLog("Registry value successfully created.");

endif ;

endif;

catch

WriteErrorLog("Unable to create registry key. The key is "+sKey+" and name is "+sKeyName);

MessageBox("Unable to create Registry", INFORMATION);

endcatch;

Enable(LOGGING);

end;


Hope this will help someone somewhereJ.

2 comments:

Anonymous said...

Nice one...thank you very much for sgaring...

Anonymous said...

Thank you for posting!