Re: Assining a Script to Run Only Once

P

Pegasus \(MVP\)

Chris Guimbellot said:
Hello,

How do you assign a script to a user or a computer to run only one time,
such as the GUIRunOnce script during Win2K unattended setup does? Group
Policy setting possibly?

Thanks,

Chris

You need to create some flag that indicates that the script
was run before. Here is a solution that relies on a flag file:

@echo off
if not exist c:\ScriptFlags md c:\ScriptFlag
if exist c:\ScriptFlags\abcxyz.flag goto :eof
.. . . . (your installation script goes here)
echo %date% %time% %UserName% > c:\ScriptFlags\abcxyz.flag

This file must reside in a central location (e.g. in
\\YourServer\Netlogon) and must be invoked by the
user's logon script. For each new installation you
use a new flag file name abcxyz.flag.
 
C

Chris Guimbellot

Thanks for the reply. For some reason I didn't think it would be so complex.
I guess its nor really, I just thought there would be a Group Policy
solution or something like that.

I understand your example and see how it is a workable solution. One thing I
do not understand is that last line:

echo %date% %time% %UserName% > c:\ScriptFlags\abcxyz.flag

It seems to me that this line simply writes a line into the abcxyz.flag
file. Is this true, because I would think that if it is, then it would mess
up, because there is no other area in the script which iterates through the
file to see if that line is in there. Of course I am sure that I'm wrong.
Any thoughts?

Thanks again,

Chris
 
P

Pegasus \(MVP\)

The code that ensures that the script runs once only does
not care what's in the file. It only checks for the existence
of the file. You could place anything into the file.

The reason why I put all this stuff into the file is simple:
From experience I know that automatic installation procedures
will not work 100% of the time. User's for example, might
interrupt the process. Having a log with date, time & username
helps enormously when figuring out what went wrong.
 
D

David H. Lipman

Here how i do it...using KixTart script interpreter

if exist ("c:\path\exist_file.txt")=0
; { perforrm needed functions }
shell '%comspec% /c ipconfig >"c:\path\exist_file.txt" '
endif

I'm not sure but also a script can be inserted in the Registry...

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

Example:
-------------
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
"MyScript"="kix32.exe MyScript.KIX"
-------------

I believe the OS will read the contents of the key, execute it, then delete it
upon completion.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top