Does the RunAs() function work in Windows 7, 64 bit? I have tried many ways to get the below code to run after compiling to an exe and I keep getting an @error code of 1. I have tried an AutoIt compiled exe as the target program and get the same error. When I use the straight Run() function for the program, under an administrator' account, it runs fine. I have checked the login and password I am using and they are good. I have tried putting the local computer name in the username as opposed to passing it as the domain as well as no domain name at all. I have also tried the ShellExecute as shown below. I have replaced all instances of @TempDir with a folder on the local C drive that has read and write rights for everyone. The Secondary Logon (RunAs) service is enabled. I believe UAC is on, and the following registry keys are set to 0:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System EnableInstallerDetection=0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System ConsentPromptBehaviorAdmin=0
So what might I be missing or how would I run this as a local computer's administrator? Do I have to use a second program, such as cpau instead? I would rather not add something like that on here if I don't have to.
Dim $pid Dim $MsiCommand Dim $MsiCommandVariable Dim $InstallExecutableName Local $sUserName = "administrator" Local $sPassword = "adminpassword" Local $sDomain = @ComputerName ;Tried these as well with no success ;~ Local $sUserName = @ComputerName & "\administrator" ;~ Local $sDomain = "" If @OSArch = "X86" Then ;32bit. Set a variable for the MSI command $MsiCommandVariable = "x86" ElseIf @OSArch = "X64" Then ;64bit. Set a variable for the MSI command $MsiCommandVariable = "x64" EndIf ;Install the latest version ; Set the variables to run the proper command $InstallExecutableName = "ProjectWise Explorer Bundle V8i (SELECTseries 4) (" & $MsiCommandVariable & ").exe" $MsiCommand = '"G:\uSTN\Install_new\Bentley\V8i\ProjectWise\Client\08_11_11_559\explorerbundle\' & $InstallExecutableName & '" /install /quiet /norestart /log ' & @TempDir & '\PWiseInstall.log' ;Run the MSI command as an administrator ;This method works when the account running the compiled script has admin rights ; $pid = Run($MsiCommand, @TempDir, @SW_ENABLE) ;These methods do not work ;~ $pid = ShellExecute("G:\uSTN\Install_new\Bentley\V8i\ProjectWise\Client\08_11_11_559\explorerbundle\" & $InstallExecutableName, "/install /quiet /norestart /log ", @TempDir & "\PWiseInstall.log", "RunAs") $pid = RunAs($sUserName, $sDomain, $sPassword, 4, $MsiCommand, @TempDir, @SW_ENABLE) ;Did the RunAs run properly? If $pid = 0 Then ; @error has been 1 every time I run this, even if I substitute an AutoIt Ciompiled Script MsgBox( 4096, "ProjectWise Installer", "Unable to Install Program. RunAs failed. Error = " & @error) MsgBox( 4096, "ProjectWise Installer", "Installation Aborted. " & $MsiCommand) Exit Else ProcessWaitClose($InstallExecutableName) MsgBox(0, "MSI Command", "Command Run Succesfully.") EndIf exit
Regards,
Karl