Okay I am trying to lock CD drive (F: here) with the code shown. But DeviceIoControl is returning "error 87: Parameter not correct". Please someone help me. I cannot find out which parameter is incorrcet.
Yes hVolume is right value. GetLastError returns 0.
GENERIC_READ already has FILE_READ_ATTRIBUTES
Tried using 0 for File sharing but still DeviceIoControl gives error 87 parameter not correct
Thanks for replying, I appreciate it.
"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++.