I want my code to automatically start a service if it's not already running when my program starts, then stop upon exit. I found the code to do this, but my program just gives me access denid errors when started. I believe I have to do some hockery pockery with tokens? although I cant find the code anywhere to do this, just wondering if anyone could help me out
Hi, the service is a local service and the exception it throws is :
System.InvalidOperationException was unhandled
Message="Cannot open screen-scraper server service on computer '.'."
Source="System.ServiceProcess"
StackTrace:
at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess)
at System.ServiceProcess.ServiceController.Stop()
at WinScraper.Program.Main() in C:\WinScraper\WinScraper\WinScraper\Program.cs:line 34
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.ComponentModel.Win32Exception
Message="Access is denied"
ErrorCode=-2147467259
NativeErrorCode=5
InnerException:
as you can see it says InnerException: System.ComponentModel.Win32Exception
Message="Access is denied", so I presumed that has something to do with windows permissions?
Check this thread for a discussion of some of the permission type issues you will run into...
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
is the basic code I'm using to check if the service is running already, and if not then to start it. I know it's recognising the service etc, no problem getting status and things like that, just don't have the permissions to start/stop the service. Still can't find a way to do this..
is the basic code I'm using to check if the service is running already, and if not then to start it. I know it's recognising the service etc, no problem getting status and things like that, just don't have the permissions to start/stop the service. Still can't find a way to do this..
Did you follow the links in the next to last two replies in the thread I provided???
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009 In theory, there is no difference between theory and paractice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Bookmarks