Command Line Elevated Privileges?

Greetings -

I would like to use some of the file management command line utilities that require elevated privileges. Does it require running the host app with elevated privileges? Or, is there a way to elevate privileges when you run the shell like you can when you open the Command Line window?

Many thanks

I would have my primary Xojo application run with Administrator privileges, then any process that it spawns (via Shell, as well, IIRC) should also have those privileges. This can be done by clicking “Windows” under Build Settings in the Navigator pane, then setting the Privileges property in the Inspector after clicking the gear icon at the top.

Thanks, Anthony -

Did not think to look at build settings. Will try that!


1 Like

If that doesn’t work, let me know. I have some code around here somewhere to execute a Shell command with elevation.

Hello, i want to run a command line that adds a user to windows, i need admin rights to do this, but have not found the way to achieve this. Hope you can help me with some code that can do the trick.
Thank you!

Thank you so much! Will test and let you know


Have been looking at the RunAs method! We are trying to execute commands that create users in a windows OS as per parameters from the end user, execute commands that require to be executed as Administrator, but are having trouble with the way we should call the RunAs so we can achieve our requirements.

for example, a basic command would be:
net user username password /ADD /FULLNAME:“User_Fullname”
net localgroup administrators John /add
I would appreciate it very much if you help me find my way on how to call the RunAs method for the above commands. Thank you so much!

In canvasDrag.MouseDown there’s a few lines where it creates a bat file with a command in that will be elevated and run, if you take that code and alter it to add all your commands you will able run a bunch of elevated commands in a single command that you elevate.

You could do it that way or create an elevated command line app that you call with some command line parameters to perform your multiple operations.

Here’s a method I’ve been using to launch a Windows helper app that needs admin privileges, I don’t remember where I got it from (probably this forum), but it works great -

Public Sub LaunchAsAdministrator(extends f as FolderItem, ParamArray args as String)
#If TargetWindows

Soft Declare Sub ShellExecuteA Lib "Shell32" ( hwnd As Int32, operation As CString, file As CString, params As CString, directory As CString, show As Int32 )
Soft Declare Sub ShellExecuteW Lib "Shell32" ( hwnd As Int32, operation As WString, file As WString, params As WString, directory As WString, show As Int32 )

Dim params As String
params = JoinNew( args, " " )

If System.IsFunctionAvailable( "ShellExecuteW", "Shell32" ) Then
  ShellExecuteW( 0, "runas", f.NativePath, params, "", 1 )
  ShellExecuteA( 0, "runas", f.NativePath, params, "", 1 )
End If

End Sub

Thank you John -

I can still use that!