Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,156 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,055 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Start/Stop Services with ASP.NET

 
Reply to this topicStart new topic

Start/Stop Services with ASP.NET

RodgerB
post 21 Jun, 2008 - 04:50 AM
Post #1


D.I.C Lover

Group Icon
Joined: 21 Sep, 2007
Posts: 1,985



Thanked 8 times

Dream Kudos: 2200
My Contributions


The last puzzle piece of my most recent project has been a tricky one, starting and stopping the squid service (it is a proxy server). The reason I need this is to refresh the list of blocked sites.

Here is the code I am using:

vb

'Try
Dim squidService As New System.ServiceProcess.ServiceController("Squid")

If squidService.Status = ServiceProcess.ServiceControllerStatus.Running Then
' Problem Occurs Here.
squidService.Stop()
End If

squidService.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

squidService.Start()
squidService.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running)

'Catch ex As Exception
'lblInfo.Text = "An error occurred while attempting to restart squid: " + ex.Message
'End Try


The exception handling has been commented out so I could get detailed exception information. The problem occurs when I try to stop the squid service, the error given is "Access is denied". I am using IIS 7, and have tried a handful of ways to try and set my application to run as a domain administrator (Application Pools), to no avail.

I have tried other methods such as invoking taskkill.exe, creating an external console application and calling it to do the work via the ASP.NET (which does the job without being called by ASP.NET), all to no avail. The Web Application has been given full trust.

Does anybody have any ideas as to what could be up with this? I have a hunch that it's got something to do with User Permissions, but don't know enough about IIS to set them (which I have attempted and failed).

Any assistance would be greatly appreciated. Attached is an image of what the exception looks like via web debugging. Thanks in advance smile.gif

Attached Image
User is online!Profile CardPM

Go to the top of the page


marcells23
post 21 Jun, 2008 - 08:13 PM
Post #2


D.I.C Head

Group Icon
Joined: 22 Aug, 2007
Posts: 116



Thanked 2 times

Dream Kudos: 125
My Contributions


are you using impersonation in your web config?
User is offlineProfile CardPM

Go to the top of the page

RodgerB
post 21 Jun, 2008 - 09:55 PM
Post #3


D.I.C Lover

Group Icon
Joined: 21 Sep, 2007
Posts: 1,985



Thanked 8 times

Dream Kudos: 2200
My Contributions


I've tried all methods of impersonation found in the Microsoft Help and Support article here: http://support.microsoft.com/default.aspx?...b;EN-US;Q306158 (web.config, and code).

All result in the same access denied error sad.gif. I will wait until my brother gets home and see if he can authenticate me with an account of higher power (i am using a network administrator account), but I can't really do anything as it isn't my server.

Thanks for your help. smile.gif
User is online!Profile CardPM

Go to the top of the page

RodgerB
post 11 Jul, 2008 - 06:22 PM
Post #4


D.I.C Lover

Group Icon
Joined: 21 Sep, 2007
Posts: 1,985



Thanked 8 times

Dream Kudos: 2200
My Contributions


W00t fixed it. For those interested in how I fixed it, I did it by editing the web.config in the top-level directory of the application folder and adding impersonation details to it.

I feel like such an idiot. wink2.gif
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/5/08 05:24PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month