Shell command in Adminstrator mode

  1. 7 years ago

    Dale A

    13 Jul 2013 San Diego, California, USA

    I have a program that I need to have execute a shell command in administrator mode. Is this possible from a Xojo app? If so, how do I structure the shell.execute command?

    - Dale

    If you're using the Shell class, you could probably use the runas command which comes with Windows.

    You could also use a declare to invoke the runas verb directly:

    Sub LaunchAsAdministrator(ProgramEXE as FolderItem, ParamArray Arguments as String)
      #If TargetWin32
        Declare Function ShellExecuteW Lib "Shell32" (HWND As Integer, verb As WString, file As WString, params As WString, directory As WString, cmd As Integer) As Integer
        Dim params as String
        params = Join(Arguments, " ")
        Call ShellExecuteW(0, "runas", ProgramEXE.AbsolutePath, params, App.ExecutableFile.Parent.AbsolutePath, 1)
      #Endif
    End Sub
  2. Andrew L

    13 Jul 2013 Answer San Francisco, CA, USA

    If you're using the Shell class, you could probably use the runas command which comes with Windows.

    You could also use a declare to invoke the runas verb directly:

    Sub LaunchAsAdministrator(ProgramEXE as FolderItem, ParamArray Arguments as String)
      #If TargetWin32
        Declare Function ShellExecuteW Lib "Shell32" (HWND As Integer, verb As WString, file As WString, params As WString, directory As WString, cmd As Integer) As Integer
        Dim params as String
        params = Join(Arguments, " ")
        Call ShellExecuteW(0, "runas", ProgramEXE.AbsolutePath, params, App.ExecutableFile.Parent.AbsolutePath, 1)
      #Endif
    End Sub
  3. Dale A

    14 Jul 2013 San Diego, California, USA

    Thanks, Andrew. I'll look into that as a solution.

or Sign Up to reply!