djones (27th February 2008)
What would be the best way to make a startup script run once as opposed to every time the machine boots?
I am using a script (based on fragments from these forums) to load printer drivers (and intend to add: setting default power settings, and add/removing devices) post deployment but this currently runs at every boot.
This means that each machine takes longer to get to the logon screen (even longer for laptops when working offline). I'd like the script to only run once following deployment. I know I could disable the appropriate GPO but I'd like a more automated method - maybe as part of the WDS/Sysprep stage.
Thanks, Dave.

Perhaps package the script as a msi which goes out as part of the build in AD thus allowing you also some version control for the future.
Alternatively, at the end of the script make a reg entry and in future have the script initially check if this reg entry exists or exit.
Why not make the script write a txt file to the c drive (script_has_run.txt for example) then get the script to check for the existance of that tx file. If it exists on the c drive the script just exits - if it doesn't exist the script runs. That way it should run once, write the text file then not run on next boot.

Do this all in WDS then, it's neater. Put your script into the image somewhere (root of C:?) and call it in the registry with HKLM\Software\Microsoft\Windows\CurrentVersion\Run OnceI'd like the script to only run once following deployment.
After it's run it's removed from the registry automagically.
Edit: Backslashes. Spot the *nix boy![]()
Last edited by powdarrmonkey; 16th February 2008 at 01:02 PM.
djones (27th February 2008)
Use a flag file. [ As Jcollins has already stated ]What would be the best way to make a startup script run once as opposed to every time the machine boots?
I have a few scripts which only need to run once so the first time they are run I copy a file over in a location, then the script is run.
The next time the script runs it checks for the file, if its there it won't run, if its not there, then it runs.
You could also write a self deleting script...... [ I used to do that for my automated Win95 thin client builds many years ago..... ]
we have various scripts that we use on a new computer in a new computer ou. Once the computer is on the network we add it to the new computer ou, reboot it severaltimes and that installs all the software we need and does any of the other stuff we need (usefull for if a small fix is made when its not worth creating a new image)

In which case, why don't you have a thin RunOnce script that goes and fetches an up-to-date fat script from a network location? Then you don't have to do any bodging with GPO, or update your image every time there's a change.
The script presumably 'does' something on the PC when it runs. Is it not possible to have the script 'detect' the status of the PC to decide if it needs to run or not? Failing that, I would tend to write an entry in the registry rather than to a file but that's just down to personal preference.
We use a registry key (HKLM\software\<our name>) and there are various values under this. the startup script checks for the presence of the relevant value and runs each sub-routine as necessary.
this makes it easy to make changes - eg a bit of code has been run on every machine but now I want a new version of it to run. I update the script so it checks for value "2" instead of "1" and updates the value once it's run.
Yes I agree with the Registry method for setting the flag. If you are doing a new image then it probably worth to use the RunOnce settings as this should take care of it before the stations is commissioned to the user.
Ash.
Thanks for all the replies, this is kinda what I have decided is going to be the best option for me in the short term at least. My scripting skills really aren't very hot to say the least and I'm really pushed for time at the moment even getting round to replying here!
I think the way I'm going to try and do this is by utilsing a [GuiRunOnce] section in 'sysprep.inf' to call the script that installs the printer drivers (so that restricted user accounts can assign specific printers at login) and then add a call, to another script, in 'CmdLines.txt' to remove/reinstall problem devices (e.g. SCSI/RAID Host Controller). However, I've got a feeling that the execution of 'CmdLines.txt' post mini-setup and before first reboot may be too early for this purpose.
There are currently 1 users browsing this thread. (0 members and 1 guests)