1

WSH や WMI などを使用して、ウィンドウのウィンドウ ハンドルにアクセスする方法はありますか? ウィンドウを常に最前面に表示したいだけです。理想的には、これには Windows スクリプト ホストを使用します。

問題のシステムに PowerShell をインストールしたくないことに注意してください。追加のソフトウェアについて心配しており、すでにいくつかの VBS ファイルが含まれています。

よろしく、

4

2 に答える 2

-1
Private Const Firefox  = "C:\App32\Mozilla Firefox\firefox.exe"
Private Const IE8      = "C:\App32\Internet Explorer\iexplore.exe"
Private Const Opera    = "C:\App32\Opera\opera.exe"
Private Const Chrome   = "C:\App32\Google\Chrome\Application\new_chrome.exe"
Private Const Safari   = "C:\App32\Safari\Safari.exe"

Private Const ShowTime  =20000
Private Const TechWait  =200
Private Const CloseWait =1000

If WScript.Arguments.Count <1 then 
           Wscript.Echo "URL not found!"         & vbCrLf &_ 
                                                   vbCrLf &_
           "ex 1: "                              & vbCrLf &_ 
       Wscript.ScriptName & " ""<URI>"       & vbCrLf &_ 
       "ex 2: "                              & vbCrLf &_ 
       Wscript.ScriptName & " ""http://www.google.com"

       Wscript.Quit(10)
End If

Set oShell=CreateObject("Wscript.Shell")

Set oCommand=oShell.exec(Firefox   & " " & WScript.Arguments(0))
FirefoxPid=oCommand.ProcessID

Set oCommand=oShell.exec(IE8       & " " & WScript.Arguments(0))
IE8Pid=oCommand.ProcessID

Set oCommand=oShell.exec(Opera     & " " & WScript.Arguments(0))
OperaPid=oCommand.ProcessID

Set oCommand=oShell.exec(Chrome    & " " & WScript.Arguments(0))
ChromePid=oCommand.ProcessID

Set oCommand=oShell.exec(Safari    & " " & WScript.Arguments(0))
SafariPid=oCommand.ProcessID


WScript.Sleep ShowTime

oShell.AppActivate(FirefoxPid)
WScript.Sleep TechWait
oShell.SendKeys "%{F4}"

WScript.Sleep CloseWait

oShell.AppActivate(IE8Pid)
WScript.Sleep TechWait
oShell.SendKeys "%{F4}"

WScript.Sleep CloseWait

oShell.AppActivate(OperaPid)
WScript.Sleep TechWait
oShell.SendKeys "%{F4}"

WScript.Sleep CloseWait

oShell.AppActivate(ChromePid)
WScript.Sleep TechWait
oShell.SendKeys "%{F4}"

WScript.Sleep CloseWait

oShell.AppActivate(SafariPid)
WScript.Sleep TechWait
oShell.SendKeys "%{F4}"

Set oCommand = Nothing
Set oShell   = Nothing
于 2012-12-31T18:42:26.907 に答える
-1
Private Const wbemFlagReturnImmediately = 16
Private Const wbemFlagForwardOnly       = 32

Dim strComputer, objWMIService, strUserName, strPassword

UserName = ""
Password = ""
strComputer   = "."

Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",strUserName,strPassword)

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem in colItems
    WScript.Echo objItem.Caption, objItem.ProcessId, objItem.Commandline
Next

参照 ... wmic CLASS win32_process > C:\4.html

Wmic プロセス where (Name='eclipse.exe') get CommandLine, ProcessId

新しい wmi-winApi 関数が必要な場合は、mof ファイルを作成してコンパイルすることもできます ...

http://msdn.microsoft.com/en-us/library/windows/desktop/aa393907(v=vs.85).aspx

于 2012-12-31T19:49:47.847 に答える