0

I have copied the shortcut of my application in startup folder for all users. I want my application to start with admin privileges when the the system is restarted and a non-admin user logs in. This is important because my application is working with the windows services. For stooping/starting a windows service admin privileges are required.

Please let me know how can i do it.

spender
  • 117,338
  • 33
  • 229
  • 351
meriaz
  • 65
  • 1
  • 11
  • Are you saying that you want to run the application as an Administrator when running the .exe? – Sean Sep 11 '15 at 08:11
  • I think all the cool kids do this with the Windows task scheduler, not the startup folder. – spender Sep 11 '15 at 08:12

2 Answers2

1

You cannot force it to start with Admin priviliges -That's up to the user who runs your application.

However you can make sure that the application runs only in admin mode by adding this to your Manifest file:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Notice that it would pop up a UAC prompt on every start-up.

Goodluck.

Slashy
  • 1,841
  • 3
  • 23
  • 42
  • Will give a UAC prompt at every startup. – spender Sep 11 '15 at 08:16
  • 1. The shortcut of my application is in System Startup folder. 2. I have added the above mentioned manifest to my application. 3. I restarted the system. 4. No UAC appeared for my application. 5.Application did not start. What should i do now? – meriaz Sep 28 '15 at 11:20
0

Add the following code to your Manifest:

<?xml version="1.0" encoding="utf-8" ?> 
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <assemblyIdentity version="1.0.0.0" name="MyApplication" />
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
            <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
            </requestedPrivileges>
        </security>
    </trustInfo>
</asmv1:assembly> 
Sean
  • 442
  • 3
  • 6
  • 19
  • Will give a UAC prompt at every startup. – spender Sep 11 '15 at 08:15
  • 1. The shortcut of my application is in System Startup folder. 2. I have added the above mentioned manifest to my application. 3. I restarted the system. 4. No UAC appeared for my application. 5.Application did not start. What should i do now? – meriaz Sep 28 '15 at 08:03