【问题标题】:Prompt for computer name run the command "SMC -stop"提示输入计算机名称运行命令“SMC -stop”
【发布时间】:2013-07-04 21:24:26
【问题描述】:

所以让我先说我在编写脚本方面毫无用处,所以请多多包涵。

我们在整个企业中使用 Symantec Endpoint Protection (SEP),Citrix XenServer 5.5 和 SEP 11 似乎存在问题,SEP 将在没有警告的情况下停止几乎所有对 VM 的访问。通常有文件和打印或打印服务器虚拟机,因此站点上的所有打印都将停止或所有文件访问。

当它发生时,您可以 ping 虚拟机(因此 Nagios 认为它​​可以),并且许多其他检查(例如 SNMP 轮询等)仍然有效(因此 HP SIM 认为它可以)但是任何域用户的 RDP 访问和登录都被拒绝,所以您必须使用 XenCenter 并使用本地帐户登录。登录后,您只需运行“SMC -stop”,然后运行“SMC -start”即可停止和启动所有相关的 SEP 服务。

现在我们有一个 24/7 全天候服务台,但不允许他们访问 XenCenter,因此电话会直接转给 3 级支持,并且在凌晨 2 点,您真的不想因为这样的事情而被吵醒很简单。

因为您仍然可以远程运行命令,所以我想出某种形式的脚本(任何语言),它只会提示输入计算机名称并在输入后运行 'SMC -Stop' ,暂停 15 秒,然后运行“SMC -start”,Echo 的“Symantec Endpoint Protection Services Restarted”将是完美的,让我和我的队友们时不时地睡一觉。

到目前为止,我已经想出了以下脚本,但还没有机会对其进行测试,所以甚至不确定它是否能正常工作(我确实说过我不擅长编写脚本)

strComputer = InputBox("Name of computer to stop SEP Services on:", "Run SMC -stop")

If strComputer = "" Then
    Wscript.Quit
End If

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /c SMC -Stop"

MsgBox "Waiting 15 Seconds before restarting SEP Services"
WScript.Sleep 15000

Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /c SMC -Start"
Set oShell = Nothing

MsgBox "Symantec Endpoint Protection Services Restarted"*

感谢提供的任何帮助。

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    您的脚本将在本地计算机上运行命令,而不是在远程计算机上。要通过 VBScript 在远程计算机上执行命令,请尝试 WMI:

    computer = "..."
    
    Sub RunRemoteCommand(cmd, host)
      Set wmi = GetObject("winmgmts://" & host & "/root/cimv2")
      rc = wmi.Get("Win32_Process").Create(cmd, , , pid)
      If rc <> 0 Then
        WScript.Echo "Running '" & cmd & "' on " & computer & " failed (" & rc & ")."
        WScript.Quit 1
      End If
    End Sub
    
    RunRemoteCommand "smc -stop", computer
    WScript.Sleep 15000
    RunRemoteCommand "smc -start", computer
    

    您可以使用InputBox 函数提示输入计算机名称:

    computer = InputBox("Enter computername:")
    

    不过,通过PsExec 运行批处理脚本可能更简单:

    C:\&gt;<b>psexec \\computer -c restart_sep.cmd</b>

    restart_sep.cmd 看起来像这样:

    @echo off
    smc -stop
    ping -n 16 127.0.0.1 >nul
    smc -start
    

    选项-c 告诉PsExec 将批处理文件从本地主机复制到远程计算机,然后再在那里执行。 ping -n 16 127.0.0.1 模拟 sleep 15ping 在 2 个回显请求之间产生约 1 秒的延迟)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      相关资源
      最近更新 更多