-
CreateFile() and UAC
Hello everyone,
This is my first post so please go easy on me :biggrin:.
I have just started diving into Win32 programming using the book Windows System Programming by Johnson M. Hart. In chapter 2 he develops three versions of a simple file-copy program. The first version uses the straightforward C standard library approach using fopen() and fwrite(). This works without a hitch.
The second version uses the Windows API CreateFile() function. This program also works but I only in an elevated command prompt or the program returns a file-not-found error.
I've read that Windows 7 onwards needs admin privileges to access a file's handle. Assuming this was done for security reasons, it seems like a loophole that standard C library file routines bypass this protection. Granted, this is a very simple example program which doesn't show the full benefit of the Windows API or UAC.
Am I misunderstanding the role of UAC, or is this actually the way it is supposed to work? And if so, how do the built-in Windows file manipulation utilities get round it?
-
I suppose the first question would be which files were you trying to access?
Regular files in your "My Documents" folder shouldn't be an issue.
Trying to mess with C:\Windows\System32 on the other hand....
-
Thanks for the reply! I was trying to copy a plain text file 'foo.txt' that I had created manually using Notepad. I tried to copy this file inside the Visual Studio Debug folder and needed to elevate. I then copied my executable and the text file to a folder on my desktop and tried the same copy command. Again I needed to elevate. Using the standard C library functions no elevation was required.