batch file help

Associate
Joined
28 Aug 2003
Posts
1,247
Location
N Ireland
it is a little complicated
i want to make a bat file to run a cmd on a remote machine to update my media library.
i can do it manually using psexec from pstools, but have got lost trying to automate it

i need to things in this order (win7 machine locally, whs2011 remote machine)

get an elevated command prompt [on win7 machine]
change directory to c:\pstools [folder where psexec.exe is]
run psexec \\vail -u Administrator -p ******** C:\YAMJ\My_YAMJ_2libraries_combined.cmd [where vail is the remote pc and YAMJ is the folder containing the command to run]

thanks for any ideas
 
Code:
@Echo off
c:
cd\
cd c:\pstools
psexec \\vail -u Administrator -p ******** C:\YAMJ\My_YAMJ_2libraries_combined.cmd
echo Update Complete
pause
exit

save that as a cmd file and job done, either right click and Run As Administrator or click properties and Advanced and set run as admin. Job done :)

The last Echo prompt and pause is just to show you its been completed you can remove those two lines if you dont need them.
 
If you paste psexec into this folder..

C:/windows/system32, then you don't need to change folder first, it will just find the exe
 
update - worked a treat

any ideas on code to automatically elevate it to a 'run as administrator' command prompt?
(it doesn't connect remotely unless it is run from an elevated command prompt and i want to run it as a scheduled task, rather than doing it manually each time)
 
nothing that I know of, but when you set up the scheduled task you can make it run as any user you want. Or just log in to the Admin account and set it up on there :)
 
I've not had any problems running a batchfile that triggers psexec without explicitly making it be an elevated command prompt. It is scheduled to run under an administrator account.
 
Back
Top Bottom