Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
循环浏览打开的Windows应用程序_Windows_Vbscript - Fatal编程技术网

循环浏览打开的Windows应用程序

循环浏览打开的Windows应用程序,windows,vbscript,Windows,Vbscript,我需要一些帮助,告诉我如何去做一件起初看起来很简单的事情 我必须找到一种在Windows PC上循环打开应用程序的方法,目标是在墙上的大屏幕上一次显示30秒。通常会有一个MS Access报告和几个网页 我最初的想法是,我可以在PC上手动打开这些应用程序,然后运行VBScript循环浏览它们。然而,这有两个问题 模拟Alt+Tab键只需切换两个最常用的键 最近使用的应用程序,而不是在它们之间循环,以及 我看不出用户能够 使用按键退出脚本 有人能建议我如何使用Windows(XP以上)机器上已有的

我需要一些帮助,告诉我如何去做一件起初看起来很简单的事情

我必须找到一种在Windows PC上循环打开应用程序的方法,目标是在墙上的大屏幕上一次显示30秒。通常会有一个MS Access报告和几个网页

我最初的想法是,我可以在PC上手动打开这些应用程序,然后运行VBScript循环浏览它们。然而,这有两个问题

  • 模拟Alt+Tab键只需切换两个最常用的键 最近使用的应用程序,而不是在它们之间循环,以及
  • 我看不出用户能够 使用按键退出脚本

  • 有人能建议我如何使用Windows(XP以上)机器上已有的资源来实现这一点吗?

    事实证明,在WHS中使用VBScript是可行的方法。这似乎奏效了

        '****************************************************************************************
    ' Script Name: ApplicationCycler.vbs
    '      Author: Ian Burns
    '        Date: 2 Dec 2011
    ' Description: VBScript for Windows Scripting Host. Cycles through any applications 
    '              visible in the Task Bar giving them focus for a set period.
    '       Usage: Save file to Desktop and double click to run. If it isn't already running,
    '              it will start. If it is already running, it will stop.
    '*****************************************************************************************
    Option Explicit
    
    Dim wshShell
    Dim wshSystemEnv
    Dim strComputer
    Dim objWMIService
    Dim colProcessList 
    Dim objProcess
    Dim intSleep
    
    ' Loop lasts 5 seconds
    intSleep = 5000
    
    Set wshShell = CreateObject("WScript.Shell")
    ' Volatile environment variables are not saved when user logs off
    Set wshSystemEnv = wshShell.Environment("VOLATILE")
    
    ' Check to see if the script is already running
    If len(wshSystemEnv("AlreadyRunning")) = 0 Then
    
        ' It isn't, so we set an environment variable as a flag to say the script IS running
        wshSystemEnv("AlreadyRunning") = "True"
    
        ' Now we go into a loop, cycling through all the apps on the task bar
        Do
            ' Simulate the Alt+Esc keypress
            wshShell.SendKeys "%+{Esc}"
            Wscript.Sleep intSleep
        Loop
    
    Else
    
        ' It IS already running so kill any or all instances of it
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'WScript.exe'")
        For Each objProcess in colProcessList
            objProcess.Terminate()
        Next
    
        ' Delete the environment variable
        wshSystemEnv.Remove("AlreadyRunning")
    
        ' Tidy up
        Set wshSystemEnv = Nothing
        Set wshShell = Nothing
        Set objWMIService = Nothing
        Set colProcessList = Nothing
    
    End If
    

    现在已经很晚了,我确实需要一种方法来手动打开和关闭这个优秀的解决方案。 因此,在xp Pro sp3上测试:

    '****************************************************************************************
    ' Script Name: Turn ON Loop thru open apps.vbs
    '      Author: Ian Burns
    '        Date: 2 Dec 2011
    ' Description: VBScript for Windows Scripting Host. Cycles through any applications 
    '              visible in the Task Bar giving them focus for a set period.
    '       Usage: Save file to Desktop and double click to run. If it isn't already running,
    '              it will start. If it is already running, it will stop.
    '*****************************************************************************************
    
    ' http://stackoverflow.com/questions/8356046/cycle-through-open-windows-applications
    
    Option Explicit
    
    Dim wshShell
    Dim wshSystemEnv
    Dim strComputer
    Dim objWMIService
    Dim colProcessList 
    Dim objProcess
    Dim intSleep
    
    ' Do Loop lasts 5 seconds
    intSleep = 5000
    
    Set wshShell = CreateObject("WScript.Shell")
    ' Volatile environment variables are not saved when user logs off
    Set wshSystemEnv = wshShell.Environment("VOLATILE")
    
    If len(wshSystemEnv("AlreadyRunning")) = 0 Then
    
        ' It isn't, so we set an environment variable as a flag to say the script IS running
        wshSystemEnv("AlreadyRunning") = "True"
    
        ' Now we go into a loop, cycling through all the apps on the task bar
        do
            ' Simulate the Alt+Esc keypress
            wshShell.SendKeys "%+{Esc}"
            Wscript.Sleep intSleep
        loop
    
        ' Tidy up
        Set wshSystemEnv = Nothing
        Set wshShell = Nothing
        Set objWMIService = Nothing
        Set colProcessList = Nothing
    
    End If
    
    and:
    
    '****************************************************************************************
    ' Script Name: Turn OFF Loop thru open apps.vbs
    '      Author: Dave
    '        Date: 1 Mar 2012
    ' Description: Turns off the above.
    ' '*****************************************************************************************
    Option Explicit
    
    Dim wshShell
    Dim wshSystemEnv
    Dim strComputer
    Dim objWMIService
    Dim colProcessList 
    Dim objProcess
    Dim intSleep
    
    Set wshShell = CreateObject("WScript.Shell")
    ' Volatile environment variables are not saved when user logs off
    Set wshSystemEnv = wshShell.Environment("VOLATILE")
    
        ' It IS already running so kill any or all instances of the above
        strComputer = "."
    
        Set objWMIService = GetObject("winmgmts:" & _
                            "{impersonationLevel=impersonate}!\\" & _
                            strComputer & "\root\cimv2")
    
        Set colProcessList = objWMIService.ExecQuery _
                               ("Select * from Win32_Process Where Name = 'WScript.exe'")
    
        For Each objProcess in colProcessList
            objProcess.Terminate()
        Next
    
        ' Delete the environment variable
        wshSystemEnv.Remove("AlreadyRunning")
    
        ' Tidy up
        Set wshSystemEnv = Nothing
        Set wshShell = Nothing
        Set objWMIService = Nothing
        Set colProcessList = Nothing
    

    值得一提的是,这里有一个基于Ian Burns脚本的“更干净”解决方案(请查看我对建议解决方案的评论):

    '****************************************************************************************
    ' Script Name: ApplicationCycler.vbs
    '      Author: Ian Burns
    '        Date: 2 Dec 2011
    '   Edited By: Makaveli84
    '   Edit Date: 30 Aug 2014
    ' Description: VBScript for Windows Scripting Host. Cycles through any applications 
    '              visible in the Task Bar giving them focus for a set period.
    '       Usage: Save file to Desktop and double click to run. If it isn't already running,
    '              it will start. If it is already running, it will stop.
    '*****************************************************************************************
    Option Explicit
    
    Dim wshShell
    Dim wshSystemEnv
    Dim intCycle
    Dim intSleep
    Dim intTimer
    
    ' Cycle every 5 seconds / Check on/off status every 250 milliseconds
    intCycle = 5000: intSleep = 250: intTimer = intCycle
    
    Set wshShell = CreateObject("WScript.Shell")
    ' Volatile environment variables are not saved when user logs off
    Set wshSystemEnv = wshShell.Environment("VOLATILE")
    
    ' Check to see if the script is already running
    If len(wshSystemEnv("AlreadyRunning")) = 0 Then
    
        ' It isn't, so we set an environment variable as a flag to say the script IS running
        wshSystemEnv("AlreadyRunning") = "True"
    
        ' Now we go into a loop, cycling through all the apps on the task bar
        Do While len(wshSystemEnv("AlreadyRunning")) > 0
            ' Simulate the Alt+Esc keypress
            If intTimer >= intCycle Then
                wshShell.SendKeys "%+{Esc}"
                intTimer = 0
            End If
            intTimer = intTimer + intSleep
            Wscript.Sleep intSleep
        Loop
    
    Else
        ' Delete the environment variable
        wshSystemEnv.Remove("AlreadyRunning")
    End If
    
    
    ' Tidy up
    Set wshSystemEnv = Nothing
    Set wshShell = Nothing
    

    这是针对哪个版本的windows?使用而不是
    Alt+Tab
    。此解决方案在其逻辑中有一个主要缺陷。“off”段(
    Else
    块)在删除“AlreadyRunning”环境变量之前自行终止,该环境变量阻止脚本再次运行,直到用户注销。快速修复方法是将
    wshsystemev.Remove(“AlreadyRunning”)
    语句移动到
    Else
    块的顶部(在WMI循环之前),尽管这不是最佳解决方案,因为脚本的迭代(开/关)都不会到达
    整理
    段。