tags:

views:

39

answers:

2

Just trying to copy a file using CopyFile() function from the current directory to C:\windows\system32\drivers.

I wrote also manifest with "requestedExecutionLevel level="highestAvailable"" in it and I run mt to add it to resulting executable.

When I try to run it, Windows 7 UAC dialog popping out, I press "Yes", but CopyFile() returning "Access Denied" error. What is wrong? What should I check?

My manifest file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <v3:trustInfo xmlns:v3="urn:schemas-microsoft-com:asm.v3">
     <v3:security>
       <v3:requestedPrivileges>
         <v3:requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
       </v3:requestedPrivileges>
     </v3:security>
   </v3:trustInfo>
 </assembly>

My piece of C code:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    if (CopyFile ("aaa.sys", "C:\\windows\\system32\\drivers", FALSE)==FALSE)
        ErrorExit ("CopyFile");
+1  A: 

Hmm, not really sure what "highestAvailable" does. Remove all doubt and use "requireAdministrator" instead, that always works to get full admin privileges. Also make sure you use the right resource name and ID, RT_MANIFEST and 1.

Hans Passant
No, doesn't work.
Dennis Yurichev
I attach manifest by running: mt -manifest 1.manifest -outputresource:1.exe;1
Dennis Yurichev
Post the manifest content, what kind of OS, details of the user account and the rights it has in the directory.
Hans Passant
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <v3:trustInfo xmlns:v3="urn:schemas-microsoft-com:asm.v3"> <v3:security> <v3:requestedPrivileges> <v3:requestedExecutionLevel level="requireAdministrator" uiAccess="false"/> </v3:requestedPrivileges> </v3:security> </v3:trustInfo></assembly>
Dennis Yurichev
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ if (CopyFile ("aaa.sys", "C:\\windows\\system32\\drivers", FALSE)==FALSE)
Dennis Yurichev
OS is Windows 7
Dennis Yurichev
Put it in your question. This answer will self-destruct in 5 minutes.
Hans Passant
+1  A: 
  • requireAdministrator = Always require admin elevation.
  • highestAvailable = If member of admin group, elevate. If normal user, run as normal user without elevation.
Anders
both not working
Dennis Yurichev