我想远程检测windows服务的状态,比如IIS,tomcat,数据库服务之类的,怎么编程实现啊???如何用程序控制这些服务呢?比如关闭,启动之类的。
解决方案 »
- delphi7开发工具这么不好???
- delphi webservice如何连接c#.net 返回的dataset?
- 哪位能反编译delphi程序,给报酬
- 如何读取excelsheet 中rang['a1,'a1']的批注?
- MDI中子窗口如何得到MDI主窗口的类指针?
- 如何取出treeview中一个结点的data值?
- 简单问题!
- 我插入CD光盘,查看光盘容量居然为0,而且每个cda文件居然都是44字节,除了超级解霸的音频解霸可以播放出声音,其他的如windows自带的cd
- 快救救小弟,超级简单的问题
- 请教各位高手,delphi中怎样读取xml文件,有没有控件可用!
- @@@@@@@@@@*****我的左邻是只鸡*****@@@@@@@@@@@
- 全文检索检索到的文件怎么打不开呀?
uses winsvc;//关于service的函数定义在这个unit中,d5自带的啦
要控制一个service的具体流程大概是这样的:
1、取得服务数据库的handle
2、根据服务数据库的handle取得服务的handle
3、根据服务的handle来取服务的状态或者控制服务
下面是一段取Sql server状态的程序
function tserviceform.GetSqlServerStatus: Boolean;
var
SrvHandle: SC_HANDLE;//这些都在winsvc单元中定义的
Service_Status: _SERVICE_STATUS;//在winsvc单元中有定义
SrvStatus: Integer;
begin
//取sql server的状态,如果sql server正在运行则返回true ,否则返回 false
SrvHandle := OpenSCManager('', SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS);
SrvHandle := OpenService(SrvHandle, PChar('MSSQLServer'), SERVICE_QUERY_STATUS or SERVICE_START);
case SrvHandle of
ERROR_ACCESS_DENIED: Memo.Lines.Add('The specified service control manager database handle does not have access to the service.');
ERROR_INVALID_HANDLE: Memo.Lines.Add('The specified handle is invalid.');
ERROR_INVALID_NAME: Memo.Lines.Add('The specified service name is invalid.');
ERROR_SERVICE_DOES_NOT_EXIST: Memo.Lines.Add('The specified service does not exist.');
end;
if QueryServiceStatus(SrvHandle, Service_Status) then
begin
//判断Sql Server服务的状态
SrvStatus := Service_Status.dwCurrentState;
case SrvStatus of
SERVICE_STOPPED: Memo.Lines.Add('The service is not running.');
SERVICE_START_PENDING: Memo.Lines.Add('The service is starting.');
SERVICE_STOP_PENDING: Memo.Lines.Add('The service is stopping.');
SERVICE_RUNNING: memo.lines.add('The service is running.');
SERVICE_CONTINUE_PENDING: Memo.Lines.Add('The service continue is pending.');
SERVICE_PAUSE_PENDING: Memo.Lines.Add('The service pause is pending.');
SERVICE_PAUSED: Memo.Lines.Add('The service is paused');
end;
Result := (SrvStatus = SERVICE_RUNNING);
end
else
Result := False;
end;
具体的service函数可以看msdn中的Service Functions部分。
可用Api:
DWORD WNetAddConnection2(
LPNETRESOURCE lpNetResource,
LPCTSTR lpPassword,
LPCTSTR lpUsername,
DWORD dwFlags
);
上 google 找下 , WNetAddConnection2 连接的例子太多了第二步,取得你要的信息,可以参考这里:http://borland.mblogger.cn/aiirii/category/400.aspx我的代码都是测试过的,不过是取本机的,你可以修改 OpenSCManager 的第一个参数就可