We have a service that we created (and runs one of our servers) I want to control through Although I have some difficulty in service and hope someone can help you.
If I try to control the service using the route given below, then it works only with users who are also on the server:
Service Controller Service = New Service Controller ("MySwive", "MySwar"); Try {if (service.Status == ServiceControllerStatus.Running) {teServiceStatus.BackColor = Color.LightGreen; TeServiceStatus.Text = "Running"; SbStartService.Enabled = false; SbStopService.Enabled = true; } And {teServiceStatus.BackColor = Color.Red; TeServiceStatus.Text = "closed"; SbStartService.Enabled = true; SbStopService.Enabled = false; }} Hold (invalid operation exception ioe) {if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break (); Else {teServiceStatus.Text = "Can not Connect"; TeServiceStatus.BackColor = Color.Red; }} Hold (Exception pre) {if (System.Diagnostics.Debugger.IsAttached) System. Diagnostics Debugger.Break (); other ; } As a network user, I am also on a server as a user and when we run our program when we want to control this program, then I Can see and stop it, but no one can do it (unless I add them to the server, which I do not want to do).
I can also use the following route and impersonate a user on the server:
// Install connection with publishing server with publication authentication Please. Connection options option connection = new connection option (); ConnectionOptions.Imersonationation = Impersonation Level. Model; ConnectionOptions.EnablePrivileges = True; ConnectionOptions.Username = "UserOnServer"; ConnectionOptions.Password = "UserPassword"; ManagementScope ManagementScope = New ManagementScope (@ "\\ Mayrver \ Root \ cimv2", Connection Options); ManagementScope.Connect (); Management Path Path = New Management Path ("Win32_Service"); ManagementClass Services = New Management Class (Management Scope, Path, Empty); (Service. Gate Instance ()) {try (if the service (service. Getproprti value ( "name"). ToString () == "Maiswaiv") if (ServicekGetPropertyValue ( "state"). ToString (). ToLower ( ) running .Equals ( "")) {teServiceStatus.BackColor = Color.LightGreen; TeServiceStatus.Text = "running"; SbStartService.Enabled = false; SbStopService.Enabled = true;} and {teServiceStatus.BackColor = Color .Red; TeServiceStatus.Text = "off"; SbStartService.Enabled = true; SbStopService.Enabled = false;}} catch (exception Amanyopreshn ioe) {if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break ( ); Else {teServiceStatus.Text = "Can not connect"; TeServiceStatus.BackColor = Color.Red;}} Hold (Exception pre) {if (System.Diagnost ics.Debugger.IsAttached) System.Digagnostics.Debugger.Break (); Else {teServiceStatus.Text = "can not connect"; TeServiceStatus.BackColor = Color.Red;}}} This works so that any user who uses the program can start / stop the service and sees the current situation, but when the program stops, the service stops (does not know if It happens, but this is it).
So how can I start my program, stop it, and read anyone who can use it to serve the service status? I think I'm close but apparently, something is missing.
When using the UPDATE connection option option, it appears that as the connection option (or management field) closes, the server is logged in as Records, "Log off of", and then closes the service at that time. I do not know why, but still trying to see it.
to impersonate their running customer code NT AUTHORITY \ NetworkService account so According to your service, there are equal permissions (or may be empty string, try both of them) I think that documentation about running the code while impersonating that user for that account is more information here. In addition, you can apply in your service as well. It is possible that being thrown exception out of your effort / catch blocks, and that's why your app is exiting the attached debugger braking without any breakpoint set in your catch block.
Comments
Post a Comment