KSum Posted June 6, 2013 Posted June 6, 2013 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_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem EnableInstallerDetection=0 HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem 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. expandcollapse popupDim $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
BrewManNH Posted June 6, 2013 Posted June 6, 2013 Is G: by any chance a mapped drive? If it is, then the credentials you're using in the RunAs won't have that drive letter. Use a UNC path instead if that's the case. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
KSum Posted June 7, 2013 Author Posted June 7, 2013 Tried a UNC path as well. Thought I tried it before, so my apologies for not including that. I did just try it to verify and I am sorry to say that it did not do the trick.
orbs Posted June 7, 2013 Posted June 7, 2013 first, BrewManNH has a very good point: never use mapped drives when RunAs, always UNC, even when using flag 4. if you suspect UAC is the issue, there are plenty of articles on how to disable it. try to disable UAC, if only for troubleshooting, so you can focus on the right track. i would check the following: in general (not always!), error code 1 is "File Not Found". so, does the local user "Administrator" have enough permissions to the network source? also, is the local user "Administrator" enabled at all? (since Vista, by default it's disabled). Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff
Solution KSum Posted June 13, 2013 Author Solution Posted June 13, 2013 So the answer was the combination of needing to use the UNC and also using an account that had access to the network share. I also had to change the "IF" statement to also check that @error was not 0 as the PID returned in some cases was 0 even though the executable ran. I tried using @ScriptDir to get the location of the current script as all the rest is in that location or subfolders, but it seemed to return a mapped drive path and not the UNC path. (See my thread on this here: '?do=embed' frameborder='0' data-embedContent>>) Ithought it returned a UNC in another script from just the other day. So my updated code from above looks something like this: expandcollapse popupDim $pid Dim $MsiCommand Dim $MsiCommandVariable Dim $InstallExecutableName Dim $ScriptPath Dim $MyPath Local $sUserName = "Networkadministrator" Local $sPassword = "Networkadminpassword" Local $sDomain = "NetworkDomain" 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 ;Get the network location of the script. All executables are under this folder. $ScriptPath = @ScriptDir ;Make sure it is a UNC and not a mapped drive if StringInStr($ScriptPath, ":") > 0 Then $MyPath = _WinNet_GetUniversalName(@ScriptDir) ;An array is returned and the first value is the full UNC path $ScriptPath = $MyPath[0] EndIf ;Install the latest version ; Set the variables to run the proper command $InstallExecutableName = "ProjectWise Explorer Bundle V8i (SELECTseries 4) (" & $MsiCommandVariable & ").exe" $MsiCommand = '"' & $ScriptPath & '\Client\08_11_11_559\explorerbundle\' & $InstallExecutableName & '" /install /quiet /norestart /log ' & @TempDir & '\PWiseInstall.log' ;Run the command as an administrator $pid = RunAsWait($sUserName, $sDomain, $sPassword, 4, $MsiCommand, @TempDir, @SW_ENABLE) ;Did the RunAs run properly? If $pid = 0 AND @error <> 0 Then MsgBox( 4096, "ProjectWise Installer", "Unable to Install Program. RunAs failed. Error = " & @error) MsgBox( 4096, "ProjectWise Installer", "Installation Aborted. ") Exit Else ProcessWaitClose($InstallExecutableName) MsgBox(0, "MSI Command", "Command Run Succesfully.") EndIf exit Note that this has been put together for the thread and is not actually tested, but a paraphrase of the entire script.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now