• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

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
0
jimbona27
Asked:
jimbona27
  • 4
  • 3
1 Solution
 
GavinMannionCommented:
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 :)
0
 
jimbona27Author Commented:
thanks, im not sure about the permissions but I know the print spooler service is running as a local system account.
0
 
GavinMannionCommented:
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jimbona27Author Commented:
how can I setup the permission so it should work when depolying the site on another server?
0
 
GavinMannionCommented:
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
http://www.eggheadcafe.com/articles/20020418.asp
0
 
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)

thanks,
0
 
GavinMannionCommented:
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now