有没有办法使用 WSH、WMI 或类似方法来访问 Windows 中的窗口句柄?

发布于 2024-08-11 20:46:13 字数 173 浏览 10 评论 0原文

有没有办法使用 WSH、WMI 或类似方法来访问 Windows 中的窗口句柄?我只想将一个窗口标记为始终在最上面。理想情况下,我会使用 Windows 脚本主机来实现此目的。

请注意,我不想在相关系统上安装 PowerShell。我们对任何附加软件感到紧张,并且已经涉及一些 VBS 文件。

问候,

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 software and already have some VBS files involved.

Regards,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苄①跕圉湢 2024-08-18 20:46:13
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 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
调妓 2024-08-18 20:46:13
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 类 win32_process > C:\4.html

Wmic 进程(名称='eclipse.exe')获取命令行,ProcessId

可能会创建 mof 文件并编译,如果需要新的 wmi-winApi 函数...

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文