Detta är tip 894, jag får felmeddelande på: Du måste sätta en referens till Active DS Type Library. Med andra ord du måste ha IIS installerat... Jag tar upp denna igen, MÅSTE jag ha IIS installerat för att starta/stoppa servicear på en annan dator?Start/stopp service i winnt/2000? REMOTE
ActiveDs.WinNTSystemInfo
ActiveDs.IADsComputer
ActiveDs.IADsServiceOperations
"user-defined type is not defined"
nån som vet? så vore jag väldigt tacksam, ELLER om nån vet nått annat tips om hur man startar o stoppar tjänster i winNT/2000.
*****************************************************
Public Function StartService(ServiceName As String) As Boolean
Dim oSysInfo As New ActiveDs.WinNTSystemInfo
Dim oComp As ActiveDs.IADsComputer
Dim oSvcOp As ActiveDs.IADsServiceOperations
Dim sCompName As String
Dim sSvc As String
Dim lRet As Boolean
On Error GoTo errorhandler:
sSvc = ServiceName
sCompName = "WinNT://" & _
oSysInfo.ComputerName & ",computer"
Set oComp = GetObject(sCompName)
Set oSvcOp = oComp.GetObject("Service", sSvc)
oSvcOp.Start
StartService = True
Exit Function
errorhandler:
StartService = False
End Function
Public Function StopService(ServiceName As String) As Boolean
Dim oSysInfo As New ActiveDs.WinNTSystemInfo
Dim oComp As ActiveDs.IADsComputer
Dim oSvcOp As ActiveDs.IADsServiceOperations
Dim sCompName As String
Dim sSvc As String
Dim lRet As Boolean
On Error GoTo errorhandler:
sSvc = ServiceName
sCompName = "WinNT://" & _
oSysInfo.ComputerName & ",computer"
Set oComp = GetObject(sCompName)
Set oSvcOp = oComp.GetObject("Service", sSvc)
oSvcOp.Stop
StopService = True
Exit Function
errorhandler:
StopService = False
End Function
Public Function PauseService(ServiceName As String) As Boolean
Dim oSysInfo As New ActiveDs.WinNTSystemInfo
Dim oComp As ActiveDs.IADsComputer
Dim oSvcOp As ActiveDs.IADsServiceOperations
Dim sCompName As String
Dim sSvc As String
Dim lRet As Boolean
On Error GoTo errorhandler:
sSvc = ServiceName
sCompName = "WinNT://" & _
oSysInfo.ComputerName & ",computer"
Set oComp = GetObject(sCompName)
Set oSvcOp = oComp.GetObject("Service", sSvc)
oSvcOp.Pause
PauseService = True
Exit Function
errorhandler:
PauseService = False
End Function
************************************************
Koden e "by Pelle"Sv: Start/stopp service i winnt/2000?
Sv: Start/stopp service i winnt/2000?
Jag vET att det inte behövs för jag har en programmvara som klarar detta utan IIS.
(Nu undrar ni väl varför inte denna kan användas men jag ska automatisera en uppdatering)
Inga andra tips?
/Benny
KAN NÅN KOLLA PÅ DENNA? FÅR DEN INTE ATT FUNKA.
INGA FELMEDDELANDEN MEN DEN GÖR INTE DET JAG VILL
<code>
Private Type SERVICE_STATUS
dwServiceType As Long
dwCurrentState As Long
dwControlsAccepted As Long
dwWin32ExitCode As Long
dwServiceSpecificExitCode As Long
dwCheckPoint As Long
dwWaitHint As Long
End Type
Private Declare Function OpenSCManager Lib "advapi32.dll" Alias _
"OpenSCManagerA" (ByVal lpMachineName As String, _
ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Private Declare Function CloseServiceHandle Lib "advapi32.dll" (ByVal hSCObject _
As Long) As Long
Private Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" _
(ByVal hSCManager As Long, ByVal lpServiceName As String, _
ByVal dwDesiredAccess As Long) As Long
Private Declare Function StartService Lib "advapi32.dll" Alias "StartServiceA" _
(ByVal hService As Long, ByVal dwNumServiceArgs As Long, _
ByVal lpServiceArgVectors As Long) As Long
Private Declare Function ControlService Lib "advapi32.dll" (ByVal hService As _
Long, ByVal dwControl As Long, lpServiceStatus As SERVICE_STATUS) As Long
Const GENERIC_EXECUTE = &H20000000
Const SERVICE_CONTROL_STOP = 1
Const SERVICE_CONTROL_PAUSE = 2
Const SERVICE_CONTROL_CONTINUE = 3
' start/stop/pause/continue a service
' SERVICENAME is the internal name of the service
' COMMAND can be 0=Start, 1=Stop, 2=Pause, 3=Continue
'
' returns True if successful, False otherwise
' if any error, call Err.LastDLLError for more information
Function ServiceCommand(ByVal ServiceName As String, ByVal command As Long) As _
Boolean
Dim hSCM As Long
Dim hService As Long
Dim res As Long
Dim lpServiceStatus As SERVICE_STATUS
' first, check the command
If command < 0 Or command > 3 Then Err.Raise 5
' open the connection to Service Control Manager, exit if error
hSCM = OpenSCManager(vbNullString, vbNullString, GENERIC_EXECUTE)
If hSCM = 0 Then Exit Function
' open the given service, exit if error
hService = OpenService(hSCM, ServiceName, GENERIC_EXECUTE)
If hService = 0 Then GoTo CleanUp
' start the service
Select Case command
Case 0
' to start a service you must use StartService
res = StartService(hService, 0, 0)
Case SERVICE_CONTROL_STOP, SERVICE_CONTROL_PAUSE, _
SERVICE_CONTROL_CONTINUE
' these commands use ControlService API
' (pass a NULL pointer because no result is expected)
res = ControlService(hService, command, lpServiceStatus)
End Select
If res = 0 Then GoTo CleanUp
' return success
ServiceCommand = True
CleanUp:
If hService Then CloseServiceHandle hService
' close the SCM
CloseServiceHandle hSCM
End Function
</code>