Solved

Running a script one time

Posted on 2006-06-21
7
661 Views
Last Modified: 2008-01-09
I have a script that I need to run on all the machines on my network but I need to run it one time and one time only. What's the easiest way to do that?
0
Comment
Question by:Newsboy
7 Comments
 
LVL 12

Expert Comment

by:craskin
ID: 16953314
what does the script do? with some rewriting, it may not be necessary to worry about it running more than once.
0
 
LVL 83

Expert Comment

by:oBdA
ID: 16953603
Depends on what you're planning to do and what your network looks like.
If it's an AD domain, you have several possibilities:
* the logon script, running with user permissions
* a GPO with a user logon script, running with user permissions as well
* a GPO with a computer startup script, running with system permissions
Then there's Sysinternal's PsExec (http://www.sysinternals.com/Utilities/PsExec.html) that can be run against a list of machines.
Either way, you can just create a "flag file" in the script when the script has done its job, and if this flag file exists when the script starts, just exit.
0
 
LVL 4

Expert Comment

by:Jandakel2
ID: 16953940
Most scripts can be edited to only run if they have not been ran before, i.e. if you are mapping a drive, check for the previously mapped drive and if it exists, halt the script process.  If you were to configure you script in this fashion, the easiest way to deploy it would be to set it up as part of your default domain policy, as either a computer startup script, or a user logon script.  I have an auditing program that I run, that I really only need ran once, but I leave it on for days at a time to make sure I get all the PC's and never see a detrimental impact....obviously all situations are different though...hope this helps,

JK
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 17

Expert Comment

by:Eagle6990
ID: 16955272
I second PSExec.  It work great and you can run it against either a list of machine, or the entire domain in one pass.
0
 
LVL 3

Author Comment

by:Newsboy
ID: 16959838
Here's the script

rem ******************************* FIXWSUS.CMD *************************************
net stop wuauserv

regsvr32 /s wuapi.dll

regsvr32 /s wups.dll

regsvr32 /s wuaueng.dll

regsvr32 /s wucltui.dll

regsvr32 /s msxml3.dll

c:
cd %windir%\SoftwareDistribution
rd /s/q DataStore
mkdir DataStore
rd /s/q Download
mkdir Download

net start wuauserv

rem Fixes problem with client machines not showing up on the server due to imaging method

reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate /v AccountDomainSid /f
reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate /v PingID /f
reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate /v SusClientId /f
cls
@echo Triggering detection after resetting WSUS client identity
net stop "Automatic Updates"
net start "Automatic Updates"
wuauclt /resetauthorization /detectnow
echo susid set to unique>c:\wsusfix.txt

exit

I like the flag idea, I am a domain with AD and use GP extensively. However I have little to no experience with actually writing script. So how would I edit this one to flag if it's been run or not?

Thanks so much I think this is what I'm looking for.
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 16959978
Looking at your script, you already have something that you can use for that:
echo susid set to unique>c:\wsusfix.txt

So all you need is a simple
if exist "c:\wsusfix.txt" goto :eof
at the beginning of the script.
0
 
LVL 3

Author Comment

by:Newsboy
ID: 16961033
Worked like a charm, thanks so much, I had not clue it was that easy. This will save me days of work.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

772 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