How to run a batch file on Windows boot?

  • Thread starter Thread starter Taed Wynnell
  • Start date Start date
T

Taed Wynnell

We're deploying a Windows Server 2003 image a bunch of times, and on the
first time it boots, we want to run a batch file (which will be slightly
different for each machine).

But I can't figure out how to get the system to run a batch file on boot...

Note that it is a batch file (not a .exe), and that I want to run it on
boot, not on user login. Ideally, the method to "install" it would not
modify the registry (since we'll be editing the image file, so editing the
registry within there would be awkward). We only need to run it once, but
if it's in some run-every-boot method, then we'd just have the batch file
rename itself at the end or somesuch.

So, I first looked at the
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnc
e" key (even though it was in the registry), but I couldn't get it to invoke
a batch file -- perhaps it only will run .exes? I even tried prefacing it
with "cmd /c", but it just won't run it.

WINSTART.BAT seemed ideal for what I want, but I'm guessing that it isn't
supported after Win98 from what I can tell. I tried it anyway in \,
\windows, and \windows\system32, but no luck.

The Win.ini, Boot.ini, and so on don't seem suited to a batch file (or am I
wrong?).

Any other ideas?

(Thanks in advance!)
 
I see. It would be easy enough to do at:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce

REG_SZ String

cmd /k c:\filename.bat

But, I,m not 100% sure but I think that it only executes when a user
logs on.

You can install the Windows 2000 Resource Kit AutoExNT Service and have
it run batch files/scripts when the computer boots, before users log on.

John
 
The Run and RunOnce keys only run when someone logs in. The RunServices and
RunServicesOnce keys are supposed to be equivalent for boot time instead of
logging on, but I can't get them to work.

And yes, a "cmd /c filename.bat" does work from the Run key, so I know I'm
doing it right, but it does not work from RunServices or RunServicesOnce,
even if I use a .exe (such as defrag.exe).
 
You can't run batch files or scripts in the Services keys. Install the
AutoExNT Service and *it* will start in a service key and run batch
files at boot time, before users log on.

John
 
John John said:
You can't run batch files or scripts in the Services keys. Install the
AutoExNT Service and *it* will start in a service key and run batch
files at boot time, before users log on.

ARGH!

AutoExNT is a kludge!
Guess what the "Tasks" folder is good for and what it provides?
Or a "startup script"?

Stefan

[ braindead fullquote removed ]
 
Stefan said:
ARGH!

AutoExNT is a kludge!
Guess what the "Tasks" folder is good for and what it provides?
Or a "startup script"?

Stefan

Will these run before log on or without a user log on?

John
 
John John said:
Will these run before log on or without a user log on?

At startup, just as their name says. Both.
Why else does "Tasks" offer "At logon" and the system a "logon script"
if there ain't a distinction?
And guess what the difference between "logoff script" and "shutdown
script" might be.-)
Maybe it's time to abandon your NT4 and switch to a still supported
version like NT5.x?

Stefan
 
Stefan said:
At startup, just as their name says. Both.
Why else does "Tasks" offer "At logon" and the system a "logon script"
if there ain't a distinction?
And guess what the difference between "logoff script" and "shutdown
script" might be.-)
Maybe it's time to abandon your NT4 and switch to a still supported
version like NT5.x?

Maybe it's time you read the posts and find out what the OP asked for to
start with. As for which operating systems I use it's none of your
business! Now, answer the question, do the solutions that you suggested
run before user log on? I suspect that you don't know the answer so
that is why you didn't answer the question. Please read the OP's
original post and supply him with a solution that works or else you can
can your smart ass remarks!

John
 
John John wrote :
Please read the OP's original post and supply
him with a solution that works or else you can can your smart ass remarks!


He did - the startup script runs before the user logs on - i.e. before
pressing Ctrl-Alt-Del.

To add a startup script:
Open gpedit.msc from command prompt and navigate to
"Computerconfiguration / Windows Settings / Scripts / STARTUP"


/klaus
 
John John said:
Stefan Kanthak wrote:

Maybe it's time you read the posts and find out what the OP asked for to
start with. As for which operating systems I use it's none of your
business! Now, answer the question, do the solutions that you suggested
run before user log on? I suspect that you don't know the answer so
that is why you didn't answer the question. Please read the OP's
original post and supply him with a solution that works or else you can
can your smart ass remarks!

Better be a smart ass than a dumb ass.

I'm so sorry that I assumed you were able to have a look into the
documentation of the system the OP wants to deploy (or even Windows NT5.x
itself) in the past 8 years and maybe retrieve the answer by yourself.
Or even show your experience with a Windows newer that NT4.

Heil to all Cargo Cult programmers!
Stefan
 
Klaus said:
John John wrote :



He did - the startup script runs before the user logs on - i.e. before
pressing Ctrl-Alt-Del.

To add a startup script:
Open gpedit.msc from command prompt and navigate to
"Computerconfiguration / Windows Settings / Scripts / STARTUP"

Thanks, klaus, that is all I wanted to know.

John
 
Stefan said:
Better be a smart ass than a dumb ass.

I'm so sorry that I assumed you were able to have a look into the
documentation of the system the OP wants to deploy (or even Windows NT5.x
itself) in the past 8 years and maybe retrieve the answer by yourself.
Or even show your experience with a Windows newer that NT4.

You don't know which operating systems I have or do not have experience
with. Instead of offering conductive criticisms or offering better
solutions when appropriate you think that you must first post obnoxious
demeaning insults, which is your usual style with most of your posts in
these groups. I like to learn new things and I like to be corrected
when I post inaccurate advice. I hadn't thought of startup scripts when
I posted my suggestion, thanks for telling us about it. As for your
obnoxiousness and insults you can keep them for yourself or we may very
well hurl them back at you!

John
 
John John said:
Stefan Kanthak wrote:

You don't know which operating systems I have or do not have experience
with.

| User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040616
| User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.4) Gecko/20030624

NT4 is LONG without support, and the Netscape you use too.
All three have numerous unpatched vulnerabilities (and simple bugs too).
Instead of offering conductive criticisms or offering better
solutions when appropriate you think that you must first post obnoxious
demeaning insults, which is your usual style with most of your posts in
these groups. I like to learn new things and I like to be corrected
when I post inaccurate advice.

Then do so. I expect people to think and do their homework before posting!
Especially with such trivialities as startup/logon/logoff/shutdown scripts
or the "Tasks".
I hadn't thought of startup scripts when
I posted my suggestion, thanks for telling us about it. As for your
obnoxiousness and insults you can keep them for yourself or we may very
well hurl them back at you! ~~

You got a big handsome brother?

Stefan
 
I'd have to add that many small sites still use NT Server, and have balked
at switching to 2000 server, let alone 2003/8 Server.

Part of the reason I guess is that in scale, NT suits the smaller business
operation, whereas 2000-on are clearly megacorporation-oriented. On these you
either make do with workgroup setup and no network logon.. or you have the
mindboggling complexity of the Active Directory. A bit like being told that
when replacing your SUV, you have a choice of either a pushbike or a Shuttle
Transporter!

It goes even further with 2003 server, which installs restrictive policies
as soon as the AD is activated. There polices are a source of trouble for
small networks whose admins simply haven't the time to attend a Group Policy
bootcamp, and don't need/want these restrictions anyway.

That, and management tend to be cagey about a server which requires WPA.
After all, their business depends on this machine, and what if one dark day
the activation fails, perhaps afer a server repair, and MS refuse to
reactivate it? In the trade we know that this isn't too serious a risk.. but
management probably don't see it that way. And, I can undestand their
viewpoint. Would you run your firm on electricity provided by a
coin-in-the-slot meter?
 
Klaus Jorgensen said:
the startup script runs before the user logs on - i.e. before
pressing Ctrl-Alt-Del.
To add a startup script:
Open gpedit.msc from command prompt and navigate to
"Computerconfiguration / Windows Settings / Scripts / STARTUP"

That worked out nicely -- thanks to all. The downside of this method is
that my images all need to be configured to invoke the batch file before the
batch file has been added to the deployed image (it's added after the image
is deployed, but before it is first booted), but GPEDIT doesn't prevent you
from adding a batch file that doesn't exist (though it will log a UserInit
Event ID 1000 error).

Is there a command-line way to add / remove things to the Startup Script
list? -- I'd like to automate that rather than doing hand-edits to each
image. I could just poke the registry using REG or whatever at
"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\windows\System\Scripts\Start
up\0\0" and the values in the key above that, but if there's a command-line
GPEDIT interface, I'd probably rather use that.

Thanks again!
 
Back
Top