i trying start notepad.exe in hidden mode below code have written:-
try { processstartinfo startinfo = new processstartinfo(); startinfo.createnowindow = false; startinfo.useshellexecute = false; startinfo.filename = "notepad.exe"; startinfo.windowstyle = processwindowstyle.hidden; startinfo.arguments = @"c:\users\sujeet\documents\test.txt"; } catch { }
but problem process(i.e. notepad.exe) gets started startinfo.windowstyle = processwindowstyle.hidden not working. have surfed net problem not able proper solution.
this version works on box:
try { processstartinfo startinfo = new processstartinfo(); startinfo.createnowindow = false; startinfo.useshellexecute = true; startinfo.filename = @"%windir%\system32\notepad.exe"; startinfo.windowstyle = processwindowstyle.hidden; startinfo.arguments = @"c:\users\sujeet\documents\test.txt"; process.start(startinfo); } catch { }
i win32exception telling file (test.txt) cannot found, process runs, , no window visible.
take care exit process, or user end invisible processes running.
if application uncooperative (like calc.exe mentioned in comments), try following:
define somewhere:
[dllimport("user32.dll")] private static extern bool showwindow(intptr hwnd, int ncmdshow); const int sw_show = 5; const int sw_hide = 0;
and following after crating process:
var proc = process.start(startinfo); while (proc.mainwindowhandle == intptr.zero) //note: works long process creates main window. system.threading.thread.sleep(10); showwindow(proc.mainwindowhandle, sw_hide);
i don't know why path %windir%\system32\calc.exe
not work, works startinfo.filename = @"c:\windows\system32\calc.exe";
Comments
Post a Comment