Run application after shutting down windows - windows

Yesterday I ran a BIOS update on a Windows7 computer. The BIOS update tool performed a shutdown of Windows and without restarting the computer (so directly after Windows shutdown), a DOS-like tool started that updated the BIOS.
I searched the WWW but all I can find is how to execute applications at Windows shutdown (so before windows goes down) or at logoff (logoff scripts).
Does anyone have any clue on how to achieve this?

It is my guess that the machine had in fact performed a soft-reboot and was running BIOS code. That's the usual approach, and in some cases the soft-reboot may not be visible to the user, i.e., the BIOS self-update code may run before the POST.
However, it is (or at least used to be) possible to run Windows code post-shutdown, although obviously it is limited in what it can do. The key information can be found in the MSDN library entry on the Service Control Handler Function:
After this time expires, system shutdown proceeds regardless of whether service shutdown is complete. Note that if the system is left in the shutdown state (not restarted or powered down), the service continues to run.
So, at least in principle, all you need to do is to install a service that asks for shutdown notification but does not actually stop when shutdown occurs, and then instruct Windows to shut down without rebooting or powering off. I have actually seen this happen, but only on older versions of Windows (before automatically powering off at shutdown became the default!) so I can't guarantee that it still works, although it definitely did once.
It should, however, be noted that this will not necessarily give you the sort of environment you may be thinking of. For example, device drivers are not necessarily unloaded before shutdown; after all, what would be the point?

You can run Local Group policy - gpedit.msc (From run).
Under Computer Configuration choose Windows Settings
choose Scripts(Startup/Shutdown)
On Shutdown properties you can add script and also mention parameters if needed.
I also advised you to look at the following question - how to delay shutdown and run a process in window service

Related

lenovo system ignoring SetThreadExecutionState() and was missing "Allow wake timers"?

I have come across a Lenovo IdeaCentre A540-24ICB system with a scheduled task that wakes the computer to start my application and it seems to start but the system goes back to sleep right away. Sometimes it appears to not start (or goes to sleep so fast nothing is logged yet) so I checked the Windows power sleep options to ensure "Allow wake timers" was enabled but it didn't exist! Searching online I found a registry entry to add to have it show up in the power options and then ensured it's was enabled. However, didn't make a difference.
I have to use the mouse/keyboard for the computer to wake long enough to run the application (it will start where it left off). The application has been used for years and waking and running has worked. It already tells the system to not go to sleep through the api call in the main processing thread (which could take a fraction of a second to get to):
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
I thought that API was enough to prevent system from going to sleep? As mentioned, it has worked for years. It's just this new Lenovo system or the Win10 installed with it doesn't seem to honor it? Is there some other API call that needs to be called? or any checks / fix the app should do to ensure the SetThreadExecutionState() will work?
TIA!!

Preventing Windows 7 embedded standard shutdown

Other similar question mostly target Windows XP, where everything was easier. =)
I'd like my application to be able to postpone the windows shutdown transparently, without having windows show this screen:
Is there any option left to me after the Vista changes to the WM_QUERYENDSESSION handling?
The target here is Windows 7 standard embedded on an embedded device that runs only my application. Before shutting down the user needs to perform some manual steps that can not be postponed until the next start and must not be forgotten. I'd like to have the user confirm these steps before shutting down.
I've come to the conclusion, that there is no way to do this. =/
The workaround I've found is to allow shutdown only via the software at opportune moments. The start menu or task manager is not available to the user, and the hardware power button behavior can be configured to do nothing in the systems power options.

Killing processes on Windows 7

I'm debugging plugins on Windows 7 and of course the plugin host (Cubase5.exe) occasionally crashes because of errors in the plugin. On XP or Vista, I could always restart it immediately and continue working. But on Windows 7, even though Cubase appears to close, it is still visible in Task Manager and I cannot kill it by any means. After a minute or two, it disappears by itself. In the mean time, I can't work because the plugin DLL is still locked by the process.
Does anyone know why this happens on Windows 7? I've already tried disabling Automatic Error Reporting but that didn't help. I've tried attaching cdb to Cubase, but I get:
Cannot debug pid 5252, NTSTATUS 0xC0000001
"{Operation Failed} The requested operation was unsuccessful."
Debuggee initialization failed, NTSTATUS 0xC0000001
"{Operation Failed} The requested operation was unsuccessful."
I tried following the instructions here but it appears this is only possible if I connect a second machine to my computer to debug it remotely.
I finally found the solution, using this article:
http://blogs.technet.com/b/markrussinovich/archive/2005/08/17/unkillable-processes.aspx
This required installing the Windows Debugging Tools for Windows (nice name) and LiveKd, but by following the steps outlined I was able to track which driver was causing the process to hang: it turned out to be the 64-bit driver for the M-Audio Oxygen 8 V2 controller I'm using. Unfortunately no driver update is available.
Anyway, if anyone encounters a similar problem, this is the way to solve it.
Have you tried Process Explorer by Mark Russinovich? It is really useful for "killing":)
If you have error reporting enabled, it's possible that werfault.exe has Cubase open to write a minidump for crash reporting purposes.
This is just a stab in the dark but it might be your problem.
One thing you can try is to check with Process Monitor what Cubase is doing. Set a filter so that everything with a process name containing "cubase" will be recorded. It could be that you are facing some timeout issue when Cubase wants to exit.
you can end the process the service is running under. You can find this process by going to the Services tab of the Task Manager, right-clicking, and selecting Go To Process(you need to click the Show processes from all users button.). Note that one process may host multiple services (especially if it's svchost.exe), and ending the process will kill all those services. Also, this is an unclean exit, and may cause data corruption depending on what the service(s) was doing when you killed it.
Depending on which specific service you are trying to stop, there may be a cleaner way to simulate failure.

Identify a reboot

Is there any "Boot session ID" or (reliable) "Boot timestamp"?
For an installation I need to detect that a scheduled reboot took place indeed.
I guess I could do a dummy MoveFileEx() with MOVEFILE_DELAY_UNTIL_REBOOT, but i did hope for something easier.
(We have to install a 3rd party package that sometimes behaves erratically after an repair/update. In that state, accessing the device may even lock up the system)
(Windows XP, Vista, 7)
For things like this, WMI (Windows Management Instrumentation) is often a good starting place. I know you can get current uptime directly through it, which may allow you to determine if a machine recently rebooted.
Here is a blog post with some code samples as well:
http://blogs.technet.com/heyscriptingguy/archive/2004/09/07/how-can-i-tell-if-a-server-has-rebooted.aspx
Depending on your implementation language, you probably just want to pull out the query code from the vbscript.
Apparently Windows has the equivalent of "uptime". Here's more info: http://support.microsoft.com/kb/555737
As I understand it, this should tell you how long ago the system was booted. Will that information solve your problem?
You could search the System event log for event 6009 from the EventLog source - this is the first event recorded after each reboot.
I think the best answer has already been given here: Find out if computer rebooted since the last time my program ran?
That seems to be the simplest way. Use GlobalFindAtom() to see if it exists and create it, with GlobalAddAtom(), if it doesn't. It will persist beyond the execution of your program. If your application runs again, and sees that the atom exists, then then it isn't the first run since reboot.
If the computer is restarted, then the atom won't exist, indicating that this is the first run of your program since the reboot.

How can I get rid of Windows Update reboot prompt?

I want Windows Update to automatically download and install updates on my Vista machine, however I don't want to be bothered by the system tray reboot prompts (which can, at best, only be postponed by 4 hours).
I have performed the registry hack described here to prevent Windows forcibly rebooting my machine, which is a good start. However, is there any way to get rid of the reboot prompts altogether, or decrease their frequency?
Not sure if it is the same for vista, but worth a try.
On Windows XP, you can modify a group policy setting to change how frequently it re-prompts you. (start -> run type gpedit.msc)
Look under Computer Configuration/Administrative Templates/Windows Components/Windows Update
The setting you want is called Re-Prompt for restart with scheduled installations.
The default is 10 minutes.
You can also try modifying the No auto-restart for scheduled Automatic Updates installations setting found in the same location.
Just turn off the Automatic Update service. It will restart the next time you reboot so you'll still get the updates done.
Running this in a command window will stop it until the next reboot.
sc stop wuauserv
I recommend disabling the auto update.
As a developer the last thing you need is to have random updates done to your workstation, especially while you are working. I set aside a time every month to go through the process manually. I avoid doing it if I am in the middle of testing something really important or up against an immediate deadline.
To clarify what ehogue said:
Start->Control Panel->Administrative Tools->Services->Automatic Updates->Right-click->Stop.
In Windows XP, after windows has been updated, I use the following trick: run this command
pssuspend wuauclt
pssuspend is a free sys-internals tool.
This way, you will not be prompted about restart.
I will risk some down-votes here by saying: this seems a little bit schizophrenic, though a lot of people ask for it.
If you want Windows to download and install the updates, but not complete the install process by rebooting - what's the point? Why not simply turn of AutoUpdates in the first place? if you don't even want the OS to tell you it would like to reboot, then how can you know that you need to, y'know, reboot?
Patches which call for a reboot are not fully active until that reboot is complete; thus your system remains vulnerable to the unpatched behaviour. If you are a human who goes to the bathroom or eats meals, I just do not understand the mentality of wanting to patch but then postpone the reboot for days, weeks, months. Better to stay unpatched!
just open taskmanager and right-click on "wuauclt.exe" en clcik stop or delete or something that should keep that program from running.

Resources