[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] 窗口信息收集工具 getwininfo.exe beta 1.0

http://bcn.bathome.net/s/tool/index.html?key=getwininfo

用Au3写了这么一个小程序,发来与大家分享,并希望各位测试其中的BUG告知本人,不胜感谢!。。。
-----------------------------------------------------------------------------------------------------------------------------------------
修改部分代码,使之能在cmd中显示。
  1. GetWinInfo.au3 Beta 1.0   [Code By BBS.bathome.net Pusofalse]
  2. Usage: @ScriptName [option-1] [option-2] [...[option-6]] [/n] <Windowtitle>
  3. Options:
  4. /position  获取窗口位置[x y 宽度 高度]
  5. /handle   获取窗口内部句柄
  6. /text   获取窗口中的文本
  7. /integertitle  获取窗口的完整标题
  8. /process  获取窗口所关联的进程/PID
  9. /state   获取窗口状态
  10. Windowtitle: 窗口标题,可使用部分标题代替通配符,此参数必须指定。
  11. 注意:
  12. 若有多个窗口符合匹配条件,则只获取本程序匹配到的第一个窗口的信息。
  13. 标题区分大小写。
  14. 程序退出代码:0 成功、 1 参数错误、 2 未找到指定窗口
复制代码
au3代码:
  1. #AutoIt3Wrapper_Change2CUI=y
  2. #cs
  3. GetWinInfo.au3 Beta 1.0   [Code By BBS.bathome.net Pusofalse]
  4. Usage: @ScriptName [option-1] [option-2] [...[option-6]] [/n] <Windowtitle>
  5. Options:
  6. /position  获取窗口位置[x y 宽度 高度]
  7. /handle   获取窗口内部句柄
  8. /text   获取窗口中的文本
  9. /integertitle  获取窗口的完整标题
  10. /process  获取窗口所关联的进程/PID
  11. /state   获取窗口状态
  12. Windowtitle: 窗口标题,可使用部分标题代替通配符,此参数必须指定。
  13. 注意: 若有多个窗口符合匹配条件,则只获取本程序匹配到的第一个窗口的信息。
  14. #ce
  15. $Usage = @CRLF & "===============================================================================" &@CRLF
  16. $Usage &="    " & @ScriptName & " Beta 1.0   [Code By BBS.bathome.net Pusofalse]" & @CRLF
  17. $Usage &="===============================================================================" & @CRLF
  18. $Usage &= @CRLF & " Usage:  " &@ScriptName &"  [option-1] [option-2] [...[option-6]] <Windowtitle>"&@CRLF&@CRLF
  19. $Usage &= " Options:"&@CRLF
  20. $Usage &= " /position  Gets the window position with 4 elements-"
  21. $Usage &= "                                            [X,Y,Width,Height]." & @CRLF
  22. $Usage &= " /handle   Gets the window handle." & @CRLF
  23. $Usage &= " /text   Gets the text in the window." & @CRLF
  24. $Usage &= " /integertitle  Gets the complete title." & @CRLF
  25. $Usage &= " /process  Gets the PID associated the window." & @CRLF
  26. $Usage &= " /state   Gets the status of the window."  & @CRLF & @CRLF
  27. $Usage &= " Windowtitle: Specifies a window-title, you can use a part of the title to instead of "
  28. $Usage &= "                wildcard, this parameter must be specified!" & @CRLF & @CRLF
  29. $Usage &= "===============================================================================" & @CRLF
  30. $Usage &= " Note: "& @CRLF
  31. $Usage &= "       1. If many windows were matched, then only got the information of the first "
  32. $Usage &= "            window been caught by this program."&@CRLF
  33. $Usage &= @CRLF & "       2. The window-title is case-sensitive,so 'System' is different from 'system'." & @CRLF
  34. $Usage &= @CRLF & "       3. Exit code:" & @CRLF
  35. $Usage &= "                   0: Succeeded" &@CRLF
  36. $Usage &= "                   1: Invalid parameters" &@CRLF
  37. $Usage &= "                   2: Not found the specified window" & @CRLF
  38. $Usage &= "===============================================================================" & @CRLF
  39. If $CmdLine[0] < 2 Then
  40.    ConsoleWrite ($Usage)
  41.    Exit (1)
  42. Endif
  43. Global $var
  44. Global $po, $han, $tex, $inte, $proc, $stat
  45. $str = StringSplit ("position handle text integertitle process state n", " ")
  46. For $a = 1 to $str[0]
  47.      Assign ($str[$a], "a",2)
  48. Next
  49. Global $Final = $CmdLine[0]
  50. If WinExists($CmdLine[$Final]) Then
  51.    For $i = 1 to $CmdLine[0]-1
  52.         $str = StringReplace($CmdLine[$i], "/", "")
  53.         If Not IsDeclared($str) Then
  54.            Beep(2000,200)
  55.            ConsoleWrite(@CRLF & " Unkown parameter: " & $CmdLine[$i] & @CRLF)
  56.            Exit (1)
  57.         Else
  58.            call ($str)
  59.         EndIf
  60.    Next
  61. Else
  62.   Beep(1500,200)
  63.   ConsoleWrite(@CRLF & " Specified window not be found." & @CRLF)
  64.   Exit (2)
  65. Endif
  66. ConsoleWrite($var & @CRLF)
  67. Exit 0
  68. Func position()
  69.       $posi =  wingetpos($CmdLine[$Final])
  70.       For $i = 0 to 3
  71.             $po &= $posi[$i] & "   "
  72.       Next
  73.       $var &= @CRLF & $CmdLine[$Final] & " -Position:  "& $po
  74. EndFunc
  75. Func handle()
  76.       $han = WinGetHandle($CmdLine[$Final])
  77.       $var &= @CRLF & $CmdLine[$Final] & " -Handle:  " & $han
  78. EndFunc
  79. Func text()
  80.       $tex = WinGetText($CmdLine[$Final])
  81.       $var &= @CRLF & $CmdLine[$Final] & " -Text:  " & $tex
  82. EndFunc
  83. Func integertitle()
  84.       $inte = WinGetTitle($CmdLine[$Final])
  85.       $var &= @CRLF & $CmdLine[$Final] & " -IntegerTitle:  " & $inte
  86. EndFunc
  87. Func process()
  88.       $proc = WinGetProcess($CmdLine[$Final])
  89.       $var &= @CRLF & $CmdLine[$Final] & " -Process:  " &$proc
  90. EndFunc
  91. Func state()
  92.      $stat = WinGetState($CmdLine[$Final])
  93.      If BitAnd($stat, 1) Then
  94.         $var &= @CRLF & $CmdLine[$Final] & " -State:    Exists."
  95.     EndIf
  96.      If BitAnd($stat, 2) Then
  97.         $var &= @CRLF & $CmdLine[$Final] & " -State:    Visibel."
  98.     EndIf
  99.      If BitAnd($stat, 4) Then
  100.         $var &= @CRLF & $CmdLine[$Final] & " -State:    Enabled."
  101.     EndIf
  102.      If BitAnd($stat, 8) Then
  103.         $var &= @CRLF & $CmdLine[$Final] & " -State:    Activated."
  104.     EndIf
  105.      If BitAnd($stat, 16) Then
  106.         $var &= @CRLF & $CmdLine[$Final] & " -State:    Minimized."
  107.     EndIf
  108.      If BitAnd($stat, 32) Then
  109.         $var &= @CRLF & $CmdLine[$Final] & " -State:    Maximized."
  110.     EndIf
  111. EndFunc
复制代码
批处理测试代码:
  1. @echo off
  2. echo  匹配标题中含有字串"批处理之家"的窗口,并输出其位置、状态。
  3. getwininfo.exe /position /state "批处理之家"
  4. pause>nul&echo.
  5. echo 匹配标题中含有字串"QQ"的窗口,并输出其完整标题、PID
  6. echo 标题名区分 大小写。
  7. getwininfo /integertitle /process QQ
  8. pause>nul&echo.
  9. echo 输出此批处理中的文本、窗口状态,并记录此文本的PID。
  10. start /min notepad.exe "%~f0"
  11. for /f "tokens=1,2*" %%a in ('getwininfo /text /state /process "%~n0"') do (
  12.      if /i "%%b" neq "-Process:" (
  13.         echo.%%a %%b %%c
  14.         ) else (
  15.         set "pid=%%c"
  16. ))
  17. echo. & echo "notepad.exe %~n0" 的pid是%pid%
  18. pause>nul
复制代码
心绪平和,眼藏静谧。

下载连接失效

TOP

返回列表