C#, Process.Start hide?

我是研究僧i 提交于 2020-01-23 01:01:31

问题


public static void Main(string[] args){
    SearchGoogle("Test");
    Console.ReadKey(true);
}

static void SearchGoogle(string t){
    Process.Start("http://google.com/search?q=" + t);
}

Is there any way to hide the browser, so it won't pop up??


回答1:


Something like:

ProcessStartInfo startInfo = new ProcessStartInfo("http://google.com/search?q=" + t);
startInfo.WindowStyle = ProcessWindowStyle.Hidden;

Process.Start(startInfo);



回答2:


Perhaps you are looking for ProcessStartInfo.CreateNoWindow ?




回答3:


If you want the results instead of a Browser you can use the WebClient class.

using (var client = new WebClient())
{
    string html = client.DownloadString("http://google.com/search?q=" + "Test");
}



回答4:


Not sure why you'd need to do this, but hey, everyone has a reason. Here's ProcessStartInfo code that does exactly what you need:

ProcessStartInfo psi = new ProcessStartInfo(string.Format("http://google.com/search?q={0}",t));
psi.RedirectStandardOutput = false;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = true;

Process.Start(psi);


来源:https://stackoverflow.com/questions/2317767/c-process-start-hide

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!