用于查找服务和管理其状态的脚本 [英] Script to find the service and manage its state

查看:77
本文介绍了用于查找服务和管理其状态的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我们在不同的机器上运行不同名称的服务,例如

We have a service that runs with different names on different machines like

Bomgar-scadsadccd,Bomgarsdscchfn,Bomgarscnkfkdk

Bomgar-scadsadccd, Bomgarsdscchfn, Bomgarscnkfkdk

所以,在这里,我们需要编写一个VB脚本,它将找到部分名称为"Bomgar"的服务。检查它的状态如

So, here we need to write a VB script that will find this service with partial name "Bomgar" and check it's status like

1)不存在,然后应该从像"start \10.216.16.245\Bomgar.exe"这样的共享文件夹安装。

1) Not present, then should install from a shared folder like "start \10.216.16.245\Bomgar.exe"

2)已安装但未运行,然后启动该服务。

2) Installed but not running, then start the service.

3)安装并运行然后退出。

3) Installed and running then quit.

我们如何实现这一目标?这就是我试过的..

How can we achieve this? This is what i have tried..

" strComputer ="。"

设置objWMIService = GetObject(" winmgmts:" _

&" {impersonationLevel = impersonate}!\\"& strComputer&" ; \ root \ cimv2")

设置colRunningServices = objWMIService.ExecQuery(" Select * from Win32_Service

,其中Name ='bomgar *'")

nItems = colRunningServices.Count

    如果nItems> 0 然后是
For colRunningServices中的每个对象

     if objItem.State =" Stopped"然后是objItem.startservice            

            ElseIf objItem.State =" Running"然后退出

               

结束如果

     Next

Else

       开始\\10.18.23.245 \ Shared \Bomgar.exe

结束如果

"strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service
where Name='bomgar*'")
nItems = colRunningServices.Count
    If nItems > 0  Then
For Each objItem in colRunningServices
    If objItem.State = "Stopped" Then objItem.startservice            
            ElseIf objItem.State = "Running" Then exit
               
End If
    Next
Else
        start \\10.18.23.245\Shared\Bomgar.exe
End If

推荐答案

您无法远程安装服务。 通过运行文件。 如果可能,您需要联系供应商以了解如何以静默方式远程安装服务。

You cannot remotely install a service.  by running the file.  You will need to contact the vendor to learn how to silently and remotely install the service if that is possible.


这篇关于用于查找服务和管理其状态的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆