"But MSDN says the PreventMediaRemoval member is BOOLEAN? Thanks for confusing me MSDN!"
MSDN is right the problem is, that TRUE is a 32 Bit-Value (TRUE and true are not the same). So you send the value 0(FALSE) to your drive. And if I'm right, the function fails if you try to unlock drive you never locked before.
If I lock with (BYTE)TRUE : works
If I unlock a locked device using (BYTE)FALSE : works
If I try to unlock a device (without locking it first) using (BYTE)FALSE : gives error #22, The device does not recognize command
I think this is expected behavior. Please guide me in right direction if I am doing it wrong.
I have a C++ program running on Windows XP compiled with Visual C++ 6.0 containing the following code
if (remove(NewName) != 0)
errmsg = strerror(errno);
printf("Removal Error: %s\n", errmsg);
and this fails, offering to send a message to Microsoft about the error of my ways.
The file I want to rename(FileName) does exist and the file I want to rename it to(NewName) does not and none of my error messages appear.
Please make suggestions on how I should fix this.
I have just run this code and it works fine, so I suspect there is some part that you have not shown that is actually failing. Can you post the full program (assuming it's not hundreds of lines)? Also please surround it with <pre></pre> tags to keep it formatted properly, use the code block button at the top of the edit window.
I am working on a project where I need to catch the windows shutdown event through a windows service running in system account, delay shutdown and execute some shutdown scripts and then once the scripts have been completed the shutdown continues.Kindly suggest me some ways to do this via a windows service developed by me in C++.
I have to run this in all operating systems namely Windows XP, Windows Server 2003& 2008, Windows Vista,Windows 7. I tried it presently on XP , but the application is meant to be supporting all flavours of Windows after NT
This means that you will need to conditionally delay the shutdown based on what operating system the service is running on. There have been some changes in how a shutdown works in Vista and above. These changes are documented here:
I would suggest creating a hidden window in each interactive logon session and returning FALSE when the window recieves a WM_QUERYENDSESSION message. On Vista and above you will need to call ShutdownBlockReasonCreate before returning FALSE to the WM_QUERYENDSESSION message.
Also to call Abort shutdown Method my service first needs to know that a shutdown signal was received. So kindly tell me how my service will come to know about that a shutdown signal was received and where should I place a call to abortshutdown ?
To catch the Shutdown-Event you have to handle SERVICE_CONTROL_SHUTDOWN or SERVICE_CONTROL_PRESHUTDOWN
event in your HandlerEx callback function you registered with RegisterServiceCtrlHandlerEx.
(To use this, you need to say the system that your service supports shutdown events.
An other possibility is to use the SetConsoleCtrlHandler function where you handle the CTRL_SHUTDOWN_EVENT event in your HandlerRoutine.
After you catched the shutdown-event you have to use the function AbortSystemShutdown or just
delay your service-shutdown for example with the status SERVICE_STOP_PENDING.