2012-07-13 85 views
0

我正在使用來自服務的類庫運行應用程序的EXE。 但是我試圖做的是隱藏應用程序EXE的窗口。 這裏是我的代碼:如何隱藏應用程序窗口,當它的EXE從進程調用?

在我的類庫的功能: -

public class MyClassLibrary 
{ 
    public void MyFunction() 
    { 
     Process process = new Process(); 
     process.StartInfo.FileName = "C:\Program Files (x86)\MyFolder\MyApp.exe"; 
     process.StartInfo.CreateNoWindow = true; 
     process.StartInfo.UseShellExecute = false; 
     process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
     process.Start(); 
    } 
} 

而且這是在那裏我從調用它:

class MyClass : ServiceBase 
{ 
    ... 
    ... 
    ... 
    protected override void OnStart() 
    { 
     MyClassLibrary obj = new MyClassLibrary(); 
     obj.MyFunction(); 
    } 
} 

儘管上述所有的,窗口尚未見到。 任何人都可以請建議一個解決方案?

感謝和問候, Siddhant

+0

奇怪,這不應該發生。也;是否爲您開啓或關閉服務與桌面設置進行交互?檢查您的服務屬性 – 2012-07-13 10:58:02

+0

其實我認爲我會修改我的問題多一點.. – Siddhant 2012-07-13 11:13:28

+1

可能(C# - 啓動隱形進程[CreateNoWindow和WindowStyle不工作?)](http://stackoverflow.com/questions/3011209/ c-sharp-launch -invisible-process-createnowindow-windowstyle-not-working)幫助 – Arne 2012-07-13 11:16:30

回答

0

我曾嘗試你的代碼不工作,但

但是,當我這樣嘗試一下它工作正常

string filePath = @"C:\Program Files (x86)\Internet Explorer\iexplore.exe";  
ProcessStartInfo pStartInfo = new ProcessStartInfo(filePath); 
pStartInfo.WindowStyle = ProcessWindowStyle.Hidden; 

Process.Start(startInfo); 

原因,它的工作原理與Process.Start(ProcessStartInfo),因爲它 將給定的信息與新組件關聯,如 MSDN

0

我已經得到了答案的傢伙,這要歸功於this評論,這是我從Arne的評論得到了在這個問題的頂部..顯然,這似乎Process.StartInfo.UseShellExecute應該設置爲true

感謝大家的幫助!乾杯!

0
string filePath = @"C:\Windows\System32\notepad.exe"; 
ProcessStartInfo pStartInfo = new ProcessStartInfo(filePath); 

**pStartInfo.UseShellExecute = true;** 

pStartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
Process.Start(pStartInfo); 

注:設置pStartInfo.UseShellExecutetrue否則,你得到一個錯誤

相關問題