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
gometangAsked:
Who is Participating?
 
NVITCommented:
Sorry, change that last one to...
psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /accepteula cmd /c "pushd D:\MyFolder & FileRename.bat"

Open in new window

0
 
NVITCommented:
When I run your example, it works.

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-)
0
 
gometangAuthor Commented:
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.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
NVITCommented:
Try this:

psexec \\IP -u Domain\user -p password /accepteula -i -d cmd

Open in new window


This opens a cmd prompt w/ the user and password passed to psexec.

Type:
D:\Folder\MyRename.bat

Open in new window


What happens?
0
 
NVITCommented:
Oops. Ignore my last post. Looks like you already tried that.
0
 
NVITCommented:
Or did you? If not, try it.
0
 
gometangAuthor Commented:
Once I get some time on my hands tomorrow, I will try that out!  thanks.
0
 
gometangAuthor Commented:
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.
0
 
NVITCommented:
You forgot the -u switch in front of Domain\user:
psexec \\IP -u Domain\user -p password /accepteula -i -d cmd

Open in new window

0
 
gometangAuthor Commented:
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.
0
 
NVITCommented:
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

Open in new window

0
 
gometangAuthor Commented:
There is definitely a dash in front of the u option, but I get the same error.
0
 
NVITCommented:
How about...
psexec \\IP -u Domain\user -p password /accepteula -i -d cmd /c "D:\Folder\MyRename.bat"

Open in new window

0
 
gometangAuthor Commented:
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>
0
 
gometangAuthor Commented:
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?
0
 
gometangAuthor Commented:
Would I need to install psexec.exe on the remote server as well?
0
 
NVITCommented:
> 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.
0
 
NVITCommented:
> 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?
0
 
gometangAuthor Commented:
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.bat"

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.
0
 
NVITCommented:
Have you tried it w/o the -i -d switches?

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"

Open in new window


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"

Open in new window

0
 
gometangAuthor Commented:
'D:\MyFolder\FileRename.bat' 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.bat
"

PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com



'D:\MyFolder\FileRename.bat' 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>
0
 
NVITCommented:
But if you run...
psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /accepteula cmd /k

Open in new window


...which opens a CMD prompt, then type
"D:\MyFolder\FileRename.bat

Open in new window

... then that works? Hmm.
0
 
gometangAuthor Commented:
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.bat".  However, if I go in to that actual folder by DIR and run > FileRename.bat, it works lol.
0
 
gometangAuthor Commented:
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.
0
 
NVITCommented:
How about this...
psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /accepteula cmd /k

Open in new window


...then
pushd D:\MyFolder & FileRename.bat

Open in new window


If that works, then try...
psexec \\xxx.xxx.xxx.xxx -u Domain\User -p Password /accepteula cmd /k pushd D:\MyFolder & FileRename.bat

Open in new window

0
 
gometangAuthor Commented:
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.
0
 
NVITCommented:
See my last post. Wrap the cmd arguments in ""
0
 
gometangAuthor Commented:
YOU ARE THE MAN!!!!  Thanks so much for your aewsome help!!
0
 
gometangAuthor Commented:
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!!
0
 
NVITCommented:
Hehe. I'm glad it worked out for you, gometang.

I believe it works both sides - thanks for being patient, also.

Take care.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.