The MASM Forum

General => The Campus => Topic started by: shaikkareem on March 02, 2014, 04:58:39 PM

Title: createfile in windows 7
Post by: shaikkareem on March 02, 2014, 04:58:39 PM
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
Title: Re: createfile in windows 7
Post by: sinsi on March 02, 2014, 05:23:35 PM
Pretty sure for Vista+ you would need admin rights to open a drive.
Have you tried running as admin?
Title: Re: createfile in windows 7
Post by: shaikkareem on March 02, 2014, 05:36:39 PM
Yes...and what i do if i dont . Now another thing what about returned truncte_existing message....
Title: Re: createfile in windows 7
Post by: sinsi on March 02, 2014, 05:43:51 PM
Post your code. Only Raymond Chen (http://blogs.msdn.com/b/oldnewthing/) can do psychic debugging.
Title: Re: createfile in windows 7
Post by: Vortex on March 02, 2014, 07:53:39 PM
Hi shaikkareem,

Try to turn off the user account control and you will be more comfortable.
Title: Re: createfile in windows 7
Post by: Antariy on March 03, 2014, 11:51:41 AM
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
Title: Re: createfile in windows 7
Post by: TWell on March 03, 2014, 10:23:24 PM
Read this (http://support.microsoft.com/kb/942448).
Title: Re: createfile in windows 7
Post by: Gunther on March 04, 2014, 03:38:16 AM
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
Title: Re: createfile in windows 7
Post by: shaikkareem on March 06, 2014, 02:57:50 PM
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'
Title: Re: createfile in windows 7
Post by: sinsi on March 06, 2014, 04:04:40 PM
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.
Title: Re: createfile in windows 7
Post by: shaikkareem on March 06, 2014, 05:15:03 PM
thanks sinsi.............,

how do i programmically run the program as administrator where i find on msdn page.....,the description any thing....................
Title: Re: createfile in windows 7
Post by: sinsi on March 06, 2014, 05:58:22 PM
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.
Title: Re: createfile in windows 7
Post by: jj2007 on March 06, 2014, 07:04:12 PM
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)
Title: Re: createfile in windows 7
Post by: shaikkareem on March 07, 2014, 07:28:59 PM
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
Title: Re: createfile in windows 7
Post by: sinsi on March 07, 2014, 08:24:01 PM
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)