Results 1 to 7 of 7

Thread: [RESOLVED] run as admin shellexecute or manifest

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Resolved [RESOLVED] run as admin shellexecute or manifest

    i was wondering if a manifest file is better than the shellexecute "runas"

    shellexecute:

    vb Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    2. ShellExecute 0, "runas", App.Path & "\Project1.exe", Command, vbNullString, 3

    or manifest file:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
         <assemblyIdentity version="1.0.0.0"
    	processorArchitecture="X86"
    	name="ExeName"
    	type="win32"/>
     <description>elevate execution level</description>
        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> 
         <security>
             <requestedPrivileges>
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
             </requestedPrivileges>
          </security>
       </trustInfo>
    </assembly>

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: run as admin shellexecute or manifest

    I think it is most common to make use of a Manifest file

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: run as admin shellexecute or manifest

    It isn't that simple.

    For example you might use an AsInvoker manifest in the child program, which lets the parent choose when to "run" and when to "runas" for elevation.

    This is handy for a program that normally runs as a standard user, but has a few operations that require elevation once in a while. You can "runas" another copy of yourself passing command line arguments telling the elevated copy what to do. This can sometimes save duplicating a lot of code in a second program.

    I assume you know about using BCM_SETSHIELD to put the shield icon on the button that will start such elevated operations.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: run as admin shellexecute or manifest

    Thanks guys for the replies

    Dillettante. I see what you mean by only certain commands will require elevation. I do not know the setshield you are talking about but I have an idea of what you are saying it makes a lot of sense! Is the setshield another api I have to add? I do not have any idea how to put it in my program so far. If you could help me or give me a link on how it works please. But one thing I was asking is about shellexecute runas.. Does this give you the elevation of an admin? Or you need the manifest file to get the admin elevation? I will go with your idea of the setshield I think I just wanted to know.

    I see that you always have something better than what we ask for!! Thanks a lot for those ideas

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: run as admin shellexecute or manifest

    another question is there a way to have a name (publisher) in UAC when it asks for permission it says Unkown publisher... how do i put my programs name for the publisher

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: run as admin shellexecute or manifest

    Here is a small demo that uses a single Project/EXE to do:

    1. A standard user function (basically display a Form with a "Perform Function" button that starts a second elevated copy when clicked).

    2. An elevated function (basically just splitting a command line and doing a MsgBox of the split parts here).

    Obviously for a real program you'd do more in both of these, and perhaps even have severaal different #2's or maybe have #2 display its own Form to do more complicated things requiring elevation.

    Note that if #1 is run with elevation ("as admin") in the first place no Shield icon is shown and the #2 functionality is performed by the same instance of the program.


    If you want a Publisher Name and "calmer" colors in your UAC prompt dialogs you need to obtain a code certificate and sign your code. Some info on that can be read in:

    Understanding User Account Control

    There are screen captures there showing what the different flavors look like too.

    More details can be found at Introduction to Code Signing.
    Attached Files Attached Files
    Last edited by dilettante; Feb 25th, 2012 at 11:04 PM.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [RESOLVED] run as admin shellexecute or manifest

    Thanks again dillettante works like a charm now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width