Detecting reboot by querying registry?

  • Thread starter Thread starter edavid3001
  • Start date Start date
E

edavid3001

I use software to automate installs of 3rd party patches. Quicktime,
Macromedia, etc.

When a user logs into the domain, I generate a setting. When he logs
out, I delete that setting.

My install software querys that setting and only installs if that
setting is removed. Meaning these patches install only when no one is
currently signed into the computer. The install occurs on a random
distribution schedule. Not all at once.

The problem I am having is that the setting gets deleted as a user
reboots and in about 1% of the cases, the patch starts to install as
Windows is shutting down. The install fails, and some times can not be
recovered. Sun Java, Quicktime, and Flash have had issues where I
can't get the installer to run and fix the partial install.

The question I have is this. When Windows is shutting down, is there a
way to query the registry or some file to tell that Windows is shutting
down?

Ideally, the user reboots and the software patches after boot up and
before the user logs on the next day.
 
I use software to automate installs of 3rd party patches. Quicktime,
Macromedia, etc.

When a user logs into the domain, I generate a setting. When he logs
out, I delete that setting.

My install software querys that setting and only installs if that
setting is removed. Meaning these patches install only when no one is
currently signed into the computer. The install occurs on a random
distribution schedule. Not all at once.

The problem I am having is that the setting gets deleted as a user
reboots and in about 1% of the cases, the patch starts to install as
Windows is shutting down. The install fails, and some times can not be
recovered. Sun Java, Quicktime, and Flash have had issues where I
can't get the installer to run and fix the partial install.

The question I have is this. When Windows is shutting down, is there a
way to query the registry or some file to tell that Windows is shutting
down?

Ideally, the user reboots and the software patches after boot up and
before the user logs on the next day.

You could perhaps process the output of

shutdown -a

and if it doesn't give the following message, you abort the installation

"Unable to abort the system shutdown because no shutdown was in progress".


Jon
 
I use software to automate installs of 3rd party patches. Quicktime,
Macromedia, etc.

When a user logs into the domain, I generate a setting. When he logs
out, I delete that setting.

My install software querys that setting and only installs if that
setting is removed. Meaning these patches install only when no one is
currently signed into the computer. The install occurs on a random
distribution schedule. Not all at once.

The problem I am having is that the setting gets deleted as a user
reboots and in about 1% of the cases, the patch starts to install as
Windows is shutting down. The install fails, and some times can not be
recovered. Sun Java, Quicktime, and Flash have had issues where I
can't get the installer to run and fix the partial install.

The question I have is this. When Windows is shutting down, is there a
way to query the registry or some file to tell that Windows is shutting
down?

Ideally, the user reboots and the software patches after boot up and
before the user logs on the next day.

Here is a simple solution:

@echo off
QueryPCStatus || goto :eof
ping localhost -n 300 > nul
QueryPCStatus || goto :eof
InstallProduct

The process queries the remote PC. If
someone is logged on then it will terminate.
If nobody is logged on then it will wait for
five minutes. This will get you safely beyond
the shutdown phase. You can make the delay
10 minutes (600 seconds) - who cares?
 
What would that do to a user who is shutting down? Would it abort?

By itself it aborts a system shutdown

Your program logic might be something like (pseudocode) ....

If <<output from "shutdown -a" is ..... >> then <<reboot>> else <<install>>


Jon
 
This will get you safely beyond the shutdown phase.

The install occurs locally from a service. Service querys central
server.

I tried that, didn't work. I used SLEEP. Found out that if I put in
a batch file as the software to be distributed the batch file is
launched and marked as installed. The PC reboots during the sleep, and
the install never retrys again.

Fixes the partial install problem, creates another.
 
That might work. I'll have to play with it.

So the very first thing I do is;

Shutdown -a > c:\file.txt 'put file elsewhere

which aborts a shutdown and allows the rest of the batch file to run.

Then I do my install.

Then I can either force a reboot if I want;

C:\BATCH\SHUTDOWN /L /R /T:15 /Y /C

or

(parse c:\file.txt| if = "Unable to abort the system shutdown
because no shutdown was in progress" then reboot|else exit)




That might work. Thanks. I'm going to play with it and see if there
are any side affects.
 
The install occurs locally from a service. Service querys central
server.

I tried that, didn't work. I used SLEEP. Found out that if I put in
a batch file as the software to be distributed the batch file is
launched and marked as installed. The PC reboots during the sleep, and
the install never retrys again.

Fixes the partial install problem, creates another.

It is impossible to propose a working solution unless
you provide full details about your installation process.
So far you have given us nothing but a rough outline.
 
I suspect that there are probably more elegant ways of doing it ie querying
whether a shutdown is in progress, without the aborting. If you hunt around
on Google a bit, though, with some well-chosen keywords, you might discover
something.

Jon
 
Active Directory. Users all run a login script which creates
c:\temp\flagfile.flg. When they log out the Active Directory logout
script deletes this file.

A service runs on the PC. It runs as SYSTEM. Quicktime 7.1 was just
released, and this is an example of one I am currently distributing.
The service downloads the quicktimeinstaller.exe and .ini to
c:\temp\quicktime7.1\ When c:\temp\flagfile.flg does not exist, we
know a user is not signed into the computer. The service only
launches the quicktimeinstaller.exe when this flag file is not in
existance. There is also a random element to this. It only polls
the flagfile once after bootup after about 6 minutes. And then every
50 minutes after. It also does a randomize and might not install for
up to several days. This prevents 500 machines getting updated at
once.

This works 99% of the time. The problem is 1% of the time the service
detection occurs between the time the user has selected to reboot, the
machine has logged the user off, but the machine has not stopped the
service yet. So the service launches quicktimeinstaller.exe (or
whatever) which runs partially and then terminates.

When this happens with Sun Java, the files end up being copied to the
program files directory, but the registry doesn't get created.
Attempts to do an MSI repair fail. Uninstall fails, and you can't
reinstall because it's already installed. It's a pain to repair.
Other things such as Quicktime are easier.

So what I would like to know is if there is some place in the registry
that I can have the service query to see if Windows is shutting down.
If it is, then do nothing. Obviously this service will eventually get
notified as it will stop. But with as much software as we run on our
machines, it takes a while for the process to complete which gives us
our 1% of installs that fail.

If we were not a 24/7 shop we'd just schedule them to run in the middle
of the night. But we have staffing in most locations around the clock.

Thank you;

Edwin.
 
Active Directory. Users all run a login script which creates
c:\temp\flagfile.flg. When they log out the Active Directory logout
script deletes this file.

A service runs on the PC. It runs as SYSTEM. Quicktime 7.1 was just
released, and this is an example of one I am currently distributing.
The service downloads the quicktimeinstaller.exe and .ini to
c:\temp\quicktime7.1\ When c:\temp\flagfile.flg does not exist, we
know a user is not signed into the computer. The service only
launches the quicktimeinstaller.exe when this flag file is not in
existance. There is also a random element to this. It only polls
the flagfile once after bootup after about 6 minutes. And then every
50 minutes after. It also does a randomize and might not install for
up to several days. This prevents 500 machines getting updated at
once.

This works 99% of the time. The problem is 1% of the time the service
detection occurs between the time the user has selected to reboot, the
machine has logged the user off, but the machine has not stopped the
service yet. So the service launches quicktimeinstaller.exe (or
whatever) which runs partially and then terminates.

When this happens with Sun Java, the files end up being copied to the
program files directory, but the registry doesn't get created.
Attempts to do an MSI repair fail. Uninstall fails, and you can't
reinstall because it's already installed. It's a pain to repair.
Other things such as Quicktime are easier.

So what I would like to know is if there is some place in the registry
that I can have the service query to see if Windows is shutting down.
If it is, then do nothing. Obviously this service will eventually get
notified as it will stop. But with as much software as we run on our
machines, it takes a while for the process to complete which gives us
our 1% of installs that fail.

If we were not a 24/7 shop we'd just schedule them to run in the middle
of the night. But we have staffing in most locations around the clock.

Thank you;

Edwin.

Modify your AD logoff script so that it deletes your flag
file not immediately but only after a wait period of 10 minutes.

I do not think that the registry contains a key that indicates
that a shutdown is in progress. It is more likely that this is
a flag maintained in the operating system's memory. If you
knew where then you could interrogate it.
 
Modify your AD logoff script so that it deletes your flag
file not immediately but only after a wait period of 10 minutes

Sounds good, but how would you do that? If I launch a batch from the
login script to delay 10 minutes then delete the file, won't I have the
user logoff also waiting this 10 minutes before the logoff completes?
Our would a START to call a batch file prevent that?

Thanks;

Edwin
 
Start doesn't work.

start "lgoff" /separate /min \\domain.com\NETLOGON\logoffgpo.bat

I have echo's throughout that bat file and it does get launched, but it
gets killed off while it is in the SLEEP 360 and never does remove the
flag file.

Any other tricks? This sounds like the right path.
 
Yes, that looks good - but Google search shows others who have tried
this and the script to try and detect if a logoff or shutdown is
occuring using this method ends up getting killed off by the "logging
off user" so you don't get the results.

Another angle. Computer start up script creates a file as
c:\temp\startup.txt

The user login script deletes this file.


So I check for this file's existance. If it exists, I know that the
computer was just rebooted and no-one has signed back into it.

It doesn't allow me to install patches if someone just logs off and
doesn't reboot..
 
I put inside the logoff script.

shutdown -a > c:\a.txt

Guess what it shows when I do a shutdown and restart? Haven't even
logged into the PC, just shutting down..

"Unable to abort the system shutdown because no shutdown was in
progress."

So this angle is out. Windows doesn't detect that it is shutting down
from the logoff scripts. I can't stick it in the reboot script
because that runs after the logoff script, so my timing issue would
remain thus not resolving the issue.

If I sleep 360 in the bat file of the installer, then do the install -
windows kills off sleep but not the batch file so the next line runs,
which calls the installer. The installer is killed off, then the next
line runs that creates the flag file that the install is done. Of
course, Windows allows that line to create the flag file. So I end up
thinking the install is done but it is not.

Thus my delima. Maybe if I run regmon and pipe to a file I can
determine a registry value that gets changed at shutdown but not just
at logoff..
 
Start doesn't work.

start "lgoff" /separate /min \\domain.com\NETLOGON\logoffgpo.bat

I have echo's throughout that bat file and it does get launched, but it
gets killed off while it is in the SLEEP 360 and never does remove the
flag file.

Any other tricks? This sounds like the right path.

Place soon.exe (Resource Kit) into the logon script,
to launch an independent task 5 minutes from now to
delete your semaphore file.
 
Start doesn't work.

start "lgoff" /separate /min \\domain.com\NETLOGON\logoffgpo.bat

I have echo's throughout that bat file and it does get launched, but it
gets killed off while it is in the SLEEP 360 and never does remove the
flag file.

Any other tricks? This sounds like the right path.

If you choose to use soon.exe then you must insert
this line into the users' netlogon batch file:

if exist %SystemRoot%\tasks\at*.job del %SystemRoot%\tasks\at*.job

If you don't then you will have a problem in those
cases where the user logs off, then immediately
logs on again.
 
Thanks, I'll play with this on Monday. We use soon a lot so just
arbitrarily killing off the at* jobs wouldn't be a good thing would it?


So at logoff I'd soon a job to delete the flag file. If the person
logs off, it deletes. If the person reboots, it doesn't delete. The
computer startup script could then remove the temp file. If a person
logs in right after logoff then I might have issues with a patch
installing, but that's not as big a deal to me as a patch start
installing during reboot.

Sounds good in theory as does all these other options. I am concerned
that the user doesn't have rights to do soon though.

Again, I'll play with it on Monday. If no dice, I guess what I could
do is create a service. At logoff a second flag file is created.
The service checks the date/time stamp of the second flag file. After
it is more than 10 minutes old, delete the main flag file. User login
scripts would remove this second flag file if exists so that I don't
run into the timing issue. Like what you were talking about
previously. Of course, if the machine did reboot the flags would need
to be removed by the computer startup scripts.
 
Yes, sounds good - and if you also added to that a 'flag file deletion on
logff', it would then also cover the user logoff scenario you mentioned.

ie

Flag1 [file created or a registry key created for the purpose]
-Set to ON (file created) with computer startup
-Turn OFF (file deleted) with user login
-Set to ON (file recreated) with user logoff

Installing only if Flag1 is ON.

Devising appropriate flag settings (or perhaps combinations of flags)
sounds like the simplest solution eg you could also another flag for
'install has been started' etc, if the above is not sufficient.

Some other links which might be helpful or simply of interest [since they'd
involve a bit more (possibly unnecessary) work] , but are related to the
original problem ....

- Trapping the exit / close event for a program
http://www.experts-exchange.com/Applications/Q_20590502.html


- AbortSystemShutdown [ possibly be more effective than the previous
'shutdown -a', which you said doesn't work ] [function located in
advapi32.dll]

http://msdn.microsoft.com/library/d...y/en-us/shutdown/base/abortsystemshutdown.asp

[Code example here for stopping a shutdown
http://msdn.microsoft.com/library/d...n/base/displaying_the_shutdown_dialog_box.asp
]


Jon
 
Back
Top