如何在Windows系统上停止并重新启动服务的附带dll?

时间:2018-04-18 16:33:54

标签: linux windows powershell dll

我正在尝试使用PowerShell构建一个脚本,以禁止来自Webhobbit监控的系统(Windows Server)的警报。 Webhobbit从名为BBwin的应用程序获取系统统计信息(CPU /内存使用/正常运行时间等)。 BBwin使用内置的dll文件报告这些统计信息。

对于Unix服务器,我可以通过使用bash脚本禁用正在运行的dll来禁止警报。但是,我无法在Windows Server上使用Powershell这样做。我尝试在我的脚本中使用regsrv32.exe,它无法正常工作。使用PowerShell我能够停止BBWin服务,但不是每个dll加载

我的问题是:如何停止并重新启动Windows系统上随附的服务dll?

以下是我为抑制警报而构建的脚本:

Bash脚本

 #!/bin/bash

if [ $# -lt 2 ]; then
   echo "USAGE:  $2 time 'message'"
   echo "Where"
   echo "   time = maintenance time [in minutes]"
   echo "   message = 'quoted downtime message' [enclosed in single-quotes]"
   exit
fi

time=$1
message=$2

# List of hosts to disable
hosts='ABCD'
tests='msgs procs url'

for test in $tests; do

   for host in $hosts; do
      echo "Disabling $host.$test"
      /usr/local/hobbit/client/bin/bb webhobbit "disable $host.$test $time $message"
   done
done 

PowerShell脚本

   $services = 'BBwin'
   $servers  = 'ABCD'
   $problems = @()

   foreach($server in $servers){
   foreach($service in $services){


   # Checking the current status of the BBwin
   $service_status = (Get-Service -Name $service).status

   #If Service Status Is : Running
   if(($service_status -eq 'running')){

        Stop-Service -Name $service 

        # Try to stop it and wait 5 seconds
        Start-Sleep -Seconds 5


        #How do I get access to msgs procs url?



        # Check again if it is running now, if not add info to $problems
        if((((Get-Service -Name $service).status) -eq 'stopped')){
          Write-Host "Process stopped succesfully"
        }
      }
    }
  }

0 个答案:

没有答案