Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a batch file remotely

Status
Not open for further replies.

kruxty

Programmer
Jul 17, 2001
197
PT
Hi,

I need to run a batch file remotely.
My first ideia was to put the file in a shared folder... but doing this the file is run in my computer, not in the other "shared" computer.

There is any tool that can run a file in other machine remotely?

Tkx to all help given ;)
 
In the Windows NT4 resource kit there was a program called RCMD for "Remote Command" that let you remotely execute command-line commands. I have used to use it to run batch files in the past. I suspect that there is a similar component for Windows 2000.
 
You can do this by using the AT command.

From SERVER1, to run a file on SERVER2:

SERVER1 CMD Prompt:

at 10:00a \\SERVER2 "c:\test\test.bat"
 
Wallst32, in your example you can execute the batch file that resides on SERVER2, but the file will execute on SERVER1. If you want to execute it on SERVER2 you will have to use a different method. Kruxty specifically indicated that he needed the file to execute on the remote system.
 
wallst32 is correct if syntax order is not critical. Please pardon my pasting of the AT command syntax rather than having everyone go look it up.

Code:
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername     Specifies a remote computer. Commands are scheduled on the
                   local computer if this parameter is omitted.
id                 Is an identification number assigned to a scheduled
                   command.
/delete            Cancels a scheduled command. If id is omitted, all the
                   scheduled commands on the computer are canceled.
/yes               Used with cancel all jobs command when no further
                   confirmation is desired.
time               Specifies the time when command is to run.
/interactive       Allows the job to interact with the desktop of the user
                   who is logged on at the time the job runs.
/every:date[,...]  Runs the command on each specified day(s) of the week or
                   month. If date is omitted, the current day of the month
                   is assumed.
/next:date[,...]   Runs the specified command on the next occurrence of the
                   day (for example, next Thursday).  If date is omitted, the
                   current day of the month is assumed.
"command"          Is the Windows NT command, or batch program to be run.

That still involves having the batch file in a commonly accessible place or getting it copied onto the remote machine. PSEXEC wraps that all together using various command line options. (It can copy the file to the remote system for you.)
 
I'm using psexec.

But i'm having some problems.
The batch file is to unregister and register dlls from SERVER2. This batch works in perfection locally, but when i use psexec gives me error 0.

I think this happens because of the code that is in the batch file. I had put a pause in the bathc file and the psexec gives me that pause, but "reject" all the other syntax.

Any ideia?!
 
kmcferrin - The specified command runs from and executes on server2 (according to my example).

I have used this procedure many times in the past. Just write something simple and test it and you will see. The only tricky thing about using AT is the paths have to be absolute (ie C:\full\path\to\my.bat instead of my.bat or .\mybat).

What' the reason for using pause?

 
kruxty-

can you post your batch file and the psexec command line you use to launch it?
 
How about creating a batch file on the server that needs to run the batch file?


Have the batch file first map a drive to the location where the target batch file is. Probably should turn off persistence.

Then, have the batch file run the other batch file, using the path through the mapped network drive. Since you mapped the drive first, it should treat it as a local file.

If that doesn't work, your local batch file can be scheduled to map the drive, copy the file to a local disk, and then run it. A separate batch file can be scheduled to delete the file when it is finished.
 
kleinicus, the process that you sugests doesn't run in the remote computer, but on my own computer.

The Code of the batch is:

Code:
@ECHO OFF
dir /b c:\site\com\*.dll > listadll.txt

for /f "delims= " %%a in (listadll.txt) do (regsvr32 /u /s c:\site\com\%%a)
regsvr32 /u /s c:\site\com2\special_com.dll

REM pause

for /f "delims= " %%a in (listadll.txt) do (regsvr32 /s c:\site\com\%%a)
regsvr32 /s c:\site\com2\special_com.dll

del listadll.txt


The pause was just for testing...

The psexec syntax is:
Code:
psexec \\IP regdll.cmd

My batch file is on system32 folder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top