vb.net阻止关机 vbs关闭程序的代码

vb.net2008拦截关机或注销消息在SystemEvents类中 可以 用户试图注销或关闭系统时发生 。(当用户试图注销或关闭系统时发生 。当用户试图注销或关闭系统时发生 。) 这个 事件处理函数中 可以找到如下方法
Private Shared WM_QUERYENDSESSION As Integer = H11
Private Shared systemShutdown As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_QUERYENDSESSION Then
'MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot")
systemShutdown = True
End If
' If this is WM_QUERYENDSESSION, the closing event should be raised in the base WndProc.
MyBase.WndProc(m)
End Sub 'WndProc
Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If (systemShutdown) Then
' Reset the variable because the user might cancel the shutdown.
systemShutdown = False
If (System.Windows.Forms.DialogResult.Yes = _
MessageBox.Show("My application", "Do you want to save your work before logging off?", MessageBoxButtons.YesNo)) Then
e.Cancel = True
Else
e.Cancel = False
End If
End If
End Sub
VB.NET怎样设计定时关机1、开机进入桌面后vb.net阻止关机,按下“Windows徽标键+I”键,选中并打开“控制面板”
2、在“控制面板”中vb.net阻止关机的“系统和安全”里,选中“管理工具”里的“计划任务”,并打开“计划任务”
3、在“任务计划程序”里,打开“创建任务”
4、在“创建任务”的“常规”中,根据相应需求设置,比如“名称:定时关机”
5、在“创建任务”的“触发器”中,点“新建”,并在“新建触发器”中,根据相应需求设置后,点“确定”
6、在“创建任务”的“操作”中,点“新建”,并在“新建操作”中的“程序或脚本”里,根据下图依次输入“shutdown”和“-s”后,“点“确定”
7、在“创建任务”的“条件”中,根据相应需求设置
8、在“创建任务”的“设置”中,根据相应需求设置后 , 点“确定”
9、这时“定时关机”的任务已创建完成vb.net阻止关机!
如何在编的VB.NET程序使用时关闭电脑有两种方法 , 第一种是调用shutdown.exe
shell("shutdown.exe路径
-s
-t
0")
'-t是延迟时间,0表示立刻关机
另一种就是使用API了,好像是ExitWindow,你可以去搜索一下其用法 。
vb.net WinXP/2000操作系统自动关机的实现Windows
XP的关机是由Shutdown.exe程序来控制的,位于Windows\System32文件夹中 。如果想让Windows
2000也实现同样的效果,可以把Shutdown.exe复制到系统目录下 。
比如你的电脑要在22:00关机,可以选择“开始→运行”,输入“at
22:00
Shutdown
-s”,这样,到了22点电脑就会出现“系统关机”对话框 , 默认有30秒钟的倒计时并提示你保存工作 。如果你想以倒计时的方式关机,可以输入“Shutdown.exe
-s
-t
3600”,这里表示60分钟后自动关机,“3600”代表60分钟 。
设置好自动关机后,如果想取消的话,可以在运行中输入“shutdown
-a” 。另外输入“shutdown
-i”,则可以打开设置自动关机对话框,对自动关机进行设置 。
Shutdown.exe的参数,每个都具有特定的用途,执行每一个都会产生不同的效果,比如“-s”就表示关闭本地计算机,“-a”表示取消关
机操作,下面列出了更多参数 , 大家可以在Shutdown.exe中按需使用 。
其他的我也不多说了 , 这样说已经很详细了 , 你应该能看懂 。

推荐阅读