扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
µ±ÎÒÃǸø·þÎñÔö¼Ó°²×°°üʱ£¬ÎÒÃÇ¿ÉÒÔÔÚProjectInstallerÀï¼ÓÉÏÎÒÃÇÐ޸ķþÎñÃèÊöµÄ´úÂë
private void InitializeComponent()
{
//ÕâÀïÒªÔö¼Ó´úÂë
this.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.ProjectInstaller_AfterInstall);
}
private void ProjectInstaller_AfterInstall(object sender,System.Configuration.Install.InstallEventArgs e)
{
int iSCManagerHandle = 0;
int iSCManagerLockHandle = 0;
int iServiceHandle = 0;
bool bChangeServiceConfig = false;
bool bChangeServiceConfig2 = false;
modAPI.SERVICE_DESCRIPTION ServiceDescription;
modAPI.SERVICE_FAILURE_ACTIONS ServiceFailureActions;
modAPI.SC_ACTION[] ScActions = new modAPI.SC_ACTION[3];
bool bCloseService = false;
bool bUnlockSCManager = false;
bool bCloseSCManager = false;
IntPtr iScActionsPointer = new IntPtr();
try
{
//´ò¿ª·þÎñ¿ØÖÆÌ¨
iSCManagerHandle = modAPI.OpenSCManagerA(null, null,
modAPI.ServiceControlManagerType.SC_MANAGER_ALL_ACCESS);
if (iSCManagerHandle < 1)
{
throw new Exception("²»ÄÜ´ò¿ª·þÎñ¹ÜÀíÆ÷.");
}
iSCManagerLockHandle = modAPI.LockServiceDatabase(iSCManagerHandle);
if (iSCManagerLockHandle < 1)
{
throw new Exception("²»ÄÜËø¶¨·þÎñ¹ÜÀíÆ÷.");
}
//·þÎñÃû
iServiceHandle = modAPI.OpenServiceA(iSCManagerHandle, "JadeWatchService",
modAPI.ACCESS_TYPE.SERVICE_ALL_ACCESS);
if (iServiceHandle < 1)
{
throw new Exception("²»ÄÜ´ò¿ª·þÎñ½øÐÐÐÞ¸Ä.");
}
bChangeServiceConfig = modAPI.ChangeServiceConfigA(iServiceHandle,
modAPI.ServiceType.SERVICE_WIN32_OWN_PROCESS | modAPI.ServiceType.SERVICE_INTERACTIVE_PROCESS,
modAPI.SERVICE_NO_CHANGE, modAPI.SERVICE_NO_CHANGE, null, null,
0, null, null, null, null);
if (bChangeServiceConfig==false)
{
throw new Exception("²»Äܸıä·þÎñÉèÖÃ.");
}
ServiceDescription.lpDescription = "ÇàÄñÎļþ¼à¿Ø·þÎñ,Èç¹ûÍ£Ö¹¸Ã·þÎñ,Êý¾Ý½«²»ÄÜÕý³£½øÐб¸·Ý!";
bChangeServiceConfig2 = modAPI.ChangeServiceConfig2A(iServiceHandle,
modAPI.InfoLevel.SERVICE_CONFIG_DESCRIPTION,ref ServiceDescription);
if (bChangeServiceConfig2==false)
{
throw new Exception("²»ÄܽøÐзþÎñÃèÊö¸ü¸Ä.");
}
ServiceFailureActions.dwResetPeriod = 600;
ServiceFailureActions.lpRebootMsg = "·þÎñÆô¶¯Ê§°Ü! ÖØÆôÖÐ...";
// ServiceFailureActions.lpCommand = "SomeCommand.exe Param1 Param2";
ServiceFailureActions.lpCommand = "";
ServiceFailureActions.cActions = ScActions.Length;
//¹ÊÕϻָ´ÉèÖã¬ÕâÀïûÓÐÉèÖÃ
ScActions[0].Delay = 20000;
ScActions[0].SCActionType = modAPI.SC_ACTION_TYPE.SC_ACTION_NONE; //²»Òª¶Ôʧ°Ü²Ù×÷×öÈκδ¦Àí,Èç¹ûÖØÆô·þÎñµÈ
ScActions[1].Delay = 20000;
ScActions[1].SCActionType = modAPI.SC_ACTION_TYPE.SC_ACTION_NONE;
ScActions[2].Delay = 20000;
ScActions[2].SCActionType = modAPI.SC_ACTION_TYPE.SC_ACTION_NONE;
iScActionsPointer = Marshal.AllocHGlobal(Marshal.SizeOf(new modAPI.SC_ACTION()) * 3);
modAPI.CopyMemory(iScActionsPointer, ScActions, Marshal.SizeOf(new modAPI.SC_ACTION()) * 3);
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。