Announcement

Collapse
No announcement yet.

Run a file as administrator in windows 8 or 7 ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Run a file as administrator in windows 8 or 7 ?

    hi
    i have a program that need administrator permission on windows 7 and higher
    i can right click manually and select run as administrator for my executable file but i must put that file into my package that i have creat with autoplay media studio
    i was saw an action with name of file.Runas
    my question is : is do right this command ? if i write Administrator in value of username that file run as administrator ?

  • #2
    If a program needs to be run as administrator, it should be manifested as such when it was compiled. Programs needing administrative privileges should request them when started normally, using Shell.Execute(), from your code or via a Quick Action. If the program does not show the UAC dialog when started, then update the program so it conforms to current Windows software guidelines.

    Ulrich

    Comment


    • #3
      thank you but there is a problem
      the program that i need to execute by administrator privilages run wrong in regular mode
      the program get a code hardware
      in regular mode program get wrong code and if i execute it by administrator mode that get right code
      i hope that you know my mind

      Comment


      • #4
        As I said, you need to correct "the program", which previously you referred to as "my executable file". Again, if this is your program as you claim, you should definitely correct it, making it ask for elevation when it starts, via Shell.Execute(). This is how things should be done since Windows Vista, which was released years ago.

        Running a program under credentials of an account with administrative rights on the computer is not the same as running the program "as administrator". One thing refers to the credentials used to log in and run the process on, the other refers to user elevation, which is another user token. Even an administrator needs to confirm the User Account Control request for elevation, when running a program which needs to perform changes to the computer, or the operation will fail. This is what you can get when you use File.RunAs() even using an admin account:
        Click image for larger version

Name:	SCRN-2014-12-05-01.png
Views:	1
Size:	19.4 KB
ID:	284264

        So now that you know how to do it properly, it should also be clear how you can run this program via AutoPlay Media Studio, although in a clumsier way: You need to manifest the AutoPlay application to be run with the "Require administrator" setting. The user elevation is requested at the program start, via the User Account Control dialog. If the current user is not an administrator, then credentials of an admin account must be provided before the elevation can be performed. Once the process was elevated, run "your executable file" with File.Run(), so the child process inherits the administrative rights previously granted via the UAC.

        Ulrich
        Last edited by Ulrich; 12-05-2014, 12:12 PM.

        Comment

        Working...
        X