How will I use Psexec with .bat file

I want to run a batch file on remote computer using psexec. Can any one tell me what the command is "xyz" is name of remote computer & "abc" is name of batch file.
Who is Participating?
NarendraGConnect With a Mentor Commented:
psexec \\xyz -u username -p password c:\BatchFile1.bat
Here is how to do it:

For ex: psexec \\xyz c:\abc.bat -u username -p password
ekogaAuthor Commented:
From where will I run this command I tried from my machine from cmd prompt but it does not works.
Do i need to write the above mentione command in a file & then execute the file or just need to run the command.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

just u need to rum from command promt

after running command wt error you are getting ?

please check user name and password is correct?

both the machine are in one domain?

or local machines?
if it is local machine not attached to domain then you need run this command with local admin account.

if it is part of domain you need appropriate permissions to run the batch file remotely(domain admin)
ekogaAuthor Commented:
'psexec' is not recognized as an internal or external command,
operable program or batch file.
This is the command tht i get when I run the command. the command that I use is as follows
psexec \\xyz -u username -p password g:\abc.bat
the way I use is to copy the bat file to the remote machine and run it from there. You can include this in another batch file. I normally have a directory called batches on most of my machines as I use psexec quite a lot. You can still create the folder in the bat file

net use g: /del
net use g: \\xyz\c$
md batches
copy c:\abc.bat g:\batches
psexec \\xyz c:\batches\abc.bat

then delete the bat file later if you dont need to use it
Now i understand the problem

copy the file Psexec.exe to C:\

Then open command prompt type cd \ this will take you to C:\
then run above command

we need run this psexec command from where that file is located
hope you downloaded  you downloaded Pstools to your machine already

you can find this psexec.exe file it pstools
What I have done is create a folder on my local c drive called pstools. Downloaded the pstools and extracted them to that folder. Then added the path c:\pstools to my environment variables (under system properties->advanced->environment variable and edited the path to include c:\pstools) so I can basically run it from anywhere on my command prompt without navigating to the actual folder
Ginsmon JosephConnect With a Mentor Citrix Windows ConsultantCommented:
You can use the below command to execute a batch file on the remote machine. Make sure you have the admin rights on the remote machine

psexec \\xyz -c abc.bat

or else you can pass the username and password as an arguement

psexec \\xyz -c abc.bat -u\administrator -p *
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Sometimes it is a better idea to have all files located centrally, and call them there. Like
   \\myserver\utils\psexec \\xyz \\myserver\utils\MyBatch.cmd
I have found that PSEXEC cannot run the batch file from a UNC path unless you run it as system.

\\myserver\utils\psexec \\xyz -s \\myserver\utils\MyBatch.cmd
ekogaAuthor Commented:
It helped me partically to write the code.
Thanks to all for their help.
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.