Is there a way to get access to a window handle in windows using WSH, or WMI or similar? I just want to flag a window as always-on-top. Ideally I'd use windows script host for this.
Please note, I don't want to install PowerShell on the system in question. We are nervous about any additional so开发者_C百科ftware and already have some VBS files involved.
Regards,
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
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
see ... wmic CLASS win32_process > C:\4.html
Wmic process where (Name='eclipse.exe') get CommandLine, ProcessId
May be create mof-file and compile, if need new wmi-winApi function ...
http://msdn.microsoft.com/en-us/library/windows/desktop/aa393907(v=vs.85).aspx
精彩评论