c# - Opening Command Prompt and Performing Commands -
first , foremost, first program , new programming overall outside of html , js. being said, building application gathers , collects system files used troubleshooting purposes. have basic understanding of have done far, having issues dxdiag arguments here:
var process = new process(); var startinfo = new processstartinfo(); // startinfo.windowstyle = system.diagnostics.processwindowstyle.hidden; startinfo.filename = "cmd.exe"; startinfo.arguments = @"/c dxdiag /whql:on /t %userprofile%\desktop\my system files\dxdiag.txt"; process.startinfo = startinfo; process.start(); process.waitforexit();
*to clarify, commented out hidden line can see cmd windows doing while build application.
now have looked , have found multiple other threads relating usage of similar code cannot figure out why variant not work using arguments have included. block bring cmd , execute dxdiag command. have tested command in cmd multiple times ensure works , does. problem is, argument above not execute within cmd prompt initiated. including full block of code below give more context utilizing msinfo32 export well. not executing commands either (did not expect different result here).
using system; using system.io; using system.diagnostics; namespace system_file_collection_app { class program { public static void main(string[] args) { // dxdiag output var process = new process(); var startinfo = new processstartinfo(); //startinfo.windowstyle = system.diagnostics.processwindowstyle.hidden; startinfo.filename = "cmd.exe"; startinfo.arguments = @"/c dxdiag /whql:on /t %userprofile%\desktop\my system files\dxdiag.txt"; process.startinfo = startinfo; process.start(); process.waitforexit(); // msinfo32 output var process = new process(); var startinfo = new processstartinfo(); //startinfo.windowstyle = system.diagnostics.processwindowstyle.hidden; startinfo.filename = "cmd.exe"; startinfo.arguments = @"/c msinfo32 /nfo %userprofile%\desktop\my system files\"; process.startinfo = startinfo; process.start(); process.waitforexit(); } } }
the indents screwed bit when copied on checks out , able run program.
edit: stripping out dxdiag arguments , using dxdiag along in code works fine. used testing point ensure command initiate. don't quite understand why secondary arguments not used.
does not work:
startinfo.arguments = @"/c dxdiag" + "/whql:on" + "/t \"%userprofile%\\desktop\\dxdiag.txt\"";
works:
startinfo.arguments = @"/c dxdiag";
you forgot spaces between arguments, 1 works fine:
startinfo.arguments = @"/c dxdiag /whql:on /t %userprofile%\desktop\examples\new folder\myinfo.txt"
note path folder must exist, otherwise won't work.
Comments
Post a Comment