2011-12-02 67 views
2

我需要一些帮助,在首先看起来像一个非常简单的要求的东西上走。通过打开的Windows应用程序进行循环

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

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

  1. 模拟的Alt + Tab按键只是切换的两个最 最近使用过的应用程序,而不是通过他们都骑自行车,和
  2. 没有可能,我可以看到用户能够 逃生出来的该脚本使用按键。

任何人都可以建议如何使用Windows(XP向上)机器上已有的资源来实现这一目标吗?

+0

这Windows的版本是针对这个目标的? – ChrisBD

+0

我需要XP和更高版本。 –

+0

使用['Alt + Esc'](http://technet.microsoft.com/en-us/magazine/2009.03.windowsconfidential.aspx)而不是'Alt + Tab'。 –

回答

5

原来,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 
+0

+1:我不知道ALT + ESC功能:) – saikosen

+0

该解决方案的逻辑有一个主要缺陷。 “关闭”段(“Else”块)在删除“AlreadyRunning”环境变量之前自行终止,该变量阻止脚本再次运行,直到用户注销。一个快速的解决方案是将'wshSystemEnv.Remove(“AlreadyRunning”)'语句移到'Else'块的顶部(在WMI循环之前),尽管这不是一个最佳的解决方案,因为无论迭代(开/关)的脚本将永远达到'整洁'部分。 – Makaveli84

1

这晚,我确实需要一种方法把这种优秀的解决方案上,并手动关闭。 因此,测试了XP专业版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 
3

对于它的价值的基础上,伊恩·伯恩斯脚本这里是一个“干净”的解决方案(检查我的提议的解决方案评论):

'**************************************************************************************** 
' 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 
相关问题