News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

createfile in windows 7

Started by shaikkareem, March 02, 2014, 04:58:39 PM

Previous topic - Next topic

shaikkareem

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

sinsi

Pretty sure for Vista+ you would need admin rights to open a drive.
Have you tried running as admin?

shaikkareem

Yes...and what i do if i dont . Now another thing what about returned truncte_existing message....

sinsi

Post your code. Only Raymond Chen can do psychic debugging.

Vortex

Hi shaikkareem,

Try to turn off the user account control and you will be more comfortable.

Antariy

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


Gunther

You have to know the facts before you can distort them.

shaikkareem

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'

sinsi

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.

shaikkareem

thanks sinsi.............,

how do i programmically run the program as administrator where i find on msdn page.....,the description any thing....................

sinsi

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.

jj2007

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)

shaikkareem

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

sinsi

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