Its really embarrasing.....
In windows xp createfile over the physicaldrive0 was well ,but in wind 7 its not working. After i callled it returning the message INVALID_FILE_ATTRIBUTE and after this i called getlasterror functon it is returnig FILE_UNKNOWN . I dont know what to do can some one tell me what is problem in returning the handle of physicaldrive0
Pretty sure for Vista+ you would need admin rights to open a drive.
Have you tried running as admin?
Yes...and what i do if i dont . Now another thing what about returned truncte_existing message....
Post your code. Only Raymond Chen (http://blogs.msdn.com/b/oldnewthing/) can do psychic debugging.
Hi shaikkareem,
Try to turn off the user account control and you will be more comfortable.
Did you specify the FILE_ATTRIBUTE_DEVICE to the CreateFile when opened the drive?
Try something like this:
invoke CreateFile,offset_to_the_drive_string,GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_DEVICE,0
Read this (http://support.microsoft.com/kb/942448).
Hi TWell,
Quote from: TWell on March 03, 2014, 10:23:24 PM
Read this (http://support.microsoft.com/kb/942448).
good hint. Thank you. :t
Gunther
hi TWell and Antariy.........thanks to u for your posts.....
first Antariy nothing happens with you suggestion it is still not returning handle to physicaldrive and i'm logged in with administrative level privillages....
and TWell i read that page from your sent link.............the question is they describing the causes and changes they made ,not the process how to operate with it in case of some restrictions are in affect..............
by the way the function is returning still error code no '-1'
and GetLastError function is returning error cod no '5'
From Windows 8.1, this code works if run as administrator
invoke CreateFile,offset disk,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0
If run normally, it returns FFFFFFFF and GetLastError returns 5 (access denied).
Don't forget that even though you are an administrator you still need to use "Run as administrator" or use a manifest for elevation.
thanks sinsi.............,
how do i programmically run the program as administrator where i find on msdn page.....,the description any thing....................
One way is to add to the linker command-line this
Quote/manifest:embed /manifestuac:"level=""requireAdministrator""
Not sure which version of link.exe supports it.
The other way is to add a manifest resource to the exe.
Sinsi,
That's not a solution for the OP. He wants to launch a prog from user level and get admin rights "programmatically". Actually, it's a fantastic idea, but I am sure it has been tried a Million times. Evil Microsoft doesn't like the idea, though 8)
with minimal parameters to CreateFile funtion running with the help of ' run as administrator' the function is working precisely but the headache is for every time i dont want to do that repeatedly, so it is like ****** thing you all know........what to do. apart from that studying about authentication,privilege levels support api on msdn.com may help me to do not doing that manually ............. hope so
If you want to always run as administrator then use a manifest.
If you want to occasionally run as administrator then look at GregL's code here (http://www.masmforum.com/board/index.php?topic=9422.msg68553#msg68553)