我有一个使用Delphi创建的服务应用程序,并设法使用提升的权限从另一个Delphi应用程序安装它.
该服务设置为以本地系统帐户登录(在Delphi中创建服务应用程序时是默认的).
我有另一个Delphi应用程序,其中普通用户应该能够启动或停止上述服务.
我的问题是:Windows允许这样做吗?当我尝试使用Delphi中的代码启动服务时,它只是失败了"Code 5. Access被拒绝".如何防止发生此错误?我希望能够让普通用户运行应用程序(不是在管理员模式下,因此没有提升权限)来启动/停止服务.有可能,如果可能,怎么样?以下是我的代码:
function ServiceStart(sMachine, sService: string): boolean;
var
schm, schs: SC_Handle;
ss: TServiceStatus;
psTemp: PChar;
dwChkP: DWord; // check point
begin
ss.dwCurrentState := 0;
// connect to the service control manager
schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
// if successful...
if (schm <> 0) then
begin
// open a handle to the specified service
// we want to start the service and query service
// status
schs := OpenService(schm, PChar(sService), SERVICE_START or SERVICE_QUERY_STATUS);
// if successful...
if …Run Code Online (Sandbox Code Playgroud)