Sign in to follow this  
Followers 0
hacksawbob

Please helpwith runas over network

12 posts in this topic

#1 ·  Posted (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 by hacksawbob

Share this post


Link to post
Share on other sites



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: "".

Share this post


Link to post
Share on other sites

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.")

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by nfwu

Share this post


Link to post
Share on other sites

Brilliant thanks that seems to be working ok now! :D

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by TigerKnee

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by TigerKnee

Share this post


Link to post
Share on other sites

Anyone?  At whit's end here.  I put the /k and the script still disappears

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by PincoPanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0