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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
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
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

NVITEnd-user supportCommented:
Oops. Ignore my last post. Looks like you already tried that.
0
NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
> 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
NVITEnd-user supportCommented:
> 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
NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
NVITEnd-user supportCommented:
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
NVITEnd-user supportCommented:
Hehe. I'm glad it worked out for you, gometang.

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

Take care.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.