-
January 12th, 2009, 08:59 AM
#1
Access denied when starting a service
Hi,
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
thanks
-
January 12th, 2009, 09:56 AM
#2
Re: Access denied when starting a service
Could you give some more information. Where do you want to start the service, local or on a network device?
Give some more details about the exception, (kind of exception, innerexception)
-
January 12th, 2009, 10:17 AM
#3
Re: Access denied when starting a service
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?
-
January 12th, 2009, 06:01 PM
#4
Re: Access denied when starting a service
Please post the code you use to start the service (and use [code ] [/ code] tags).
-
January 12th, 2009, 06:15 PM
#5
Re: Access denied when starting a service
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,2010
In theory, there is no difference between theory and practice; 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
-
January 12th, 2009, 07:56 PM
#6
Re: Access denied when starting a service
ServiceController sc = new ServiceController("screen scraper server");
if(sc.Status.Equals(ServiceControllerStatus.Stopped)){
sc.Start();
}
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..
-
January 12th, 2009, 08:11 PM
#7
Re: Access denied when starting a service
Originally Posted by Bobby_1234
ServiceController sc = new ServiceController("screen scraper server");
if(sc.Status.Equals(ServiceControllerStatus.Stopped)){
sc.Start();
}
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,2010
In theory, there is no difference between theory and practice; 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|