Page 1 of 1

Console program as Adminstrator

Posted: 16 Jun 2023 18:52
by daveplummermd
Hello. Trying to run Robocopy as a command line or within a batch file and wish to use robocopy's backup switch (/ B) wich requires administrative privileges.
Using this code:

Code: Select all

  ...   Command =             string::format(@[robocopy %  % /e /b /mir /xo /im /np /LOG:Backup.log], SourceDir, DestinationDir),         RunObj = useExe::new(Command),         RunObj:run(),         ...
The robocopy log reveals an error for lack of admin privileges.
I am using Windows 11 and signed in under an administrator account.
Are there any suggestions to "run" the useExe object as admin?
Thanks in advance.
Dave

Re: Console program as Adminstrator

Posted: 16 Jun 2023 21:59
by Thomas Linder Puls
That is only possible if your program itself run in elevated state (you can require that using an option in the project settings, which will change the manifest file).

If your program runs in normal mode and you want to launch an elevated program from it, then you will need to use shell_api::shellExecute with "runas" as Command. But that will just launch the program; you will not get any handle to it or any other information about the process at all.

Re: Console program as Adminstrator

Posted: 19 Jun 2023 19:01
by daveplummermd
This is very helpful. Thanks Thomas!