扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
using System;
using System.Runtime.InteropServices;
namespace FileWatchService
{
public class modAPI
{
[DllImport("advapi32.dll")]
public static extern int LockServiceDatabase(int hSCManager);
[DllImport("advapi32.dll")]
public static extern bool UnlockServiceDatabase(int hSCManager);
[DllImport("kernel32.dll")]
public static extern void CopyMemory(IntPtr pDst, SC_ACTION[] pSrc,int ByteLen);
[DllImport("advapi32.dll")]
public static extern bool ChangeServiceConfigA(
int hService, ServiceType dwServiceType, int dwStartType,
int dwErrorControl, string lpBinaryPathName, string lpLoadOrderGroup,
int lpdwTagId, string lpDependencies, string lpServiceStartName,
string lpPassword, string lpDisplayName);
[DllImport("advapi32.dll")]
public static extern bool ChangeServiceConfig2A(
int hService, InfoLevel dwInfoLevel,
[MarshalAs(UnmanagedType.Struct)] ref SERVICE_DESCRIPTION lpInfo);[DllImport("advapi32.dll")]
public static extern bool ChangeServiceConfig2A(
int hService, InfoLevel dwInfoLevel,
[MarshalAs(UnmanagedType.Struct)] ref SERVICE_FAILURE_ACTIONS lpInfo);[DllImport("advapi32.dll")]
public static extern int OpenServiceA(
int hSCManager, string lpServiceName, ACCESS_TYPE dwDesiredAccess);[DllImport("advapi32.dll")]
public static extern int OpenSCManagerA(
string lpMachineName, string lpDatabaseName, ServiceControlManagerType dwDesiredAccess);[DllImport("advapi32.dll")]
public static extern bool CloseServiceHandle(
int hSCObject);[DllImport("advapi32.dll")]
public static extern bool QueryServiceConfigA(
int hService, [MarshalAs(UnmanagedType.Struct)]
ref QUERY_SERVICE_CONFIG lpServiceConfig, int cbBufSize,
int pcbBytesNeeded);
[DllImport("advapi32.dll")]
public static extern int StartService(int SVHANDLE,int dwNumServiceArgs,string lpServiceArgVectors);public const int STANDARD_RIGHTS_REQUIRED = 0xF0000;
public const int GENERIC_READ = -2147483648;
public const int ERROR_INSUFFICIENT_BUFFER = 122;
public const int SERVICE_NO_CHANGE = -1;
//public const int SERVICE_NO_CHANGE = 0xFFFF;public enum ServiceType
{
SERVICE_KERNEL_DRIVER = 0x1,
SERVICE_FILE_SYSTEM_DRIVER = 0x2,
SERVICE_WIN32_OWN_PROCESS = 0x10,
SERVICE_WIN32_SHARE_PROCESS = 0x20,
SERVICE_INTERACTIVE_PROCESS = 0x100,
SERVICETYPE_NO_CHANGE = SERVICE_NO_CHANGE
}public enum ServiceStartType:int
{
SERVICE_BOOT_START = 0x0,
SERVICE_SYSTEM_START = 0x1,
SERVICE_AUTO_START = 0x2,
SERVICE_DEMAND_START = 0x3,
SERVICE_DISABLED = 0x4,
SERVICESTARTTYPE_NO_CHANGE = SERVICE_NO_CHANGE
}public enum ServiceErrorControl:int
{
SERVICE_ERROR_IGNORE = 0x0,
SERVICE_ERROR_NORMAL = 0x1,
SERVICE_ERROR_SEVERE = 0x2,
SERVICE_ERROR_CRITICAL = 0x3,
msidbServiceInstallErrorControlVital = 0x8000,
SERVICEERRORCONTROL_NO_CHANGE = SERVICE_NO_CHANGE
}public enum ServiceStateRequest:int
{
SERVICE_ACTIVE = 0x1,
SERVICE_INACTIVE = 0x2,
SERVICE_STATE_ALL = (SERVICE_ACTIVE + SERVICE_INACTIVE)
}public enum ServiceControlType:int
{
SERVICE_CONTROL_STOP = 0x1,
SERVICE_CONTROL_PAUSE = 0x2,
SERVICE_CONTROL_CONTINUE = 0x3,
SERVICE_CONTROL_INTERROGATE = 0x4,
SERVICE_CONTROL_SHUTDOWN = 0x5,
SERVICE_CONTROL_PARAMCHANGE = 0x6,
SERVICE_CONTROL_NETBINDADD = 0x7,
SERVICE_CONTROL_NETBINDREMOVE = 0x8,
SERVICE_CONTROL_NETBINDENABLE = 0x9,
SERVICE_CONTROL_NETBINDDISABLE = 0xA,
SERVICE_CONTROL_DEVICEEVENT = 0xB,
SERVICE_CONTROL_HARDWAREPROFILECHANGE = 0xC,
SERVICE_CONTROL_POWEREVENT = 0xD,
SERVICE_CONTROL_SESSIONCHANGE = 0xE,
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者