bigt123
asked on
Disable a winnt service how?
How do I disable a Win NT service through VB 6.0?
bigT
bigT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The easiest way I know of is to use the above code to stop it, then change it's startup options by editing the registry.
1) Change the registry setting using the Registry API. For exmple, if you want to change the start type of "Xyz" service. See following,
Change the Start (it's a DWORD) string value of the following registry key to setting shown below.
HKEY_LOCAL_MACHINE\SYSTEM\ CurrentCon trolSet\Se rvices\Xyz
Start=2 => Automatic
Start=3 => Manual
Start=4 => Disabled
Make sure that "Xyz" is the name of the service and not the display name displayed in the services control panel applet. You can easily do this by using Registry API fuctions.
1) Change the registry setting using the Registry API. For exmple, if you want to change the start type of "Xyz" service. See following,
Change the Start (it's a DWORD) string value of the following registry key to setting shown below.
HKEY_LOCAL_MACHINE\SYSTEM\
Start=2 => Automatic
Start=3 => Manual
Start=4 => Disabled
Make sure that "Xyz" is the name of the service and not the display name displayed in the services control panel applet. You can easily do this by using Registry API fuctions.
There's also lots of information regarding doing this with api's here:
https://www.experts-exchange.com/questions/10223022/NT4-Services-and-VB-changing-startup-options.html
https://www.experts-exchange.com/questions/10223022/NT4-Services-and-VB-changing-startup-options.html
ASKER
Great!
Thanks but one more esay question: How do i change : HKEY_LOCAL_MACHINE\SYSTEM\ CurrentCon trolSet\Se rvices\Xyz to Start=4 => Disabled in VB?
Thanks but one more esay question: How do i change : HKEY_LOCAL_MACHINE\SYSTEM\
ASKER
I has to be able to change the reg key on a remote machine.
Thanks
Thanks
ASKER
Can you give me an example of the usage you use? how do i connect to a computer with this code? im not sure how to use it.
ASKER
Nerver mind i think i got it.
ASKER
how do i determine if a remote computer is winnt?
ASKER
or is there a function to disable the service?
there's different ways to determine if the remote machine is NT . . . I often use code from here: http://www.mvps.org/vbnet/code/network/netserverenumver.htm
the experts-exchange link I gave you earlier has functions to disable the service. I haven't personally put all the code together, to make it work, but from what I can see it should work.
the experts-exchange link I gave you earlier has functions to disable the service. I haven't personally put all the code together, to make it work, but from what I can see it should work.
ASKER
That last link you gave me did the trick for getting only nt computers!!!
But i still didnt see the disable service function at : https://www.experts-exchange.com/questions/10223022/NT4-Services-and-VB-changing-startup-options.html
Thanks
But i still didnt see the disable service function at : https://www.experts-exchange.com/questions/10223022/NT4-Services-and-VB-changing-startup-options.html
Thanks
ASKER
Is there anyting wrong with this?
-------------------------- ---------- ---------- ---------- ---------- ---------- -
Function RegChange() As String
Dim lRetVal As Long
Dim sRemMachName As String
Dim lTopLevelKey As Long
Dim lHKeyhandle As Long
Dim sKeyName As String
Dim lhkey As Long
Dim sValueName As String
Dim vValue As String
sKeyName = "SYSTEM\CurrentControlSet\ Services\M essenger"
sValueName = "Start"
lTopLevelKey = HKEY_LOCAL_MACHINE
lpMachineName = "tony"
DoEvents
lRetVal = RegConnectRegistry(lpMachi neName, lTopLevelKey, lHKeyhandle)
If lRetVal = 0 Then
If lRetVal = RegOpenKeyEx(lHKeyhandle, sKeyName, 0, KEY_ALL_ACCESS, lhkey) = 0 Then
lRetVal = SetValueEx(lhkey, sValueName, REG_DWORD, 4)
RegCloseKey (lhkey)
End If
End If
End Function
--------------------------
Function RegChange() As String
Dim lRetVal As Long
Dim sRemMachName As String
Dim lTopLevelKey As Long
Dim lHKeyhandle As Long
Dim sKeyName As String
Dim lhkey As Long
Dim sValueName As String
Dim vValue As String
sKeyName = "SYSTEM\CurrentControlSet\
sValueName = "Start"
lTopLevelKey = HKEY_LOCAL_MACHINE
lpMachineName = "tony"
DoEvents
lRetVal = RegConnectRegistry(lpMachi
If lRetVal = 0 Then
If lRetVal = RegOpenKeyEx(lHKeyhandle, sKeyName, 0, KEY_ALL_ACCESS, lhkey) = 0 Then
lRetVal = SetValueEx(lhkey, sValueName, REG_DWORD, 4)
RegCloseKey (lhkey)
End If
End If
End Function
ASKER
Nerver mind... Thanks AlbertaBeef
ASKER