Click here to Skip to main content
15,911,132 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 17-Jun-17 22:38pm
v2

1 solution

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[^]...
 
Share this answer
 
Comments
Divyay208 19-Jun-17 4:03am    
Thank You For your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900