n0t0r10u5 Posted October 6, 2010 Share Posted October 6, 2010 Hello Forum, I'm new to using Autoit and your help will be very much appreciated. I have written a script to install software automatically on to a PC where the user doesn't have admin rights, when testing the script with my account which does have admin rights the script works fine, the setup.exe is called and runs as the specified account. However, when run as a domain user without admin rights the script doesn't call the setup.exe and the msgbox is shown at the end. The user's do have access to the network location and the secondary logon (RunAs) service is enabled. The script is below, thanks in advance for your help ; Fill in the username and password appropriate for your system. Local $sUserName = "username" Local $sPassword = "password" Local $sDomain = "DOMAIN" Local $sLocation = "\\MYserver\setup.exe" ;Run program as another user RunAsWait($sUserName, $sDomain, $sPassword, 0,($sLocation), @SystemDir,"","") ; Show a message. MsgBox(0, "", "Completed.") Link to comment Share on other sites More sharing options...
mentor Posted October 6, 2010 Share Posted October 6, 2010 Hi, I am having problems with this command as well but I am unable to run the command at all. I am using a variable to capture the output to see if the command has ran OK but it returns a zero every time. What am I doing wrong? Some help would be great. I am new to AutoIT. $test = RunAsWait("user", "domain", "password", 0, "filepath", @TempDir,"","") Link to comment Share on other sites More sharing options...
mentor Posted October 6, 2010 Share Posted October 6, 2010 n0t0r10u5, I found a solution to my problem here - http://www.autoitscript.com/forum/index.php?showtopic=118567&st=0&p=824933&hl=runaswait&fromsearch=1&#entry824933 I was using an MSI file which is why it wouldn't run. I had to add 'Msiexec.exe /I' before the path. This is my current working script - ; script to install Express metrix agent $username = "administrator" $domain = "domain" $password = "password" $program = 'Msiexec.exe /I "\\Server\path\install.msi" /qn' ;$test = RunAsWait ($username, $domain, $password, 2, $program, @TempDir) RunAsWait($username, $domain, $password, 0, $program, @SystemDir," "," ") Hope this helps. Q Hello Forum, I'm new to using Autoit and your help will be very much appreciated. I have written a script to install software automatically on to a PC where the user doesn't have admin rights, when testing the script with my account which does have admin rights the script works fine, the setup.exe is called and runs as the specified account. However, when run as a domain user without admin rights the script doesn't call the setup.exe and the msgbox is shown at the end. The user's do have access to the network location and the secondary logon (RunAs) service is enabled. The script is below, thanks in advance for your help ; Fill in the username and password appropriate for your system. Local $sUserName = "username" Local $sPassword = "password" Local $sDomain = "DOMAIN" Local $sLocation = "\\MYserver\setup.exe" ;Run program as another user RunAsWait($sUserName, $sDomain, $sPassword, 0,($sLocation), @SystemDir,"","") ; Show a message. MsgBox(0, "", "Completed.") Link to comment Share on other sites More sharing options...
n0t0r10u5 Posted October 7, 2010 Author Share Posted October 7, 2010 Hi Mentor, Thanks for the reply, however I'm using a setup.exe not a msi, I have tried your suggestion by converting the exe to a msi without any luck, I get an error when running the msi. Thanks Again Link to comment Share on other sites More sharing options...
AdamUL Posted October 7, 2010 Share Posted October 7, 2010 (edited) Try DriveMapAdd to connect the network share before running the EXE. Your script updated.; Fill in the username and password appropriate for your system. Local $sUserName = "username" Local $sPassword = "password" Local $sDomain = "DOMAIN" Local $sShare = "\\MYserver" Local $sLocation = $sShare & "\setup.exe" ;Connect to network share. DriveMapAdd("", $sShare, 0, $sDomain & "\" & $sUsername, $sPassword) ;Run program as another user. RunAsWait($sUserName, $sDomain, $sPassword, 0, $sLocation, $sShare, "", "") ; Show a message. MsgBox(0, "", "Completed.") ;Disconnect from the network share. DriveMapDel($sShare)AdamEdit: Replaced @SystemDir with $sShare in the RunAsWait function. Edited October 7, 2010 by AdamUL Link to comment Share on other sites More sharing options...
BrewManNH Posted October 7, 2010 Share Posted October 7, 2010 @ n0t0r10u5 Instead of using @SystemDir, which the user might not have write access to, you might want to try using @TempDir which they definitely will have write access to. @AdamUL The RunAs command sometimes has issues running programs on a mapped drive so that brings up another whole load of problems. I just discovered this yesterday about the RunAs command that I didn't realize before. Better to just point to the share location without mapping a drive to it. 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 Link to comment Share on other sites More sharing options...
n0t0r10u5 Posted October 7, 2010 Author Share Posted October 7, 2010 Thanks for all the help, I have now resolved the issue, I moved the folder containing the setup.exe to a top level share after reading in the forum that autoit sometimes doesn't like long UNC paths. Thanks again. Link to comment Share on other sites More sharing options...
AdamUL Posted October 7, 2010 Share Posted October 7, 2010 @BrewManNH When you had trouble using RunAs with DriveMapAdd, did you pass a drive letter or a blank string for the "device" parameter? Passing a blank string as quoted in the help file: If you pass a blank string for this parameter a connection is made but not mapped to a specific drive. If you look at the code I posted, that is what I did. DriveMapAdd("", $sShare, 0, $sDomain & "\" & $sUsername, $sPassword) It works the same as RunWait('net use "' & $sShare & '" /USER:' & $sDomain & '\' & $sUserName & ' ' & $sPassword, @SystemDir, @SW_HIDE) but with less typing. I have not had trouble with either solution, but prefer using DriveMapAdd with a blank string to connect to a network share. Adam Link to comment Share on other sites More sharing options...
BrewManNH Posted October 7, 2010 Share Posted October 7, 2010 If you look HERE you will see that MS acknowledges that you might have problems running programs on a mapped drive under RunAs. If you look at the thread "Fun With Batch Files" you will see how not using a mapped drive fixed the OPs problem. Just thought I'd give a heads up regarding this because it's actually easier to not map the drive first and then have to delete it, especially if the script end prematurely and never gets to the deleting part. 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 Link to comment Share on other sites More sharing options...
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