Running a BAT file on remote workstations.

Posted on 2013-06-12
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 83

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 95

Accepted Solution

Lee W, MVP earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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