redirect - Redirecting output from elevated process C# -
i need run elevated process c#, , need redirect input , output. since doing 3 impossible, think may have come workaround, doesn't seem work.
process p = new process(); string command1 = "/s " + path + "\\script1.script"; p.startinfo = new processstartinfo("diskpart",command1) { useshellexecute = true, createnowindow = false, verb="runas" }; p.start(); p.waitforexit();
that works. calls diskpart script list volume
. want capture output outfile1.txt
. when run following command terminal works: diskpart /s script1.script>outfile1.txt
however, when modify command1
"/s " + path + "\\script1.script>+path+"\\outfile1.txt"
error diskpart unable open or read file. doing wrong?
edit
didn't find solution, found workaround.
i trying drive letter of usb drive wanted set readonly. however, using driveinfo.name
able it. (it have been more helpful if called driveinfo.driveletter
) wrote diskpart script accordingly.
you might have syntax error in command1. said changed to:
"/s " + path + "\script1.script>+path+"\outfile1.txt"
and think want is(missing 1 double quotation mark):
"/s " + path + "\script1.script>" + path + "\outfile1.txt"
if that's not case, happens when use terminal command - "diskpart /s script1.script>outfile1.txt" - command1? might want @ other stackoverflow topic running commands in c#:
Comments
Post a Comment