Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Running a BAT file on remote workstations.

Posted on 2013-06-12
4
Medium Priority
?
906 Views
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.##.##.##
pause

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?  
Thanks
0
Comment
Question by:SpencerKarnovski
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 85

Expert Comment

by:oBdA
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
http://technet.microsoft.com/en-us/library/cc779329(v=ws.10).aspx
0
 
LVL 96

Accepted Solution

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

Author Comment

by:SpencerKarnovski
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:

\\ICT101

Here is the usage syntax for PsEXEC.

http://technet.microsoft.com/en-gb/sysinternals/bb897553.aspx

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.

Thanks.
0
 

Author Comment

by:SpencerKarnovski
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 !

Thanks.

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?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

636 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