-1

I'm trying to run this command in cmd from c# but for some reason it doesn't work. But when I change my Argument to "/C ipconfig" it work perfectly. I don't understand why. What am I doing wrong? Here is my code:

   Process process = new Process();
        process.StartInfo.FileName = "cmd.exe";
        process.StartInfo.Arguments = $"/C wbadmin start backup - backupTarget:{TargetBackupDrive}: -include:{LocationOs}: -allcritical - quiet";
        process.StartInfo.CreateNoWindow = true;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardInput = true;
        process.StartInfo.Verb = "runas";
        process.Start();
        CmdOutput = process.StandardOutput.ReadToEnd();
        process.WaitForExit();
Red hood
  • 29
  • 1
  • 1
  • 7

1 Answers1

0

The verb "runas" does not work when UseShellExecute is set to false as it is pointed out here: Set ProcessStartInfo.EnvironmentVariables when Verb="runas"

You could either provide admin credentials with the UserName and Password properties our set UseShellExecute to true and execute your command in the shell.

René
  • 100
  • 1
  • 8