hacksawbob Posted January 12, 2010 Posted January 12, 2010 (edited) Hopefully quite simple but I have been trawling the forum for at least the last hour. I am trying to run a batch file at logon as an admin by a non admin user. RunAs(adminuser, @computername, XXXXPASS, 0, \\server\share\batch.bat, @SystemDir) The batch file has can be viewed by all authenticated users I get a syntax error whenever it comes accross the \\ in the UNC. I have tried mapping the drive but with no luck although I understand that UNC are supposed to work better than mapped drives. I am sure there is some "" quotes issue somewhere but I cant for the life of me work it out! Newb in need! Edited January 12, 2010 by hacksawbob
nfwu Posted January 12, 2010 Posted January 12, 2010 Hopefully quite simple but I have been trawling the forum for at least the last hour. I am trying to run a batch file at logon as an admin by a non admin user. RunAs(adminuser, @computername, XXXXPASS, 0, \\server\share\batch.bat, @SystemDir) The batch file has can be viewed by all authenticated users I get a syntax error whenever it comes accross the \\ in the UNC. I have tried mapping the drive but with no luck although I understand that UNC are supposed to work better than mapped drives. I am sure there is some "" quotes issue somewhere but I cant for the life of me work it out! Newb in need! RunAs("adminuser", @computername, "XXXXPASS", 0, "\\server\share\batch.bat", @SystemDir) String literals, or string data in source code, needs quotes: "". TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
hacksawbob Posted January 12, 2010 Author Posted January 12, 2010 Thanks for the quick reply heres the full code that I have pasted from the help file and modified, with the quotes in in it around the UNC I would expect to see a dos box pop up but i dont it doesn't complete the operation (a simple file copy for now) ; Fill in the username and password appropriate for your system. Local $sUserName = "USERNAME" Local $sPassword = "PASSWORD" ; Run a command prompt as the other user. Local $pid = RunAsWait($sUserName, @ComputerName, $sPassword, 0, "\\server\share\batch.bat", @SystemDir) ; Wait for the process to close. ProcessWaitClose($pid) ; Show a message. MsgBox(0, "", "The process we were waiting for has closed.")
nfwu Posted January 12, 2010 Posted January 12, 2010 (edited) I'm pretty sure you can't run a batch file directly but need a shell to do so, so here: ; Fill in the username and password appropriate for your system. Local $sUserName = "USERNAME" Local $sPassword = "PASSWORD" ; Run a command prompt as the other user. Local $pid = RunAsWait($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c " & "\\server\share\batch.bat", @SystemDir) ; Wait for the process to close. ProcessWaitClose($pid) ; Show a message. MsgBox(0, "", "The process we were waiting for has closed.") EDIT: Typos Edited January 12, 2010 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
hacksawbob Posted January 12, 2010 Author Posted January 12, 2010 Brilliant thanks that seems to be working ok now!
TigerKnee Posted April 25, 2014 Posted April 25, 2014 (edited) Hi all. Would rather just raise this thread than to create another one. Trying to run it through the network. What is the proper command? I tried: #RequireAdmin RunAsWait(John.Smith, FakeDomain, PaSsW0Rd, 0, @ComSpec & " /c " & "\\server\share\folderinshare\anotherfolder\install.cmd", @SystemDir) And (desperate attempt...) ; Fill in the username and password appropriate for your system. Local $sUserName = "John.Smith" Local $sPassword = "PaSsW0Rd" ; Run a command prompt as the other user. Local $pid = RunAsWait($sUserName, FakeDomain, $sPassword, 0, @ComSpec & " /c " & "\\server\share\folderinshare\anotherfolder\install.cmd", @SystemDir) ; Wait for the process to close. ProcessWaitClose($pid) ; Show a message. MsgBox(0, "", "The process we were waiting for has closed.") To no avail. Command prompt pops up and disappears. What did I (obviously) do wrong? Edited April 25, 2014 by TigerKnee
BrewManNH Posted April 25, 2014 Posted April 25, 2014 First, remove the /c and replace it with /k so you can see any errors. Second, don't use RunAsWait if you're going to use ProcessWaitClose, the 2 are redundant. RunAsWait will pause the script until the process you start has closed, so the next line will never see the process. Also, RunAsWait returns an exit code not a PID, so your processwaitclose won't ever see the process anyways, because it's looking for a process PID that probably doesn't exist. More than likely the issue is because of permissions, but without being able to see what's in the command console, you'll never know. 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
TigerKnee Posted April 25, 2014 Posted April 25, 2014 (edited) First, remove the /c and replace it with /k so you can see any errors. Second, don't use RunAsWait if you're going to use ProcessWaitClose, the 2 are redundant. RunAsWait will pause the script until the process you start has closed, so the next line will never see the process. Also, RunAsWait returns an exit code not a PID, so your processwaitclose won't ever see the process anyways, because it's looking for a process PID that probably doesn't exist. More than likely the issue is because of permissions, but without being able to see what's in the command console, you'll never know. Here's my script #RequireAdmin RunAs("John.Smith", "FakeDomain", "PaSsW0Rd", 0, @ComSpec & " /k " & "c:\install\install.cmd", @SystemDir) I got this error: 'C:InstallLync2013.cmd' is not recognized as an internal or external command, operable program or batch file. C:WindowsSysWOW64> Tried @HomeDrive and got System32 instead of SysWOW64 Any ideas? Edited April 25, 2014 by TigerKnee
TigerKnee Posted April 25, 2014 Posted April 25, 2014 Anyone? At whit's end here. I put the /k and the script still disappears
Gianni Posted April 25, 2014 Posted April 25, 2014 (edited) what happens with this? #RequireAdmin _Wow64FsRedirection(False) RunAs("John.Smith", "FakeDomain", "PaSsW0Rd", 0, @ComSpec & " /k " & "c:\install\install.cmd", @SystemDir) _Wow64FsRedirection(True) Func _Wow64FsRedirection($state) ; Disables or reverts the filesystem redirector for a 32 bit process running on 64bit OS If Not @AutoItX64 And @OSArch = 'X64' Then If $state Then DllCall("kernel32.dll", "int", "Wow64RevertWow64FsRedirection", "int", 0) Else DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 0) EndIf EndIf EndFunc edit: anyway would you run a task on a remote machine?? I think you will not achieve that goal in >that way. Edited April 25, 2014 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
jguinch Posted April 25, 2014 Posted April 25, 2014 TigerKnee, in your script, you are running c:installinstall.cmd, and you say the error is about C:InstallLync2013.cmd. So, is it a mistake, or Lync.cmd is launched from install.cmd ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
TigerKnee Posted April 25, 2014 Posted April 25, 2014 TigerKnee, in your script, you are running c:installinstall.cmd, and you say the error is about C:InstallLync2013.cmd. So, is it a mistake, or Lync.cmd is launched from install.cmd ? No it was an error on my part. I should've put a PAUSE in my script so I can see what I did wrong. Thank you for your reply!
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