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 , hCSrvStatestring s, ls_nullQUERY_SERVICE_CONFIG scfgsetnull(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 ifEnd Ifreturn 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 lnvoboolean csrvstateconstant ulong SERVICE_ALL_ACCESS = 983551constant ulong SERVICE_WIN32_OWN_PROCESS = 16string lpServiceName //创建登记数据库中的关键字string lpDisplayName //服务名称ulong dwDesiredAccess //指定服务返回类型ulong dwServiceType //指定服务类型ulong dwStartType //指定启动类型 2表示自动运行 3表示手动运行 4表示禁止ulong dwErrorControl //指定服务启动失败的严重程度string lpBinaryPathName //指定服务程序二进制文件的路径string lpLoadOrderGroup //指定顺序装入的服务组名ulong lpdwTagId //忽略,NULLstring lpDependencies //指定服务帐号。如是NULL,则表示使用LocalSystem帐号 string lpstring lpPassword //指定对应的口令。为NULL表示无口令。但使用LocalSystem时填NULLstring ls_nulllpServiceName = "MyService"lpDisplayName = "测试服务"dwServiceType = 272dwStartType = 2dwErrorControl = 1lpBinaryPathName = ''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
[解决办法]
把程序单步执行一下,如果用到回调函数,PB需要用pbni来实现,如果用pb11以上版本,可以用在程序中直接嵌套.net代码来实现
[解决办法]
PB.NET WinForm 应该可以直接使用 回调函数。。。