c# - Start WebClient Windows Service from Manual state in code -


the webclient windows service installed , set manual default; due customer's restrictions unable change automatic.

when service stopped , try access files directory.enumeratedirectories exception:

an unhandled exception of type 'system.io.directorynotfoundexception' occurred in mscorlib.dll

additional information: not find part of path '\mysever\myfolder'.

when webclient service started works fine.

accessing path using explorer works fine webclient service started part of request.

from code, how can tell windows want access webclient service should start it?

i have following (working) code, unsure if requires administrator permission or if there better way this:

using (servicecontroller servicecontroller = new servicecontroller("webclient")) {     servicecontroller.start();     servicecontroller.waitforstatus(servicecontrollerstatus.running); } 

effectively want execute command net start webclient, above code cleanest way , there security restrictions need aware of in locked down environment?

i have checked msdn servicecontroller.start method , doesn't seem if users must administrator or not.

you need administrative privileges.

you can test out below code in console application on computer webclient service turned off. running without administrative privileges gives "cannot start service on computer '.'"

static void main(string[] args) {     string servicetorun = "webclient";      using (servicecontroller servicecontroller = new servicecontroller(servicetorun))     {         console.writeline(string.format("current status of {0}: {1}", servicetorun, servicecontroller.status));         if (servicecontroller.status == servicecontrollerstatus.stopped)         {             console.writeline(string.format("starting {0}", servicetorun));             servicecontroller.start();             servicecontroller.waitforstatus(servicecontrollerstatus.running, new timespan(0, 0, 20));             console.writeline(string.format("{0} {1}", servicetorun, servicecontroller.status));         }     }      console.readline(); } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -