如何使用.NET中的Windows服务打开网站URL [英] How to open website URL using windows service in .NET

查看:242
本文介绍了如何使用.NET中的Windows服务打开网站URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开网站网址,每2分钟从Windows服务下载PDF文件,我使用以下条件但是没有打开网址而且没有任何错误



我尝试了什么:



我试过下面



<预> ProcessStartInfo sInfo = new ProcessStartInfo(www.google.com); 
Process.Start(sInfo);



 Thread.Sleep(100000); 



打开此URL后,我将关闭此流程如下



 Process [] AllProcesses = Process.GetProcesses(); 
foreach(AllProcesses中的var进程)
{
if(process.MainWindowTitle!=)
{
string s = process.ProcessName.ToLower();
if(s ==iexplore|| s ==iexplorer|| s ==chrome|| s ==firefox)
process.Kill();
writelog(Browsser关闭文件);
}
}









以上相同的代码在Windows窗体应用程序中工作但在Windows服务中它无法正常工作,请协助解决此问题

解决方案

问题是你实际尝试打开 - 可视化 - 网站... Windows服务没有用户界面,没有显示权限的访问权限,因此通过进程运行URL将被阻止...

您想要下载来自URL的文件,您应该使用 WebClient.DownloadFile [ ^ ] ...

I want to open website URL to download PDF file from windows service for every 2 minutes, I am using following criteria but it's not opening the URL and not giving any error

What I have tried:

I tried Below

<pre> ProcessStartInfo sInfo = new ProcessStartInfo("www.google.com");
       Process.Start(sInfo);


Thread.Sleep(100000);


After opening this URL I am closing this process as follows

Process[] AllProcesses = Process.GetProcesses();
foreach (var process in AllProcesses)
{
    if (process.MainWindowTitle != "")
    {
        string s = process.ProcessName.ToLower();
        if (s == "iexplore" || s == "iexplorer" || s == "chrome" || s == "firefox")
            process.Kill();
        writelog("Browsser closed Files");
    }
}





The above same code is working in windows form application but in windows service it's not working, Please assist to solve this

解决方案

The problem is that you actually try to open - visually - the site... A Windows service has no UI and has no access rights to display one, so running the URL via process will be blocked...
As you want to download a file from an URL, you should use WebClient.DownloadFile[^]...


这篇关于如何使用.NET中的Windows服务打开网站URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆