VBS调用windows api函数(postmessage)实现后台发送按键脚本

简介: '=========================================================================='' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
' NAME:
'
' AUTHOR: Microsoft , Microsoft
' DATE : 2014/8/10
'
' COMMENT:
'
'===================定义变量,注册API对象==================================
Dim UserWrap,hWnd

Set UserWrap = CreateObject("DynamicWrapper")
Set ws=WScript.CreateObject("wscript.shell")

WScript.Sleep 500

ws.Run "calc",0

WScript.Sleep 500

'Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
UserWrap.Register "USER32.DLL", "ShowWindow", "I=hl", "f=s", "R=l"

'Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

UserWrap.Register "USER32.DLL", "FindWindow", "I=ss", "f=s", "R=l"

'Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

UserWrap.Register "USER32.DLL", "SetWindowPos", "I=Hllllll", "f=s", "R=l"

'Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
UserWrap.Register "USER32.DLL", "PostMessage", "I=hlls", "f=s", "R=l"

'Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
UserWrap.Register "USER32.DLL", "SetWindowText", "I=Hs", "f=s", "R=l"

'Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
UserWrap.Register "USER32.DLL", "FindWindowEx", "I=llss", "f=s", "R=l"

'Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long

UserWrap.Register "USER32.DLL", "SetCursorPos", "I=ll", "f=s", "R=l"

'===================查找控件或者窗体句柄===============================


hWnd = UserWrap.FindWindow(vbNullString,"计算器")
'hWnd = UserWrap.FindWindow("kugou_ui",vbNullString)

hWnd1 = UserWrap.FindWindowEx(hWnd,0,vbNullString,Edit)

'UserWrap.ShowWindow hWnd,SW_HIDE

'UserWrap.SetWindowText hWnd,"hello world"

' MsgBox hWnd
' MsgBox hWnd1

'UserWrap.SetWindowPos hWnd, -1, 0, 0, 0, 0, 3

'MsgBox "将鼠标移到左上角"


'UserWrap.SetCursorPos 0,0


'=================定义系统常量===========================

Private Const WM_KEYDOWN = &H100
Private Const wm_keyup= &H101
Private Const WM_CHAR = &H102
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105

 

'=================发送F1按键=====================
UserWrap.PostMessage hWnd, WM_KEYDOWN, 112, 0

'=================发送1002========================
UserWrap.PostMessage hWnd,WM_KEYDOWN ,97,0
UserWrap.PostMessage hWnd,WM_KEYDOWN ,96,0
UserWrap.PostMessage hWnd,WM_KEYDOWN ,96,0
UserWrap.PostMessage hWnd,WM_KEYDOWN ,98,0

 

技术改变世界! --狂诗绝剑
目录
相关文章
|
2月前
|
Linux C++ Windows
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
【Azure 应用服务】Azure App Service(Windows)环境中如何让.NET应用调用SAP NetWeaver RFC函数
|
9天前
|
Python Windows
python之windows脚本启动bat
python之windows脚本启动bat
|
6天前
|
网络协议 API Windows
MASM32编程调用 API函数RtlIpv6AddressToString,windows 10 容易,Windows 7 折腾
MASM32编程调用 API函数RtlIpv6AddressToString,windows 10 容易,Windows 7 折腾
|
2月前
|
安全 Shell Windows
记windows自定义bat脚本自启动
【8月更文挑战第27天】在Windows系统中,可让自定义bat脚本自启动的方法有两种:一是利用“启动”文件夹,通过创建bat脚本的快捷方式并将其放置于该文件夹;二是使用任务计划程序,创建一个启动时触发的任务来运行bat脚本。需确保脚本正确安全,避免对系统产生不良影响。
|
4月前
|
Windows
【Windows内核驱动函数(1)】IoCreateSymbolicLink()-----创建符号链接函数
【Windows内核驱动函数(1)】IoCreateSymbolicLink()-----创建符号链接函数
|
4月前
|
关系型数据库 MySQL 数据安全/隐私保护
windows系统bat批处理 mysql 脚本启动关闭
windows系统bat批处理 mysql 脚本启动关闭
187 3
|
4月前
|
Windows
windows系统vbs脚本 恶搞关不掉的窗口 以及解决办法
windows系统vbs脚本 恶搞关不掉的窗口 以及解决办法
90 2
|
4月前
|
Windows
windows系统vbs脚本 恶搞将系统搞崩 死机 以及解决
windows系统vbs脚本 恶搞将系统搞崩 死机 以及解决
43 1
|
4月前
|
Windows
逆向学习Windows篇:通过编写函数处理菜单消息
逆向学习Windows篇:通过编写函数处理菜单消息
27 0
|
4月前
|
监控 安全 Windows
逆向学习Windows篇:lab的使用和生成过程,以及“dell”的导出函数和作用
逆向学习Windows篇:lab的使用和生成过程,以及“dell”的导出函数和作用
56 0
下一篇
无影云桌面