I have a InstallShield InstallScript project that needs to be ran with administrative rights. In a nutshell from the InstallShield I need to:
- Detect if the installer currently has administrative privileges.
- If setup.exe is not being ran with admin rights spawn a new instance of the setup.exe using a local admin account/password then close the old (non-privledged) setup.exe.
So far I know I can do something like this to find if I have admin rights:
//---------------------------------------------------------------------------
// Run As Utilities Library
//---------------------------------------------------------------------------
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
//---------------------------------------------------------------------------
export prototype UserRightsCheck();
function UserRightsCheck()
begin
MessageBox(INSTALLPROPERTY_INSTALLLOCATION, INFORMATION);
if(USER_ADMINISTRATOR) then
MessageBox("hello Admin", INFORMATION); // testing only
// do nothing we are an admin
else
MessageBox("hello user", SEVERE); // testing only
RunAsAdmin();
endif;
end;
export prototype RunAsAdmin();
function RunAsAdmin()
begin
STRING username = "myUserID";
STRING password = "myPassword";
STRING filepath = INSTALLPROPERTY_INSTALLLOCATION;
RunAsUserAccount(username,password,filepath);
end;
export prototype RunAsUserAccount();
function RunAsUserAccount()
STRING username;
STRING password;
STRING filepath;
begin
/*
Is this the best way to do this? this is the function I need help with
This seems like a hack
*/
if ( SYSINFO.WINNT.bWinXP ) then
LAAW_SHELLEXECUTEVERB = "open"; // target PC is on Windows XP
else
LAAW_SHELLEXECUTEVERB = "runas"; // Windows 7 (or Vista)
endif;
LaunchApplication(
filepath
,"" // Arguments
,"" // Directory
,SW_NORMAL // Use Window Mode
,0
,LAAW_OPTION_WAIT_INCL_CHILD | LAAW_OPTION_USE_SHELLEXECUTE
);
end;
How do I relaunch the installer though? This can be done in Wise Package Studio and many other tools but I haven't found the answer how to do it in this one yet.
I know I could probably do a runas.exe or psexec.exe but that feels like a hack and sounds like a poor practice. After about a day of reading I am still not sure how to do this though.
Could someone please point me in the right direction of the proper way to do this in InstallShield?