|
楼主 |
发表于 2024-7-23 18:33
|
显示全部楼层
本帖最后由 伶俐的毛豆 于 2024-7-23 18:40 编辑
tspliu 发表于 2024-7-23 17:18
拆字符串转键码这算基础知识了应该,一个foreach循环就解决了的事。
读回显内容啊,有一类windowsAPI 可 ...
如何用postmessage把这串命令传到dos窗口?我试验了好几次,都失败了,比如我要传入"cd C:\Users\G4987120\AppData\Local\Programs\WinSCP"
- Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
- Private Declare PtrSafe Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As LongPtr, ByVal wMsg As LongPtr, ByVal wParam As LongLong, lParam As LongPtr) As LongPtr
- Const VN_KEYDOWN = &H100 '???U??L?Y??
- Const VN_KEYUP = &H101 '?P?}??L?Y??
- Sub test()
- Dim hWnd As LongPtr
- Dim lParan As Long
- Dim TitleName As String
- Dim j&
- Dim Brr() As Byte
-
- TitleName = "C:\Windows\SYSTEM32\CMD.EXE"
-
- line1:
- hWnd = FindWindow("ConsoleWindowClass", TitleName)
- If hWnd <> 0 Then
- AppActivate TitleName
- Brr = StrConv("cd C:\Users\G4987120\AppData\Local\Programs\WinSCP", vbFromUnicode)
- For j = LBound(Brr) To UBound(Brr)
- Debug.Print "&H" & Format(Hex(Brr(j)), "00")
- PostMessage hWnd, VN_KEYDOWN, "&H" & Hex(Brr(j)), ByVal 0& '?o?e??
- Next j
- PostMessage hWnd, VN_KEYUP, &HD, ByVal 0& '?o?e???^????
- Application.Wait (Now + TimeValue("0:00:02"))
- Else
- Debug.Print "??????CMD???f."
- shell "CMD.EXE", 1
- Application.Wait (Now + TimeValue("00:00:02"))
- GoTo line1
- End If
- End Sub
复制代码
|
|