M
mkc
Unregistered / Unconfirmed
GUEST, unregistred user!
1.本人想用cgi,通过ie远程启动(或关闭)sql server,写了下面的代码,代码在应用程序中能
启动sql server,但粘贴到cgi中,执行没错误,就是不能启动sql server,why?
procedure TWebModule1.WebModule1WebActionItem3Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
//start mssql server
var
lpServiceArgVectorschar;
hscmanager,hService:SC_HANDLE;
returnstatus:TServiceStatus;
html:string;
exeresult:boolean;
begin
lpServiceArgVectors:=nil;
hscmanager:=OpenSCManager(nil,nil,SC_MANAGER_ENUMERATE_SERVICE);// 打开service control manager database
hService:=OpenService(hscmanager,'MSSQLSERVER',SERVICE_ALL_ACCESS);
//打开该Service
if(hService<0) then
begin
html:='无法打开该Service';
exit;
end;
QueryServiceStatus(hService,returnstatus); //查看该Service的状态
if returnstatus.dwCurrentState=SERVICE_STOPPED then //如果该Service已停止则启动它
begin
html:=html+'正在启动SQL SERVER数据库...';
StartService(hService,0,lpServiceArgVectors);
html:=html+'启动成功.';
end
else
html:=html+'无法打开SQL SERVER'+inttostr(returnstatus.dwServiceType);
CloseServiceHandle(hService);//关闭该Service
Response.Content:=html;
end;
2.如不用上述方法,通过IE启动远程的sql server 或 nt service,谁有高见?
启动sql server,但粘贴到cgi中,执行没错误,就是不能启动sql server,why?
procedure TWebModule1.WebModule1WebActionItem3Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
//start mssql server
var
lpServiceArgVectorschar;
hscmanager,hService:SC_HANDLE;
returnstatus:TServiceStatus;
html:string;
exeresult:boolean;
begin
lpServiceArgVectors:=nil;
hscmanager:=OpenSCManager(nil,nil,SC_MANAGER_ENUMERATE_SERVICE);// 打开service control manager database
hService:=OpenService(hscmanager,'MSSQLSERVER',SERVICE_ALL_ACCESS);
//打开该Service
if(hService<0) then
begin
html:='无法打开该Service';
exit;
end;
QueryServiceStatus(hService,returnstatus); //查看该Service的状态
if returnstatus.dwCurrentState=SERVICE_STOPPED then //如果该Service已停止则启动它
begin
html:=html+'正在启动SQL SERVER数据库...';
StartService(hService,0,lpServiceArgVectors);
html:=html+'启动成功.';
end
else
html:=html+'无法打开SQL SERVER'+inttostr(returnstatus.dwServiceType);
CloseServiceHandle(hService);//关闭该Service
Response.Content:=html;
end;
2.如不用上述方法,通过IE启动远程的sql server 或 nt service,谁有高见?