Running a BAT file on remote workstations.

Posted on 2013-06-12
Medium Priority
Last Modified: 2013-06-14
Hello, I have to run the following BAT file on all the workstations in our network, thats  400+ workstations.

BAT code.
netsh firewall set service type = FILEANDPRINT mode = ENABLE

netsh firewall set portopening protocol = TCP port = 52965 name = APP-3-DS scope = CUSTOM addresses = 10.##.##.##

netsh firewall set portopening protocol = TCP port = 52966 name = APP-3-AGENT scope = CUSTOM addresses = 10.##.##.##

netsh firewall set portopening protocol = TCP port = 8739 name = APP-3--AGENT-UI scope = CUSTOM addresses = 10.##.##.##

netsh firewall set service type = REMOTEADMIN mode = ENABLE scope = CUSTOM addresses = 10.##.##.##

Open in new window

What options are there for running this on each workstation?   To install this bat you do have to "Press a key to continue".   Is there a bit of code My network manager wants me to run round each pc, login to a profile (he has put the BAT file in the startup folder) and activate it after the profile has loaded.

Surely there has got to be a better way?  
Question by:SpencerKarnovski
  • 2
LVL 86

Expert Comment

ID: 39241742
Remove the last line that says "pause" to remove the need for a key press.
Then use a computer startup script (not a user logon script) in a GPO applied to the  workstations in question.
Assign computer startup scripts
LVL 97

Accepted Solution

Lee W, MVP earned 2000 total points
ID: 39242957
Or run it on all the machines using PSEXEC.

Author Comment

ID: 39243813
Hello Lee,

I was going to suggest using PsEXEC.  Could you help me with the syntax (even if we do use GP as suggested, this would still be extremely beneficial to me to be able to run an application on a workstation.

So, for example.  

We have a BAT file stored on Z:\SCRIPTS\BAT.BAT

We want to run that BAT file, using PsEXEC, on the workstation:


Here is the usage syntax for PsEXEC.


Usage: psexec [\\computer[,computer2[,...] | @file][-u user [-p psswd]][-n s][-l][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,... ] cmd [arguments]

Open in new window

Something like.

C:\psexec \\computer \filelocation \file \user \password

Then I could create one BAT file, add all the computers in our network and run that just once.  I know I could do it with GPs, as someone suggested, but  I would certainly like to know how to do it from command line.  There are many times I need to run scripts on workstations that have users logged in.


Author Comment

ID: 39244576
Ok, figured it out.

How can I run multiple commands (one for each workstation) from this single batch file.

C:\>C:\PSTools\PsExec \\SMR05 -s -c C:\FW.bat

That commands runs the BAT file on SMR05, but say I wanted to run on all the computers in SMR, so something like;

C:\PSTools\PsExec \\SMR05 -s -c C:\FW.bat
C:\PSTools\PsExec \\SMR06 -s -c C:\FW.bat

And so on.  Also, I'm having to drag the PsExec into a CMD,then type the rest of the command.   When I try to create a BAT file, to do it automatically, the CMD window opens for a second, then closes without executing the command.

So, say I create the following

C:\PSTools\PsExec \\SMR05 -s -c C:\FW.bat in notepad, and save that as RUN.bat, then click RUN.bat that nothing happens.

I could go research this, but I pay for this, so someone else can show me instead !


OK, this seems to work.

start c:\PsExec.exe \\ICT211 -s -c c:\FW.bat
start c:\PsExec.exe \\ICT212 -s -c c:\FW.bat
start c:\PsExec.exe \\ICT213 -s -c c:\FW.bat
start c:\PsExec.exe \\ICT214 -s -c c:\FW.bat

This executes each command in a separate CMD - can you see any issues with this?

Featured Post

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.

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.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

586 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question