PB调用api函数CreateService创建系统服务
of_createservice函数(string lpservicename,string lpdisplayname,unsignedlong dwdesiredaccess,unsignedlong dwservicetype,unsignedlong dwstarttype,unsignedlong dwerrorcontrol,string lpbinarypathname,string lploadordergroup,unsignedlong lpdwtagid,string lpdependencies,string lp,string lppassword)
uLong hSCManager, hService, r, r1, ll_rtn, ll , hCSrvState
string s, ls_null
QUERY_SERVICE_CONFIG scfg
setnull(ls_null)
hSCManager = OpenSCManager(ls_null, ls_null, SC_MANAGER_ALL_ACCESS)
If hSCManager > 0 Then
hCSrvState = CreateService(hSCManager,ref lpServiceName, ref lpDisplayName, dwDesiredAccess, dwServiceType, dwStartType, dwErrorControl,ref lpBinaryPathName, ref lpLoadOrderGroup, ref lpdwTagId, ref lpDependencies, ref lp, ref lpPassword)
if isnull(hCSrvState) then
return false
else
return true
end if
End If
return false
FUNCTION ulong OpenSCManager(ref string lpMachineName,ref string lpDatabaseName,ulong dwDesiredAccess) LIBRARY "advapi32.dll" ALIAS FOR "OpenSCManagerA"
FUNCTION ulong CreateService(ulong hSCManager,ref string lpServiceName,ref string lpDisplayName,ulong dwDesiredAccess,ulong dwServiceType,ulong dwStartType,ulong dwErrorControl,ref string lpBinaryPathName,ref string lpLoadOrderGroup,ref ulong lpdwTagId,ref string lpDependencies,ref string lp,ref string lpPassword) LIBRARY "advapi32.dll" ALIAS FOR "CreateServiceA"
private:
constant ulong SC_MANAGER_ALL_ACCESS = 0
nvo_systemserver lnvo
boolean csrvstate
constant ulong SERVICE_ALL_ACCESS = 983551
constant ulong SERVICE_WIN32_OWN_PROCESS = 16
string lpServiceName //创建登记数据库中的关键字
string lpDisplayName //服务名称
ulong dwDesiredAccess //指定服务返回类型
ulong dwServiceType //指定服务类型
ulong dwStartType //指定启动类型 2表示自动运行 3表示手动运行 4表示禁止
ulong dwErrorControl //指定服务启动失败的严重程度
string lpBinaryPathName //指定服务程序二进制文件的路径
string lpLoadOrderGroup //指定顺序装入的服务组名
ulong lpdwTagId //忽略,NULL
string lpDependencies //指定服务帐号。如是NULL,则表示使用LocalSystem帐号
string lp
string lpPassword //指定对应的口令。为NULL表示无口令。但使用LocalSystem时填NULL
string ls_null
lpServiceName = "MyService"
lpDisplayName = "测试服务"
dwServiceType = 272
dwStartType = 2
dwErrorControl = 1
lpBinaryPathName = ''
lpLoadOrderGroup = '0'
setnull(ls_null)
csrvstate = lnvo.of_createservice(ref lpServiceName,ref lpDisplayName,SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,dwStartType,dwErrorControl,ref lpBinaryPathName,ref lpLoadOrderGroup,ref lpdwTagId,ref lpDependencies,ref lp,ref lpPassword)
if(csrvstate) then
messagebox("提示","成功创建" + lpServiceName + "服务!")
else
messagebox("提示","创建服务失败!")
end if
[解决办法]