已经实现对服务的控制.
现在想把我编译的EXE注册为系统服务,免得服务器重启了,程序也退出了.
代码如下#include <SmtpMailer.au3>
#Include <ServiceControl.au3>
Local $alarmtype[2]
$alarmtype[1]='服务挂了'
$sServiceName="linkService"
While 1
$server_status=_ServGetDetails($sServiceName)
If StringCompare($server_status,"running")<>0 Then
$s_Subject=$alarmtype[1]
sendmail()
EndIf
;Sleep(5*60*1000)
WEnd ;为真停止运行
Func sendmail()
$s_SmtpServer = "smtp.126.com" ;SMTP服务器
$s_FromName = "liu" ;邮件发送人
$s_FromAddress = "smtptest@126.com" ;邮件发送者地址
$s_ToAddress = "smtptest@126.com" ;收件人地址
;$s_Subject = "网关出错了!" ;邮件标题
$as_Body = "" ;邮件正文
$s_AttachFiles = "" ;附件地址
$s_CcAddress = "" ;抄送地址
$s_BccAddress = "" ;密件抄送地址
$s_Username = "smtptest@126.com" ;用户名
$s_Password = "12232311989824" ;密码
$IPPort = 25 ;发送端口,Gmail使用的发送端口为465
$ssl = 0
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
If @error Then
MsgBox(0, "邮件发送失败", "错误代号:" & @error & " 描述:" & $rc)
EndIf
EndFunc ;==>sendmail
利用srvinstw.exe 这个工具进行生成的. |