service control permission problem as the same code works in application


I have the following code for my webmethod to control the Print Spooler service although Im getting a webby permission problem because copying the code into a application works perfectly.

Any ideas what permissions I need to set?  Many thanks

    <WebMethod()> _
    Public Function test() As String
        Dim sc As ServiceController

            For Each sc In ServiceController.GetServices()
                If sc.DisplayName.Equals("Print Spooler") Then Exit For

            If sc.Status = ServiceControllerStatus.Stopped Then
                ' Start the service if its stopped

                    ' Start the service, and wait until its status is "Running".
                Catch ex As Exception
                    Return "11111 " & ex.Message
                End Try

            End If

        Catch ex As Exception
            Return "22222 " & ex.Message
        End Try
    End Function
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Which user is running the service?

I generally setup a service user which has the permissions required to access the file system and event logs and such.

An exact error message always helps :)
jimbona27Author Commented:
thanks, im not sure about the permissions but I know the print spooler service is running as a local system account.
Check your service in the Services Console. Go into it's properties and you will see under whch account it is running. Change this to Local System and you should have more luck.

If not change it to your logon details and try again.

Else show us the error message because it might be a permissions problem somewhere else.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

jimbona27Author Commented:
how can I setup the permission so it should work when depolying the site on another server?
Wait I got confused... I thought you where writing a windows service,...

To get permissions to access a service that is running you need to use impersonation.

This is a bit more complicated.

Take a look at this article on how to impersonate a user

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimbona27Author Commented:
will do.

can you inform me how to move a website to another location, i.e. copy the files onto another server?
then I'll test whether the impersonation works (after reading the url)

In v1.1 you just build the site for release and then copy the entire structure (excluding all .vb or .cs files) to the server.

In v2 you need to publish your site to a local folder and then copy the structure from there.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.