PDA

Click to See Complete Forum and Search --> : [RESOLVED] Enable Disabled Windows Services


Octopus
May 1st, 2007, 04:38 AM
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

jmcilhinney
May 1st, 2007, 04:56 AM
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:Public Shared Function EnsureTransactionManagerStarted(ByVal setAutoStart As Boolean) As Boolean
Dim result As Boolean

Try
Dim msDtcController As New ServiceController("MSDTC")

'Make sure the transaction coordinator is running.
If msDtcController.Status <> ServiceProcess.ServiceControllerStatus.Running Then
msDtcController.Start()
msDtcController.WaitForStatus(ServiceControllerStatus.Running)
End If

result = True
Catch ex As Exception
ErrorLogger.Log(ex)
Debug.WriteLine(ex.ToString())
MessageBox.Show(My.Resources.StartMsDtcServiceFailedErrorString, _
"Start Service Failed", _
MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
result = False
End Try

Try
Dim keyName As String = My.Resources.MsDtcRegistryKeyPathString
Dim valueName As String = "Start"

If setAutoStart AndAlso CInt(My.Computer.Registry.GetValue(keyName, _
valueName, _
0)) <> 2 Then
'Set the start-up type for the Distributed Transaction Coordinator service to Automatic.
My.Computer.Registry.SetValue(keyName, _
valueName, _
2)
End If
Catch ex As Exception
ErrorLogger.Log(ex)
End Try

Return result
End FunctionYou can get the idea from that and apply the same principles in C#.

Octopus
May 4th, 2007, 02:20 AM
2 for automatic, 3 manual , 4 disabled

Thank you