好像是vb版吧。 调用net.exe,参数:"stop {你的服务名}" net的详细介绍: 此命令的语法是: NET STOP serviceNET STOP 用于终止 Windows 服务。终止一个服务可以取消这个服务正在使用的任何一个网络连接。同样的一些 服务是依赖于另外一些服务的。终止一个服务就会终止其它服务。用户必须终止服务器服务的管理权限。不能终止事件记录服务。service 指如下服务之一: ALERTER BROWSER CLIENT SERVICE FOR NETWARE CLIPBOOK DHCP CLIENT FILE REPLICATION MESSENGER NET LOGON NT LM SECURITY SUPPORT PROVIDER REMOTE ACCESS CONNECTION MANAGER ROUTING AND REMOTE ACCESS RPCLOCATOR SCHEDULE SERVER SPOOLER/这就是你要关的打印服务 TCP/IP NETBIOS HELPER SERVICE UPS WORKSTATIONNET STOP 还可以终止 Windows 没有提供的网络服务。
楼上的办理也可以,代码声明都在这了,自己整理一下~ Public Function Control_Service(Service_Name As String, Control As Long) As Boolean
Dim lnghService As Long Dim RetVal As Long
' open service lnghService = OpenService(mlngServicesManager, Service_Name, SERVICE_ALL_ACCESS)
' check for error If RetVal = 0 Then mLastErrorDescription = ErrorMessages(Err.LastDllError) Control_Service = False Exit Function End If If RetVal <> 0 Then Control_Service = True
End FunctionPublic Function Stop_Service(Service_Name As String) As Boolean ' SERVICE_CONTROL_STOP Stop_Service = Control_Service(Service_Name, SERVICE_CONTROL_STOP)
End Function Public Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long Public Declare Function ControlService Lib "advapi32.dll" (ByVal hService As Long, ByVal dwControl As Long, lpServiceStatus As SERVICE_STATUS) As Long Private mlngServicesManager As Long ' hold the reference to the Service manager mlngServicesManager = OpenSCManager(vbNullString, vbNullString, SC_MANAGER_ENUMERATE_SERVICE) ' check to see if we connected properly If mlngServicesManager = 0 Then MsgBox "Service control manager connection error!" End If Public Const SC_MANAGER_ENUMERATE_SERVICE As Long = &H4 Public Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long Public Const SERVICE_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SERVICE_QUERY_CONFIG Or SERVICE_CHANGE_CONFIG Or SERVICE_QUERY_STATUS Or SERVICE_ENUMERATE_DEPENDENTS Or SERVICE_START Or SERVICE_STOP Or SERVICE_PAUSE_CONTINUE Or SERVICE_INTERROGATE Or SERVICE_USER_DEFINED_CONTROL) Private mServiceStatus As SERVICE_STATUS ' used with the start and stop service methods (not used yet) 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 Public Const SERVICE_CONTROL_STOP As Long = &H1
二、调用windos系统服务组件,停止服务
三、在注册表中找到该注册项,修改服务类型(缺点:系统重启后才有效果)
调用net.exe,参数:"stop {你的服务名}"
net的详细介绍:
此命令的语法是:
NET STOP
serviceNET STOP 用于终止 Windows 服务。终止一个服务可以取消这个服务正在使用的任何一个网络连接。同样的一些
服务是依赖于另外一些服务的。终止一个服务就会终止其它服务。用户必须终止服务器服务的管理权限。不能终止事件记录服务。service 指如下服务之一:
ALERTER
BROWSER
CLIENT SERVICE FOR NETWARE
CLIPBOOK
DHCP CLIENT
FILE REPLICATION
MESSENGER
NET LOGON
NT LM SECURITY SUPPORT PROVIDER
REMOTE ACCESS CONNECTION MANAGER
ROUTING AND REMOTE ACCESS
RPCLOCATOR
SCHEDULE
SERVER
SPOOLER/这就是你要关的打印服务
TCP/IP NETBIOS HELPER SERVICE
UPS
WORKSTATIONNET STOP 还可以终止 Windows 没有提供的网络服务。
Public Function Control_Service(Service_Name As String, Control As Long) As Boolean
Dim lnghService As Long
Dim RetVal As Long
' open service
lnghService = OpenService(mlngServicesManager, Service_Name, SERVICE_ALL_ACCESS)
RetVal = ControlService(lnghService, Control, mServiceStatus)
' check for error
If RetVal = 0 Then
mLastErrorDescription = ErrorMessages(Err.LastDllError)
Control_Service = False
Exit Function
End If
If RetVal <> 0 Then Control_Service = True
End FunctionPublic Function Stop_Service(Service_Name As String) As Boolean
' SERVICE_CONTROL_STOP
Stop_Service = Control_Service(Service_Name, SERVICE_CONTROL_STOP)
End Function
Public Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long
Public Declare Function ControlService Lib "advapi32.dll" (ByVal hService As Long, ByVal dwControl As Long, lpServiceStatus As SERVICE_STATUS) As Long
Private mlngServicesManager As Long ' hold the reference to the Service manager
mlngServicesManager = OpenSCManager(vbNullString, vbNullString, SC_MANAGER_ENUMERATE_SERVICE)
' check to see if we connected properly
If mlngServicesManager = 0 Then
MsgBox "Service control manager connection error!"
End If
Public Const SC_MANAGER_ENUMERATE_SERVICE As Long = &H4
Public Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Public Const SERVICE_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SERVICE_QUERY_CONFIG Or SERVICE_CHANGE_CONFIG Or SERVICE_QUERY_STATUS Or SERVICE_ENUMERATE_DEPENDENTS Or SERVICE_START Or SERVICE_STOP Or SERVICE_PAUSE_CONTINUE Or SERVICE_INTERROGATE Or SERVICE_USER_DEFINED_CONTROL)
Private mServiceStatus As SERVICE_STATUS ' used with the start and stop service methods (not used yet)
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
Public Const SERVICE_CONTROL_STOP As Long = &H1