2

Ahh...so frustrated...hopefully someone here can help!

There is a software product called ScreenConnect that allows you to install it on your own server and through this install set up attended and unattended remote access sessions. I use this with a lot of my clients, but it's a lot easier to set up unattended installs on those client's machines that I'm going to be needing access to more than once. However, a few clients want to have control over when I can remote in and when I can't, and since the software product doesn't yet have this functionality built into it, I figured I'd just create two vbscript files on their desktops - one that turns off the service if it's on (and vice versa), and the other that changes the startup type of the service to automatic (if it's set to manual) and vice versa. I was able to pretty easily get the start/stop service vbscript file going:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
    ("select State from Win32_Service where Name LIKE '%ScreenConnect%'")

For Each objService in colRunningServices
Wscript.Echo "State: " & objService.State
    If objService.State <> "Running" Then
        errReturn = objService.StartService()
    Wscript.Echo "FalconRemote Started"
    Else
    errReturn = objService.StopService()
    Wscript.Echo "FalconRemote Stopped"
    End If
Next

However, for the life of me, I can't get the automatic/manual start-up type vbscript working on Windows XP. If I simplify it down to the bones and just want to have the vbscript tell me the current status of the startup (i.e. manual, automatic, disabled), which is obviously necessary for the vbscript to know so it can determine what to do based on that information, then this is what I put together:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
    ("select StartMode from Win32_Service where Name LIKE '%ScreenConnect%'")

For Each objService in colRunningServices
Wscript.Echo "StartMode: " & objService.PathName
Next

And yet, that returns "Unknown" instead of an acceptable value like "Manual", "Disabled", or "Autoamtic" - I have no idea why it's returning "Unknown"!!!

I've tried changing the fifth line to this:

("select * from Win32_Service where Name LIKE '%ScreenConnect%'")

or this

("select StartMode from Win32_Service where DisplayName LIKE '%ScreenConnect%'")

but it seems to have no effect.

If I change out ScreenConnect in the above script for another service, like helpsvc (using Name) or Help and Support (using DisplayName), it works! And it works fine on a Windows 7 machine. Why does it not work on a Windows XP machine? Any ideas???? I tried installing Mozilla Firefox 20 (with the Mozilla Maintenance Service) and it works fine reading the startmode of that service (which isn't built into WinXP), so why won't it read the startmode of this service?

Any help is greatly appreciated!

Thanks.

  • Marc
4

1 回答 1

0

我最近才遇到这个问题。

我不确定 Windows 服务是如何进入这种状态的,但似乎 Windows 服务处于“未知”状态。

例如,文件系统上可能不再存在可执行文件,但 Windows 服务(注册表)条目仍然(部分)存在。

无论如何,只需删除 Windows 服务条目即可解决问题。

可以使用以下命令行删除 Windows 服务,例如:

sc delete "ScreenConnect service name"
于 2014-04-12T01:22:55.913 回答