VBS 强制关闭Symantec Endpoint Protection的代码

2019-01-15 23:02:48王冬梅

' ====================================================================================================
' 获取当前的日期时间,并格式化
Function NowDateTime()
    'MyWeek = "周" & Right(WeekdayName(Weekday(Date())), 1) & " "
    MyWeek = ""
    NowDateTime = MyWeek & Format_Time(Now(),2) & " " & Format_Time(Now(),3)
End Function
Function Format_Time(s_Time, n_Flag)
    Dim y, m, d, h, mi, s
    Format_Time = ""
    If IsDate(s_Time) = False Then Exit Function
    y = cstr(year(s_Time))
    m = cstr(month(s_Time))
        If len(m) = 1 Then m = "0" & m
    d = cstr(day(s_Time))
        If len(d) = 1 Then d = "0" & d
    h = cstr(hour(s_Time))
        If len(h) = 1 Then h = "0" & h
    mi = cstr(minute(s_Time))
        If len(mi) = 1 Then mi = "0" & mi
    s = cstr(second(s_Time))
        If len(s) = 1 Then s = "0" & s
    Select Case n_Flag
        Case 1
            Format_Time = y  & m & d  & h  & mi  & s    ' yyyy-mm-dd hh:mm:ss
        Case 2
            Format_Time = y & "-" & m & "-" & d    ' yyyy-mm-dd
        Case 3
            Format_Time = h & ":" & mi & ":" & s   ' hh:mm:ss
        Case 4
            Format_Time = y & "年" & m & "月" & d & "日"    ' yyyy年mm月dd日
        Case 5
            Format_Time = y & m & d    ' yyyymmdd
    End Select
End Function


' ====================================================================================================
' 检查字符串是否符合正则表达式
'Msgbox Join(RegExpTest( "[A-z]+-[A-z]+", "a-v d-f b-c" ,"Value"), VbCrLf)
'Msgbox RegExpTest( "[A-z]+-[A-z]+", "a-v d-f b-c" ,"Count")
'Msgbox RegExpTest( "[A-z]+-[A-z]+", "a-v d-f b-c" ,"")
Function RegExpTest(patrn, strng, mode)
    Dim regEx, Match, Matches      ' 建立变量。
    Set regEx = New RegExp         ' 建立正则表达式。
        regEx.Pattern = patrn      ' 设置模式。
        regEx.IgnoreCase = True    ' 设置是否区分字符大小写。
        regEx.Global = True        ' 设置全局可用性。
    Dim RetStr, arrMatchs(), i  :  i = -1
    Set Matches = regEx.Execute(strng)     ' 执行搜索。
    For Each Match in Matches              ' 遍历匹配集合。
        i = i + 1
        ReDim Preserve arrMatchs(i)        ' 动态数组:数组随循环而变化
        arrMatchs(i) = Match.Value
        RetStr = RetStr & "Match found at position " & Match.FirstIndex & ". Match Value is '" & Match.Value & "'." & vbCRLF
    Next
    If LCase(mode) = LCase("Value") Then RegExpTest = arrMatchs       ' 以数组返回所有符合表达式的所有数据
    If LCase(mode) = LCase("Count") Then RegExpTest = Matches.Count   ' 以整数返回符合表达式的所有数据总数
    If IsEmpty(RegExpTest) Then RegExpTest = RetStr                   ' 返回所有匹配结果
End Function