Delay Windows shutdown
-
Royce Fickling wrote:
Can that be done?
Only if you are interested in
SERVICE_CONTROL_STOP
."Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
At this point when I go get a cup of coffee if feels like you are following me ;P
led mike
Nah. I usually open a dozen or so browser windows with various CP threads. By the time I get around to answering the last few, anywhere from 5-25 minutes may have passed since the OP's question, thus I'm usually repeating what has already been said.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Nah. I usually open a dozen or so browser windows with various CP threads. By the time I get around to answering the last few, anywhere from 5-25 minutes may have passed since the OP's question, thus I'm usually repeating what has already been said.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I have a Windows service in which I need to detect the Windows shutdown event and, depending on what kind of processing I am doing at the time, delay the shutdown for a few seconds until my processing is complete. Can that be done? Any help appreciated.
AbortSystemShutdown() http://msdn2.microsoft.com/en-us/library/aa376630(VS.85).aspx[^] Sample Usage:
BOOL AbortShutdown(LPTSTR lpMachineName) { HANDLE hToken; // handle to process token TOKEN_PRIVILEGES tkp; // pointer to token structure BOOL fResult; // system shutdown flag // Get the current process token handle so we can get shutdown // privilege. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { TRACE("OpenProcessToken failed.\n"); return false; } // Get the LUID for shutdown privilege. LookupPrivilegeValue(lpMachineName, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Get shutdown privilege for this process. AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0); // Cannot test the return value of AdjustTokenPrivileges. if (GetLastError() != ERROR_SUCCESS) { TRACE("AdjustTokenPrivileges(setting) enable failed.\n"); return false; } // Prevent the system from shutting down. fResult = AbortSystemShutdown(lpMachineName); if (!fResult) { TRACE("AbortSystemShutdown failed.\n"); return false; } else m_bIsShuttingDown = false; // Reset shut down flag // Disable shutdown privilege. tkp.Privileges[0].Attributes = 0; AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); if (GetLastError() != ERROR_SUCCESS) { TRACE("AdjustTokenPrivileges(re-setting) disable failed.\n"); return false; } return true; }
-
DavidCrow wrote:
I usually open a dozen or so browser windows with various CP threads.
How do you do that? Can you email the code?
led mike
Is it urgent?
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Is it urgent?
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I have a Windows service in which I need to detect the Windows shutdown event and, depending on what kind of processing I am doing at the time, delay the shutdown for a few seconds until my processing is complete. Can that be done? Any help appreciated.
Read carefully: Service Control Handler Function[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Mark Salsbery wrote:
Is it urgent?
If you have to ask you don't understand anything about the codes
led mike
-
lol
-
-
Mark Salsbery wrote:
Fishing season is OPEN!
Didn't you get the memo? The season opens on January 1st at 00:00:00 and closes on December 31st at 24:59:59 Here's another[^]
led mike
:doh: Good one, thanks!
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Read carefully: Service Control Handler Function[^] Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark Salsbery wrote:
Service Control Handler Function[^]
Sounds more like a candidate for the Buzzword hall of shame forum. :doh:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
Mark Salsbery wrote:
Service Control Handler Function[^]
Sounds more like a candidate for the Buzzword hall of shame forum. :doh:
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
Rajesh R Subramanian wrote:
Mark Salsbery wrote: Service Control Handler Function[^] Sounds more like a candidate for the Buzzword hall of shame forum.
Nope :), it's actually a very concise description of the subject at hand - the specifics of the function which handles control messages for a service. MS surprisingly actually titled the page with meaningful text. Judy
-
Rajesh R Subramanian wrote:
Mark Salsbery wrote: Service Control Handler Function[^] Sounds more like a candidate for the Buzzword hall of shame forum.
Nope :), it's actually a very concise description of the subject at hand - the specifics of the function which handles control messages for a service. MS surprisingly actually titled the page with meaningful text. Judy
Thanks everyone for the help. The AbortShutdown() is what I was looking for. I know about the WM_QUERYENDSESSION message and how to handle it. Originally, I was looking for a way to get around the hidden window in my service, but because I have to interact with my user, I must use it.