|
本帖最后由 伶俐的毛豆 于 2024-7-23 18:53 编辑
- 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
- Const VN_KEYUP = &H101
- 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\我的文档\AppData\Local\Programs\WinSCP", vbFromUnicode)
- For j = LBound(Brr) To UBound(Brr)
- PostMessage hWnd, VN_KEYDOWN, "&H" & Hex(Brr(j)), ByVal 0&
- Next j
- PostMessage hWnd, VN_KEYUP, &HD, ByVal 0&
- Application.Wait (Now + TimeValue("0:00:02"))
- Else
- shell "CMD.EXE", 1
- Application.Wait (Now + TimeValue("00:00:02"))
- GoTo line1
- End If
- End Sub
复制代码
我想用postMessage函数将这串dos命令("cd C:\Users\我的文档\AppData\Local\Programs\WinSCP")发送到dos窗口,死活没有成功,请大家帮忙看看
|
|