VB6中怎样启动和停止windows2000的系统服务
来源:互联网 发布:撞库攻击软件 编辑:程序博客网 时间:2024/05/17 00:03
您可以通过API, ADSI或WMI三种方式在VB6中启动和停止windows2000的系统服务。
1.API方式。
您需要调用下面4个API函数:
OpenSCManager用以获得service信息数据库
OpenService用以获得service的句炳
StartService/StopService用以启动/停止service
以下链接提供了用VB查询service的状态和设置的样例程序,在Q189633等文章里面的代码可以作为您在VB里调用NT service操作的一个参考。
http://support.microsoft.com/support/kb/articles/q189/6/33.asp
您可以参考以下链接提供的VC样例程序,停止一个service。
http://support.microsoft.com/support/kb/articles/q245/2/30.asp
2.ADSI方式
您可以使用IADsServiceOperations接口的start/stop方法启动/停止一个NT的service.
如下例在Windows 2000 Professional中启动一个Microsoft® Fax Service
Dim cp As IADsComputer
Dim so As IADsServiceOperations
Set cp = GetObject("WinNT://myMachine,computer")
Set so = cp.GetObject("Service", "Fax")
If (so.Status <> ADS_SERVICE_RUNNING) Then ' The operation is not running.
so.Start
End If
详细信息请参考:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/adsi/iadsserviceoperations_start.asp
3.WMI方式。
您也可以用WMI编程对系统service进行管理,如下例:
Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select *
from Win32_Service where State='Stopped' )
‘上面的代码返回停止状态的service对象集。
for each Service in ServiceSet
‘ 您可以在这里用Win32_Service对象的StartService/StopService方法启动/停止service。
Next
关于WMI的详细信息请参考以下链接:
http://msdn.microsoft.com/library/en-us/dnwmi/html/mngwmi.asp
- 微软全球技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
1.API方式。
您需要调用下面4个API函数:
OpenSCManager用以获得service信息数据库
OpenService用以获得service的句炳
StartService/StopService用以启动/停止service
以下链接提供了用VB查询service的状态和设置的样例程序,在Q189633等文章里面的代码可以作为您在VB里调用NT service操作的一个参考。
http://support.microsoft.com/support/kb/articles/q189/6/33.asp
您可以参考以下链接提供的VC样例程序,停止一个service。
http://support.microsoft.com/support/kb/articles/q245/2/30.asp
2.ADSI方式
您可以使用IADsServiceOperations接口的start/stop方法启动/停止一个NT的service.
如下例在Windows 2000 Professional中启动一个Microsoft® Fax Service
Dim cp As IADsComputer
Dim so As IADsServiceOperations
Set cp = GetObject("WinNT://myMachine,computer")
Set so = cp.GetObject("Service", "Fax")
If (so.Status <> ADS_SERVICE_RUNNING) Then ' The operation is not running.
so.Start
End If
详细信息请参考:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/adsi/iadsserviceoperations_start.asp
3.WMI方式。
您也可以用WMI编程对系统service进行管理,如下例:
Set ServiceSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select *
from Win32_Service where State='Stopped' )
‘上面的代码返回停止状态的service对象集。
for each Service in ServiceSet
‘ 您可以在这里用Win32_Service对象的StartService/StopService方法启动/停止service。
Next
关于WMI的详细信息请参考以下链接:
http://msdn.microsoft.com/library/en-us/dnwmi/html/mngwmi.asp
- 微软全球技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
- VB6中怎样启动和停止windows2000的系统服务
- 系统服务的启动和停止,禁用 和自动启动
- Linux攻略 如何修改系统的服务启动和停止
- LINUX下如何修改系统的服务启动和停止
- VC启动和停止windows系统服务
- linux中启动和停止MySQL服务
- 启动和停止服务
- linux系统查看服务状态和启动停止服务
- Oracle9i服务启动和停止的批处理文件
- oracle正常启动和停止的服务
- 管理weblogic服务的启动和停止
- oracle正常启动和停止的服务
- 服务(Service)的停止和启动
- wmi学习之启动和停止系统服务
- AIX上如何启动和停止系统服务
- AIX系统下如何启动和停止ftp服务
- 如何在MacOS系统里的命令行下启动和停止mysql服务
- 怎样停止一个 starting 和 stoping 的服务
- Java-JSTL(JSP标准标签库)
- The first step of Java[8]
- The first step of Java[9]
- 浅论taglib设计
- The first step of Java[10]
- VB6中怎样启动和停止windows2000的系统服务
- 我的XP精仿你的Vista
- 06年中国互联网10大创新模式 成功运营关键在人
- VOIP开源项目源码地址
- 免费索要Intel开发手册纸制版
- Why is the size of an empty class not zero?
- XmlDocument序列化到Session
- 崔英杰为了什么?
- Google adsense发布者应该知道的13大网站/博客[转东转西]