- CommandModeX64("VBS 取前景窗体标题")
- WScript.Sleep(2000)
- WScript.Echo("前景窗体标题为:" & vbCrLf & GetForeWindowCaption())
-
- '************************************************************************
- '取前景窗体标题
- '************************************************************************
- Function GetForeWindowCaption()
- Const WM_GETTEXT = &HD
- Set Wrap = CreateObject("DynamicWrapper")
- Wrap.Register "USER32.DLL", "GetForegroundWindow", "f=s", "r=l"
- Wrap.Register "USER32.DLL", "SendMessage", "i=lllr", "f=s", "r=l"
- Title = Space(100)
- res = Wrap.SendMessage(Wrap.GetForegroundWindow(), WM_GETTEXT , 100, Title)
- GetForeWindowCaption = Title
- End Function
-
- '************************************************************************
- '以命令提示符环境运行(保留参数X64)
- '************************************************************************
- Sub CommandModeX64(ByVal sTitle)
- Dim objFSO, objWSO, strApp, strCommand, objItem, strArgs
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objWSO = CreateObject("WScript.Shell")
- strApp = objWSO.ExpandenVironmentStrings("%windir%\SysWOW64\cscript.exe")
- If Not objFSO.FileExists(strApp) Then strApp = objWSO.ExpandenVironmentStrings("%windir%\System32\cscript.exe")
- If InStr(1, WScript.FullName, strApp, vbTextCompare) > 0 Then Exit Sub
- strCommand = "%Comspec% /c title " & sTitle & " & " & strApp & " //NoLogo """ & WScript.ScriptFullName & """"
- For Each objItem In WScript.Arguments
- strArgs = strArgs & " " & """" & objItem & """"
- Next
- objWSO.Run strCommand & strArgs & " & pause", 1, False
- WScript.Quit
- End Sub
复制代码 Win10 x64 测试结果如下:- 前景窗体标题为:
- C:\Users\Yu2n\Desktop\0.vbs - Notepad++
- 请按任意键继续. . .
复制代码
|