gometang
asked on
PsExec Not Executing .BAT on Remote Server eventhough it does not error
Hi guys,
I am trying to execute a .BAT file that sits within a remote server \\A and a directory my network user has access to. I can execute the batch .BAT just fine when I log into that \\A server via RDP. The remote server is Windows Server 2008 R2. When I try to run PsExec.exe from a different \\B server with the PsExec.exe on a local folder in \\B, I am trying to execute the .BAT on \\A:
D:\PSTools>psexec \\IP -u Domain\user -p password /accepteu
la -i -d cmd /c "D:\Folder\MyRename.bat" >> test.log
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Starting cmd on <IP>... <IP>...
cmd started on <IP> with process ID 4580.
D:\PSTools>
This looks like it was successful, but it is not running the .BAT file. The user/password is the same account I use to RDP into server \\A, which I can run manually just fine.
Can someone help me determine why the PsExec looks like it is running the .BAT file remotely, but is not?
Thanks,
Gome
I am trying to execute a .BAT file that sits within a remote server \\A and a directory my network user has access to. I can execute the batch .BAT just fine when I log into that \\A server via RDP. The remote server is Windows Server 2008 R2. When I try to run PsExec.exe from a different \\B server with the PsExec.exe on a local folder in \\B, I am trying to execute the .BAT on \\A:
D:\PSTools>psexec \\IP -u Domain\user -p password /accepteu
la -i -d cmd /c "D:\Folder\MyRename.bat" >> test.log
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Starting cmd on <IP>... <IP>...
cmd started on <IP> with process ID 4580.
D:\PSTools>
This looks like it was successful, but it is not running the .BAT file. The user/password is the same account I use to RDP into server \\A, which I can run manually just fine.
Can someone help me determine why the PsExec looks like it is running the .BAT file remotely, but is not?
Thanks,
Gome
ASKER
Actually, I don't care about the test.log... i left it in there to see what it does. The .BAT I have does not run or doesn't seem to; it is a small script that renames all the files in the folder it contains. I wonder if there might be file rename permission issues? I don't think there is because I can run the .BAT file normally with the same login I put in the psexec statement.
Try this:
This opens a cmd prompt w/ the user and password passed to psexec.
Type:
What happens?
psexec \\IP -u Domain\user -p password /accepteula -i -d cmd
This opens a cmd prompt w/ the user and password passed to psexec.
Type:
D:\Folder\MyRename.bat
What happens?
Oops. Ignore my last post. Looks like you already tried that.
Or did you? If not, try it.
ASKER
Once I get some time on my hands tomorrow, I will try that out! thanks.
ASKER
Sorry for such a late response; been swamped with so many things.
The result I get is this:
D:\PSTools>psexec \\IP Domain\User -p Password /accepteula -i -
d cmd
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
PsExec could not start Domain\User on xxx.xxx.xxx.xxx:
The system cannot find the path specified.
D:\PSTools>
It seems like I cannot connect at all. I can ping the IP just fine and can also log into that machine via RDP.
The result I get is this:
D:\PSTools>psexec \\IP Domain\User -p Password /accepteula -i -
d cmd
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
PsExec could not start Domain\User on xxx.xxx.xxx.xxx:
The system cannot find the path specified.
D:\PSTools>
It seems like I cannot connect at all. I can ping the IP just fine and can also log into that machine via RDP.
You forgot the -u switch in front of Domain\user:
psexec \\IP -u Domain\user -p password /accepteula -i -d cmd
ASKER
I now get this error:
PsExec could not start ?u on xxx.xxx.xxx.xxx:
The system cannot find the file specified.
Does this mean that my credentials is not working? I wonder if there is something that prevents me from logging in via PsExec eventhough I can log in remotely via RDP.
PsExec could not start ?u on xxx.xxx.xxx.xxx:
The system cannot find the file specified.
Does this mean that my credentials is not working? I wonder if there is something that prevents me from logging in via PsExec eventhough I can log in remotely via RDP.
Did you forget to put the dash in front of the U? If I run it without the dash, I get the same error as you:
psexec \\IP u Domain\user -p password /accepteula -i -d cmd
ASKER
There is definitely a dash in front of the u option, but I get the same error.
How about...
psexec \\IP -u Domain\user -p password /accepteula -i -d cmd /c "D:\Folder\MyRename.bat"
ASKER
Hi,
These are the cmd results; however, the .bat did not actually run. It seems to only run if I run as administrator logged into via RDP to the box:
D:\PSTools>psexec \\IP -u Domain\User -p Password /accepteu
la -i -d cmd /c "D:\Folder\FileRename.bat"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
cmd started on xxx.xxx.xxx.xxx with process ID 9848.
D:\PSTools>
These are the cmd results; however, the .bat did not actually run. It seems to only run if I run as administrator logged into via RDP to the box:
D:\PSTools>psexec \\IP -u Domain\User -p Password /accepteu
la -i -d cmd /c "D:\Folder\FileRename.bat"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
cmd started on xxx.xxx.xxx.xxx with process ID 9848.
D:\PSTools>
ASKER
Also, I was able to log into the machine via PSEXEC:
D:\PSTools>psexec \\IP -u domain\user -p password /accepteu
la cmd
Then I was able to cd to the folder that contains the bat and execute it from cmd line. However, I can't get it to execute via the one command.
Any ideas?
D:\PSTools>psexec \\IP -u domain\user -p password /accepteu
la cmd
Then I was able to cd to the folder that contains the bat and execute it from cmd line. However, I can't get it to execute via the one command.
Any ideas?
ASKER
Would I need to install psexec.exe on the remote server as well?
> install psexec.exe on the remote server as well?
It wouldn't hurt. Wherever you put it, make sure it's locatable on the system PATH.
It wouldn't hurt. Wherever you put it, make sure it's locatable on the system PATH.
> I was able to cd to the folder that contains the bat and execute it from cmd line.
> However, I can't get it to execute via the one command.
If you are using the exact command string for both methods, I don't see why it wouldn't work.
Possibly antivirus blocking?
> However, I can't get it to execute via the one command.
If you are using the exact command string for both methods, I don't see why it wouldn't work.
Possibly antivirus blocking?
ASKER
Apologies for all the messages, but I did more research; when I remove the "cmd /c" so I can execute the .bat, I get an error message:
D:\PSTools>psexec \\IP -u Domain\User -p Password /accepteu
la -i -d "D:\MyFolder\FileRename.ba t"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Starting D:\MyFolder\FileRename.bat on xxx.xxx.xxx.xxx
PsExec could not start D:\MyFolder\FileRenam
e.bat on xxx.xxx.xxx.xxx:
The system cannot find the file specified.
D:\PSTools>psexec \\IP -u Domain\User -p Password /accepteu
la -i -d "D:\MyFolder\FileRename.ba
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Starting D:\MyFolder\FileRename.bat
PsExec could not start D:\MyFolder\FileRenam
e.bat on xxx.xxx.xxx.xxx:
The system cannot find the file specified.
Have you tried it w/o the -i -d switches?
This should open cmd and run the .bat. The cmd window stays open:
This should open cmd and run the .bat. The cmd window closes when done:
This should open cmd and run the .bat. The cmd window stays open:
psexec \\IP -u Domain\User -p Password /accepteula cmd /k "D:\MyFolder\FileRename.bat"
This should open cmd and run the .bat. The cmd window closes when done:
psexec \\IP -u Domain\User -p Password /accepteula cmd /c "D:\MyFolder\FileRename.bat"
ASKER
'D:\MyFolder\FileRename.ba t' is not recognized as an internal or external command,
operable program or batch file.
cmd exited on xxx.xxx.xxx.xxx with error code 1.
C:\Users\MyUser>psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /a
ccepteula cmd /k "D:\MyFolder\FileRename.ba t
"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
'D:\MyFolder\FileRename.ba t' is not recognized as an internal or external command,
operable program or batch file.
C:\Windows\system32>
C:\Windows\system32>exit
cmd exited on xxx.xxx.xxx.xxx with error code 9009.
C:\Users\MyUser>
operable program or batch file.
cmd exited on xxx.xxx.xxx.xxx with error code 1.
C:\Users\MyUser>psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /a
ccepteula cmd /k "D:\MyFolder\FileRename.ba
"
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
'D:\MyFolder\FileRename.ba
operable program or batch file.
C:\Windows\system32>
C:\Windows\system32>exit
cmd exited on xxx.xxx.xxx.xxx with error code 9009.
C:\Users\MyUser>
But if you run...
...which opens a CMD prompt, then type
psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /accepteula cmd /k
...which opens a CMD prompt, then type
"D:\MyFolder\FileRename.bat
... then that works? Hmm.
ASKER
Actually, I get the same error. It looks like once I am in prompt on the remote machine, it doesn't like the "D:\MyFolder\FileRename.ba t". However, if I go in to that actual folder by DIR and run > FileRename.bat, it works lol.
ASKER
The results are the same when I am actually in the remote C:\Windows\System32 drive on the remote machine. It looks like it doesn't like that statement; I am not sure how else to run the .bat file from the C:\ drive, but the .bat is on the D:\ drive.
How about this...
...then
If that works, then try...
psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /accepteula cmd /k
...then
pushd D:\MyFolder & FileRename.bat
If that works, then try...
psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /accepteula cmd /k pushd D:\MyFolder & FileRename.bat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Closer!! It actually works up to the 2nd step. However, when I run the full command on the last step, it says:
C:\Users\MyUser>psexec \\IP -u Domain\User -p Password /a
ccepteula -i -d cmd /c pushd D:\MyFolder & FileRename.bat
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
cmd started on IP with process ID 11116.
'FileRename.bat' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\MyUser>psexec \\IP -u Domain\User -p Password /a
ccepteula -i -d cmd /c pushd D:\MyFolder & FileRename.bat
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
cmd started on IP with process ID 11116.
'FileRename.bat' is not recognized as an internal or external command,
operable program or batch file.
See my last post. Wrap the cmd arguments in ""
ASKER
YOU ARE THE MAN!!!! Thanks so much for your aewsome help!!
ASKER
Very patience and great at working a solution from different angles. Definitely got the solution I needed eventhough I wasn't able to respond promptly!!
Hehe. I'm glad it worked out for you, gometang.
I believe it works both sides - thanks for being patient, also.
Take care.
I believe it works both sides - thanks for being patient, also.
Take care.
I setup D:\Folder\MyRename.bat to create a log on the remote station A. The log created by psexec, i.e. test.log, just has the words "Password:"
Do you want test.log to show the results on \\A?
Or, do you want the log at \\A to show on \\B as test.log?
Or, none of the above? 8-)