Results 1 to 3 of 3

Thread: [RESOLVED] Enable Disabled Windows Services

  1. #1

    Thread Starter
    Member Octopus's Avatar
    Join Date
    Jan 2006
    Posts
    48

    Resolved [RESOLVED] Enable Disabled Windows Services

    Dear All,

    1- I am using C# 2

    2-I need a way to start disabled windows xp Messenger service(on client pcs) from C# Application(on windows 2003 Server), so "net send.." instruction works.

    3- Service Controller Component start the service if it is not disabled.

    4-if it is not possible(step 2) , Is there a way to send a message to clients pcs on the LAN from C# Application other than (net send ..)??

    thank you all
    Last edited by Octopus; May 1st, 2007 at 04:43 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,274

    Re: Enable Disabled Windows Services

    You have to edit the Registry to enable or disable a Windows service. The key you need is "HKLM\SYSTEM\CurrentControlSet\Services\<service name>" and you need to set the Start value. I can tell you that a value of 2 corresponds to a Startup Type of Automatic. If I remember correctly o is Disabled and 1 is Manual but you can check that. Here's a method that I wrote in VB.NET to make sure the Distributed Transaction Coordinator service was running:
    vb Code:
    1. Public Shared Function EnsureTransactionManagerStarted(ByVal setAutoStart As Boolean) As Boolean
    2.     Dim result As Boolean
    3.  
    4.     Try
    5.         Dim msDtcController As New ServiceController("MSDTC")
    6.  
    7.         'Make sure the transaction coordinator is running.
    8.         If msDtcController.Status <> ServiceProcess.ServiceControllerStatus.Running Then
    9.             msDtcController.Start()
    10.             msDtcController.WaitForStatus(ServiceControllerStatus.Running)
    11.         End If
    12.  
    13.         result = True
    14.     Catch ex As Exception
    15.         ErrorLogger.Log(ex)
    16.         Debug.WriteLine(ex.ToString())
    17.         MessageBox.Show(My.Resources.StartMsDtcServiceFailedErrorString, _
    18.                         "Start Service Failed", _
    19.                         MessageBoxButtons.OK, _
    20.                         MessageBoxIcon.Warning)
    21.         result = False
    22.     End Try
    23.  
    24.     Try
    25.         Dim keyName As String = My.Resources.MsDtcRegistryKeyPathString
    26.         Dim valueName As String = "Start"
    27.  
    28.         If setAutoStart AndAlso CInt(My.Computer.Registry.GetValue(keyName, _
    29.                                                                    valueName, _
    30.                                                                    0)) <> 2 Then
    31.             'Set the start-up type for the Distributed Transaction Coordinator service to Automatic.
    32.             My.Computer.Registry.SetValue(keyName, _
    33.                                           valueName, _
    34.                                           2)
    35.         End If
    36.     Catch ex As Exception
    37.         ErrorLogger.Log(ex)
    38.     End Try
    39.  
    40.     Return result
    41. End Function
    You can get the idea from that and apply the same principles in C#.

  3. #3

    Thread Starter
    Member Octopus's Avatar
    Join Date
    Jan 2006
    Posts
    48

    Re: Enable Disabled Windows Services

    2 for automatic, 3 manual , 4 disabled

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width