Link to home
Start Free TrialLog in
Avatar of jimbona27
jimbona27Flag for United Kingdom of Great Britain and Northern Ireland

asked on

service control permission problem as the same code works in vb.net application

hi,

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 vb.net application works perfectly.

Any ideas what permissions I need to set?  Many thanks


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

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

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

                Try
                    ' Start the service, and wait until its status is "Running".
                    sc.Start()
                    sc.WaitForStatus(ServiceControllerStatus.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
Avatar of GavinMannion
GavinMannion

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 :)
Avatar of jimbona27

ASKER

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.
how can I setup the permission so it should work when depolying the site on another server?
ASKER CERTIFIED SOLUTION
Avatar of GavinMannion
GavinMannion

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)

thanks,
In asp.net 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 asp.net v2 you need to publish your site to a local folder and then copy the structure from there.