Administer/manage servers and services in domain. 
Author Message
 Administer/manage servers and services in domain.

I would like to use ADSI to stop and start services on a NT 4.0 server
running Exchange Server 5.5.
It is ment to be fired by superusers when they have to stop the main
services on our Exchange server
when I am not around an the company is attacked by a virus like maybe a
worm.
I have tried the code below which works all right when trying to start/stop
services at the local Intranet server (I have tested on NT 4.0 and W2K) but
fails if trying to start/stop a service on another server in the domain.

The error message is:
Error Type:
Active Directory (0x80004005)
Unspecified error
pagetitel.asp, line 43

And the lines are:
42:Set Computer = GetObject("WinNT://" & ComputerDomain & "/" & ComputerName
& ",computer")
43:Set Service = Computer.GetObject("service", TargetService)

In an ASP page i have made the following code:
<body>
<%
doSomething()
Function doSomething()
 Dim Computer
 Dim ComputerName
 Dim ComputerDomain
 Dim TargetService
 TargetService = "Alerter"
 ComputerDomain = "NT_DOMAIN"
 ComputerName = "INTRANET"
 Set Computer = GetObject("WinNT://" & ComputerDomain & "/" & ComputerName &
",computer")
 Set Service = Computer.GetObject("service", TargetService)
 If Service.Status = 1 Then
  Service.Start
      Response.Write "The service " & Service.Name & " is started."
 Else
      If Service.Status = 4 Then
           Response.Write "The service " & Service.Name & " is allready
started."
      Else
           Response.Write "The service " & Service.Name & " could not be
started."
      End If
 End If
End Function
%>
</body>

I have allso tryed compiling a DLL and regsvr32 it and using it on the IIS
server. The Visual Bascic
project and the DLL has the following data:
Project name and DLL name: NTServiceAdmin
Class Modul name: NTServiceManagement
Code:
Public Function ServiceOperations(ByVal TargetDomain As String, ByVal
TargetComputer As String, ByVal TargetService As String, ByVal
ServiceOperation As String) As Integer
    Dim Computer As IADsComputer
    Dim Service As IADsServiceOperations
    Set Computer = GetObject("WinNT://" & TargetDomain & "/" &
TargetComputer & ",computer")
    Set Service = Computer.GetObject("service", TargetService)
    Select Case UCase(ServiceOperation)
        Case "START"
            If Service.Status = 1 Then
                Service.Start
            Else
                If Service.Status = 4 Then
                    Err.Number = 1 'statusquo
                Else
                    Err.Number = 2 'no change
                End If
            End If
        Case "STOP"
            If Service.Status = 4 Then
                Service.Stop
            Else
                If Service.Status = 1 Then
                    Err.Number = 1 statusquo
                Else
                    Err.Number = 2 'no change
                End If
            End If
        Case "CONTINUE"
            If Service.Status = 7 Then
                Service.Continue
            Else
                If Service.Status = 1 Then
                    Err.Number = 1 statusquo
                Else
                    Err.Number = 2 'no change
                End If
            End If
        Case "PAUSE"
            If Service.Status = 4 Then
                Service.Pause
            Else
                If Service.Status = 1 Then
                    Err.Number = 1 statusquo
                Else
                    Err.Number = 2 'no change
                End If
            End If
    End Select
    ServiceOperations = Err.Number
End Function

And then I call the DLL using the following in an ASP page:
<body>
<%
doSomething()
Function doSomething()
 Dim ComputerName
 Dim ComputerDomain
 Dim Service
 Dim TargetService
 Dim StartStop
 Dim ServiceManagement
 StartStop = "start"
 TargetService = "Alerter"
 ComputerDomain = {*filter*}ain
 ComputerName = "nt_server_02"

 Set ServiceManagement =
Server.CreateObject("NTServiceAdmin.NTServiceManagement")
 Resultat = ServiceManagement.ServiceOperations(ComputerDomain,
ComputerName, TargetService, StartStop)

 If Resultat = 0 Then
       Response.Write "The servicen " & TargetService & " is started."
 Else
       If Resultat = 1 Then
            Response.Write "The servicen " & TargetService & " is already
started."
       Else
            Response.Write "The servicen " & TargetService & " could not be
started."
       End If
 End If
End Function
%>
</body>

The error message is:

Error Type:
Active Directory (0x80004005)
Unspecified error
pagetitel.asp, line 46

And the lines are:
44:Dim ServiceManagement
45:Set ServiceManagement =
Server.CreateObject("NTServiceAdmin.NTServiceManagement")
46:Resultat = ServiceManagement.ServiceOperations(ComputerDomain,
ComputerName, TargetService, StartStop)



Sun, 10 Oct 2004 15:30:09 GMT  
 Administer/manage servers and services in domain.
I've actaully done this with ADSI to troll my network and
kill game servers so I know its possible but I also know
of a freeware tool that your users will be able to use a
little easier. The program is part of a suite is called
PStools. Check it out here:

http://www.sysinternals.com/ntw2k/freeware/pstools.shtml

Trust me, its worth a look. These are stand alone
executables and require no installation, I use PSlist.exe
and PSkill.exe all the time. Works great and you can't
beat free.



Mon, 11 Oct 2004 01:05:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Ole Directory Services (Active Directory Services) 1.1 - Has any body managed to use the VB examples

2. domain pruefen domain provider es domain registrieren domain angebot no domain

3. Using WSH from win95 to administer W2K server

4. Managing FAX Service?

5. Managing Services Using ADSI

6. Manage NT services with WMI/WBEM

7. Connecting with Domain-Managed Security.

8. Managing server certificates on IIS servers programmatically

9. domaene sichern de tc domain domain registrieren preisvergleich kostenlose toplevel domain de domain preis

10. plesk domain anmeldung domaene langsam anmeldung an domain de domain kaufen domain suchen

11. Manage NT Services in VB

12. How to manage WindowsNT services

 

 
Powered by phpBB® Forum Software