用VB编写重启程序

用VB编写重启程序,第1张

你需要两个创建两个程序...

首先在你的主程序的代码里面添加它们:

'main program

public sub restart()

shell app.path &"\restart.exe " &app.path &"你的主程序的名字.exe",vbhide

end

end sub

用于重启的程序,叫做restart.exe

先创建标准exe工程

然后再在右边的工程资源管理器中右键点击form1

在d出的菜单中选择移除form1

然后点击菜单条上面的添加模块

在新添加的module1里添加它们

'restart program

sub main

shell command

end sub

生成exe到你的主程序所在的目录

这时你便可以在主程序的任意地方添加一行restart来重新启动你的程序了

Private Declare Function ExitWindowsEx Lib user (ByVal uFlags As Integer ByVal dwReserved As Integer) As IntegerConst EWX_FORCE As Short = Const EWX_LOGOFF As Short = Const EWX_REBOOT As Short = Const EWX_SHUTDOWN As Short = Dim retval As Integer 定义Esc按键Const VK_ESCAPE As Short = &H BsPrivate Sub Command _Click(ByVal eventSender As System Object ByVal eventArgs As System EventArgs) Handles Command ClickIf Option Checked Then 注销当前用户retval = ExitWindowsEx(EWX_FORCE )ElseIf Option Checked Then 关闭计算机retval = ExitWindowsEx(EWX_SHUTDOWN )ElseIf Option Checked Then 重新启动retval = ExitWindowsEx(EWX_REBOOT )End IfEnd SubPrivate Sub Command _Click(ByVal eventSender As System Object ByVal eventArgs As System EventArgs) Handles Command ClickMe Close()End Sub 按Esc键时 结束应用程序Private Sub Form _KeyPress(ByVal eventSender As System Object ByVal eventArgs As System Windows Forms KeyPressEventArgs) Handles MyBase KeyPressDim KeyAscii As Short = Asc(eventArgs KeyChar)If KeyAscii = VK_ESCAPE ThenMe Close()End IfIf KeyAscii = TheneventArgs Handled = TrueEnd IfEnd Sub本实例通过使用ExitWindowEx()API函数来达到关机和重新启动的目的 在ExitWindowEx()函数中 参数uFlags指定要进行何种 *** 作 在表 中列出了参数uFlags的值及其说明 表  参数uFlags的值及说明lishixinzhi/Article/program/net/201311/13585

添加一个按钮,输入代码:

Private Sub Command1_Click()

Shell "shutdown.exe -r -t 0" '立刻重启计算机

End Sub

运行后点击按钮,电脑就会重启


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存