2011-12-02 64 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 
相關問題