VB里面单击按钮运行程序

VB里面单击按钮运行程序,第1张

Shell () 函数额可以调用第前旁三方程序。 shutdown是windows管理关机的程序,直接调用

Shell "cmd.exe /c shutdown -s -t 10 -c"

另外,你说要别的办法,用windows API: ExitWindowsEx

ExitWindowsEx需要获取权限

主要代码:

Private Sub Form_Load()

Dim hProcessHandle As Long

Dim hTokenHandle As Long

Dim tmpLuid As LUID

Dim tkpNew As TOKEN_PRIVILEGES

Dim tkpPrevious As TOKEN_PRIVILEGES

Dim lBufferNeeded As Long

'获取当前棚正进程的一个链悔悔伪句柄

hProcessHandle = GetCurrentProcess()

OpenProcessToken hProcessHandle, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hTokenHandle

LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid

tkpNew.PrivilegeCount = 1

tkpNew.TheLuid = tmpLuid

tkpNew.Attributes = SE_PRIVILEGE_ENABLED

lBufferNeeded = 0

'允许当前应用程序有关闭 *** 作系统的权限

AdjustTokenPrivileges hTokenHandle, False, tkpNew, Len(tkpPrevious), tkpPrevious, lBufferNeeded

End Sub

Private Sub Command1_Click()

'重新启动计算机

ExitWindowsEx EWX_REBOOT, 0

End Sub

Private Sub Command2_Click()

'关闭计算机

ExitWindowsEx EWX_FORCE Or EWX_SHUTDOWN, 0

End Sub

Private Sub Command4_Click()

ExitWindowsEx EWX_LOGOFF, 0

End Sub

'一个Timer : Timer1

'早绝两个Command : Command1,Command2

'三个OptionBox : Option1 , Option2 , Option3 .

Option Explicit

'

'请把详细过程和代码说下?

Private Sub Command1_Click()

'1:按键盘的 ALT+TAB(是先按ALT然后不松开ALT按TAB 目的就是为了切换)

SendKeys "%{TAB}"

Me.Timer1.Enabled = True

End Sub

Private Sub Command2_Click()

Me.Timer1.Enabled = False

End Sub

Private Sub Form_Load()

Me.Timer1.Interval = 1000

Me.Timer1.Enabled = False

End Sub

Private Sub Timer1_Timer()

'前面有6个选择。后面是6个相对应的运行按键. 然后还有一个停止按键,按后停止所有动作。

'

'例如选择1(神睁伏在1选择那打勾,然后点运行后 键盘自动先按ctrl+d后按ctrl+q

If Me.Option1.Value Then

SendKeys "^D"

SendKeys "^Q"

End If

'选择2(在2选择那打勾,然后点运行后 键盘自动先按ctrl+d后按ctrl+d

'

If Me.Option2.Value Then

SendKeys "^D"

SendKeys "^D"

End If

'选择3(在3选择那打勾,然后点运行后 键盘自动先按ctrl+q后按ctrl+q

If Me.Option2.Value Then

SendKeys "^Q"

SendKeys "^Q"

End If

'选择3(在3选择那打勾,然后游携点运行后 键盘自动先按ctrl+q后按ctrl+a

'

If Me.Option3.Value Then

SendKeys "^Q"

SendKeys "^A"

End If

'

'

'忘了 都要是 能无限 按的 直到自己按 停止 键后才停止!

End Sub

写了一个简易代码,基山陵本上能满足你的需求~~

在Form上丛键添加两个Timer控件,然后在代码窗口中复制粘贴以下代码:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

Private Sub Form_Load()

Timer1.Interval = 100

Timer2.Interval = 500

Timer1.Enabled = False

End Sub

Private Function MyHotKey(vKeyCode) As Boolean

MyHotKey = GetAsyncKeyState(vKeyCode) <0

End Function

Private Sub Timer1_Timer()

SendKeys "{5}"

SendKeys "{3}"

SendKeys "{2}"

SendKeys "{4}"

SendKeys "{7}"

SendKeys "{8}"

SendKeys "{9}"

End Sub

Private Sub Timer2_Timer()

If MyHotKey(vbKey6) Then

If Timer1.Enabled = False Then

Timer1.Enabled = True

Else

Timer1.Enabled = False

End If

End If

End Sub

程序运行后,按下键盘字符6键后逗郑戚开始不停按键 *** 作,再次按下字符6键即停止。这段代码只适用于目标程序处于前台窗口激活状态下使用!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12234440.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存