_Singleton("TheNameOfMy")
Opt("WinTitleMatchMode", 2)
Opt("TrayIconHide", 1)
if $CmdLineRaw ="" Then
$cfgpath=@ScriptDir&"\Safe.ini"
Else
$cfgpath=$CmdLine[1]
EndIf
if $cmdline[0] < 2 Then
$hkey=IniRead($cfgpath,"程序配置","热键设置","")
Else
$hkey=$cmdline[2]
EndIf
If not FileExists ( $cfgpath ) Then error("未找到配置文件!")
If $hkey="" Then error("未设置热键!")
HotkeySet($hkey, "_exit")
if IniRead($cfgpath,"程序配置","日志路径","") = "" Then
$logfilename=@ScriptDir&"\SafeLog.log"
Else
$logfilename=iniread($cfgpath,"程序配置","日志路径","")
EndIf
$msg=iniread($cfgpath,"程序配置","弹出消息","")
$s_windows = 1
$c_windows = IniReadSection($cfgpath, "禁止窗口")
if @error then $s_windows=0
$s_pro = 1
$c_pro = IniReadSection($cfgpath, "禁止进程")
if @error then $s_pro=0
$s_runpro = 1
$c_runpro = IniReadSection($cfgpath, "监视进程")
if @error then $s_runpro=0
$s_mustpro = 1
$c_mustpro = IniReadSection($cfgpath, "必须进程")
if @error then $s_mustpro=0
if $s_windows=0 And $s_pro=0 And $s_runpro=0 And $s_mustpro=0 Then error("配置文件的项目为空或无法读取!程序退出!")
While 1
if $s_windows=1 then
For $i = 1 To $c_windows[0][0]
If StringInStr(WinGetTitle(""),$c_windows[$i][0])>0 Then
WinClose("")
if $msg = 1 Then MsgBox(4096,"提醒!","您的操作不被安全中心允许,该行为已被记录上报",15)
WriteLog("在计算机" & @ComputerName & "上发现非法窗口:" & $c_windows[$i][0])
endif
Next
Endif
If $s_pro =1 Then
for $i = 1 to $c_pro[0][0]
If ProcessExists($c_pro[$i][0]) Then
ProcessClose($c_pro[$i][0])
if $msg = 1 Then MsgBox(0,"警告!","对不起!进程("&$c_pro[$i][0]&")已被安全中心禁止!",2)
WriteLog("在计算机" & @ComputerName & "上发现非法[进程]:" & $c_pro[$i][0])
endif
Sleep(15)
Next
EndIf
If $s_runpro = 1 Then
For $i = 1 to $c_runpro[0][0]
If Not ProcessExists($c_runpro[$i][0]) Then
Run($c_runpro[$i][1],"",@SW_HIDE)
If @error Then Run(@ComSpec & " /c " & $c_runpro[$i][1], "", @SW_HIDE)
EndIf
Sleep(5000)
Next
EndIf
If $s_mustpro = 1 Then
for $i= 1 to $c_mustpro[0][0]
If Not ProcessExists($c_mustpro[$i][0]) Then Shutdown(6)
Next
EndIf
WEnd
Func _exit()
exit
EndFunc
Func writelog($s)
$logfile=FileOpen($logfilename,1)
if $logfile=-1 Then
ToolTip("日志文件写入失败!",0,0)
Else
$time1=@YEAR&"-"&@MON&"-"&@MDAY&" "&@HOUR&":"&@MIN&":"&@SEC&" "
FileWriteLine($logfile,$time1&$s)
EndIf
FileClose($logfile)
EndFunc
Func error($s)
MsgBox(0,"错误!",$s)
Exit
EndFunc
最后修改:2022 年 03 月 27 日
© 允许规范转载