Jump to content
Sign in to follow this  
Mark-

Elevation...

Recommended Posts

Hello,

 

Using CreateProcess I am attempting to launch another program of mine.

If the "Run this program as administrator", is enabled in the compatibility" tab. all works as expected. If not enabled, I get an OS error: "The requested operation requires elevation". Perhaps the manifest is in error.

 

This is the manifest I am using:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" name="Configure" version="1.0.0.0" processorArchitecture="x86"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        publicKeyToken="6595b64144ccf1df"
        language="*"
        processorArchitecture="*"/>
    </dependentAssembly>
  </dependency>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!--Windows 7-->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!--Windows 8 and Windows Server 2012-->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <!--Windows 8.1 and Windows Server 2012 R2-->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <!--Windows 10, Windows Server 2016 and Windows Server 2019-->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
    </application>
  </compatibility>
</assembly>

 

Any ideas?

 

Thanks,

 

Mark

 

Share this post


Link to post

I assume "I get an OS error" means "CreateProcess(..) returns false and GetLastError() will then return ERROR_ELEVATION_REQUIRED". Is that correct?

 

If so, it appears that CreateProcess(..) cannot be used to automatically handle the UAC prompt and everything beyond that for you. Use ShellExecute(..) instead.

 

Quote

Applications should be modified to use the ShellExecute APIs, because they correctly handle this elevation error and are more robust at error handling for future issues.

(Source: Using the ElevateCreateProcess Fix | Microsoft Docs)

  • Like 1

Share this post


Link to post
5 minutes ago, Der schöne Günther said:

I assume "I get an OS error" means "CreateProcess(..) returns false and GetLastError() will then return ERROR_ELEVATION_REQUIRED". Is that correct?

That is correct.

 

I have used and use ShellExecute in other code and will give it a try.

 

Thanks,

 

Mark

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×