关于delphi ScktSrvr.exe注册为服务,不能自启动问题探讨?(50)

D

dorry

Unregistered / Unconfirmed
GUEST, unregistred user!
加入我的收藏 楼主: ScktSrvr.exe注册为服务后,发现不能自启动。分析其源码,发现默认注册为系统服务:‘localsystem’,但是启动时,它检测当前用户名是否为‘SYSTEM’,如果为‘SYSTEM’ 则自动启动。如果是其他登录用户则不启动。仅仅简单屏蔽了如下代码,即可自动启动。function StartService: Boolean;var Mgr, Svc: Integer; UserName, ServiceStartName: string; Config: Pointer; Size: DWord;begin Result := False; Mgr := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS); if Mgr <> 0 then begin Svc := OpenService(Mgr, PChar(SServiceName), SERVICE_ALL_ACCESS); Result := Svc <> 0; if Result then begin QueryServiceConfig(Svc, nil, 0, Size); Config := AllocMem(Size); try QueryServiceConfig(Svc, Config, Size, Size); ServiceStartName := PQueryServiceConfig(Config)^.lpServiceStartName; if CompareText(ServiceStartName, 'LocalSystem') = 0 then ServiceStartName := 'SYSTEM'; finally Dispose(Config); end; CloseServiceHandle(Svc); end; CloseServiceHandle(Mgr); end; if Result then begin// Size := 256;// SetLength(UserName, Size);// GetUserName(PChar(UserName), Size);// SetLength(UserName, StrLen(PChar(UserName)));// Result := CompareText(UserName, ServiceStartName) = 0;检测用户是否为SYStem。实际上似乎不可能?。比如登录用户:abc,实际上ServiceStartName:='SYSTEM' end;end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
542
import
I
顶部