0

I have created a windows application for refreshing all the open browsers in client machine. here is the link Need to refresh chrome browser using C#

Now i have converted that windows application to windows service but the problem is that its not working , because in my windows application i am refreshing browsers on the basis of processes running in task manager and i think in windows service it is unable to recognize any process.

Community
  • 1
  • 1
asif iqbal
  • 45
  • 2
  • 8

2 Answers2

0

It seems that it is because of permissions. When your are running your windows application it will be running with currently logged in user's permissions. When you have configured it as windows service, which account have you used? Try running your windows service as admin.

Anuj Yadav
  • 980
  • 11
  • 20
  • How can i run my service as admin, i am running visual studio as an administrator. – asif iqbal Oct 22 '14 at 07:04
  • @asifiqbal please do a google search for that. You can also refer existing thread e.g. http://stackoverflow.com/questions/22888712/run-service-with-administrator-privlages – Anuj Yadav Oct 22 '14 at 07:28
0

The easiest solution is to convert your application to a Windows Service using Topshelf. A sample initialisation call would look like this:

        HostFactory.Run(x =>
            {
                x.Service<MyServiceHost>(s =>
                    {
                        s.ConstructUsing(name => new MyServiceHost());
                        s.WhenStarted(tc => tc.Start());
                        s.WhenStopped(tc => tc.Stop());
                    });
                x.DependsOnEventLog(); // Windows Event Log
                x.DependsOnIis(); // Internet Information Server
                x.StartAutomaticallyDelayed();

                x.EnablePauseAndContinue();
                x.EnableShutdown();
                x.EnableServiceRecovery(rc =>
                    {
                        rc.RestartService(1); // restart the service after 1 minute
                        rc.SetResetPeriod(1); // set the reset interval to one day
                    });

                x.RunAsLocalSystem();

                x.SetDescription("The My Service provides services to the My Webspace web application that require elevated privileges, such as creating customer websites in IIS.");
                x.SetDisplayName("My Service");
                x.SetServiceName("MyService");
            });

In this example the service is running as the local SYSTEM account. Other options are: Local Service, Network Service, to prompt for credentials, or to use an explicit username/password (which would presumably be read from your config file) e.g. x.RunAs("username", "password");