Link to home
Start Free TrialLog in
Avatar of bigt123
bigt123

asked on

Disable a winnt service how?

How do I disable a Win NT service through VB 6.0?

bigT
ASKER CERTIFIED SOLUTION
Avatar of Glen A.
Glen A.
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bigt123
bigt123

ASKER

Thaks for the help but this only stops it..I want it to be disabled..so it stays disables after next time the computer turns on.
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\CurrentControlSet\Services\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.
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
Avatar of bigt123

ASKER

Great!

Thanks but one more esay question: How do i change : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Xyz to Start=4  => Disabled in VB?
Avatar of bigt123

ASKER

I has to be able to change the reg key on a remote machine.

Thanks
for remote registry work I use the code found here: http://www.andreavb.f2s.com/tip080003.html

Avatar of bigt123

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.
Avatar of bigt123

ASKER

Nerver mind i think i got it.
Avatar of bigt123

ASKER

how do i determine if a remote computer is winnt?
Avatar of bigt123

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.
Avatar of bigt123

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
Avatar of bigt123

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\Messenger"
   sValueName = "Start"
   lTopLevelKey = HKEY_LOCAL_MACHINE
   lpMachineName = "tony"
   DoEvents
   
   
   
   lRetVal = RegConnectRegistry(lpMachineName, 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
Avatar of bigt123

ASKER

Nerver mind... Thanks  AlbertaBeef