0
我開始使用下面的代碼chrome。c#爲什麼chrome不讓我用user32.dll隱藏它ShowWindow()
Process OpenYouTube = new Process();
Chrome.StartInfo.FileName = "chrome.exe";
Chrome.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Chrome.Start();
然後使用下面的代碼試圖隱藏它。
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
const int SW_SHOW = 5;
HideProcessAndChildren(Chrome.Id);
private void HideProcessAndChildren(int pid)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid);
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
HideProcessAndChildren(Convert.ToInt32(mo["ProcessID"]));
}
try
{
Process proc = Process.GetProcessById(pid);
ShowWindow(proc.MainWindowHandle, SW_HIDE);
}
catch (ArgumentException ex)
{
// Process already exited.
}
}
此代碼適用於記事本等,但Chrome拒絕隱藏。
我怎樣才能隱藏它一旦啓動或啓動時?我知道硒等
感謝輸入帕特里克,你能解釋一下爲什麼請:-) – jamie
@jamie做一個谷歌搜索「C#隱藏的鍍鉻」或「 ChromeDriver隱藏鉻「,你應該得到更多的信息。 – Patrick