-1

I am trying to execute 'move' command, how you would in the command prompt, but it fails using Process.Start(). I understand move seems to be some integrated part of cmd and not an isolated executable, is there any way to trigger it using Process anyway ? I need to move some special location folder and trying to use elevated process instead of Directory.Move.

6
  • cmd /C <stuff>? I.e. invoke cmd.exe, and tell it to run its move command Commented Apr 29, 2021 at 10:48
  • Is elevation not available to your app so you can do it via C#? Commented Apr 29, 2021 at 10:50
  • I tried invoking cmd and tell it to run move but it does not work Commented Apr 29, 2021 at 11:10
  • its a net core service which tries to migrate some data, it can run process in elevated mode but it fails to Directory.Move Commented Apr 29, 2021 at 11:11
  • 2
    @frno What exactly did you try, and what makes you think it doesn't work? I've definitely called into cmd to do similar things in the past Commented Apr 29, 2021 at 12:06

1 Answer 1

1

That should work. The arguments should start with '/C' otherwise won't work.

var process = new Process
    {
         StartInfo = new ProcessStartInfo
            {
                FileName = "cmd.exe",
                Arguments = @"/C move ""test.txt"" ""test/test.txt""",
                UseShellExecute = false
            }
    };

process.Start();
Sign up to request clarification or add additional context in comments.

1 Comment

(Just as a note: the default for UseShellExecute changed from true to false with the introduction of .NET Core. Annoyingly, therefore, portable code which runs on both Framework and Core needs to always explicitly set it, as this answer does)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.