重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net自动关机 vb自动关机的代码

求一个VB检测鼠标键盘无操作自动关机脚本

楼上vb的可行,在vb.net中不行,vb.net格式如下

创新互联 - 服务器托管,四川服务器租用,成都服务器租用,四川网通托管,绵阳服务器托管,德阳服务器托管,遂宁服务器托管,绵阳服务器托管,四川云主机,成都云主机,西南云主机,服务器托管,西南服务器托管,四川/成都大带宽,成都机柜租用,四川老牌IDC服务商

Imports System.Collections.Generic

Imports System.ComponentModel

Imports System.Data

Imports System.Drawing

Imports System.Text

Imports System.Windows.Forms

Imports System.Runtime.InteropServices

Public Class Form2

'定义结构体

Private Structure LASTINPUTINFO

Public cbSize As Int32

Public dwTime As Int32

End Structure

'引入系统API

Private Declare Function GetLastInputInfo Lib "user32" (ByVal plii As IntPtr) As Long '重新定义为 IntPtr

'在计时器中,进行相应的计算

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

'获取系统的运行时间

Dim systemUpTime As Integer = Environment.TickCount

Dim LastInputTicks As Integer = 0

Dim IdleTicks As Integer = 0

Dim LastInputInfo As New LASTINPUTINFO()

LastInputInfo.cbSize = Len(LastInputInfo)

Dim thObject2 As Runtime.InteropServices.GCHandle = Runtime.InteropServices.GCHandle.Alloc(LastInputInfo, Runtime.InteropServices.GCHandleType.Pinned)

Dim tpObject2 As IntPtr = thObject2.AddrOfPinnedObject() '取得指向结构的指针

'获取用户上次操作的时间

If GetLastInputInfo(tpObject2) Then

LastInputTicks = CInt(thObject2.Target.dwTime)

'LastInputTicks = CInt(LastInputInfo.dwTime)

'求差,就是系统空闲的时间

IdleTicks = systemUpTime - LastInputTicks

End If

lblSystemUpTime.Text = "系统运行时间:" + Convert.ToString(systemUpTime / 1000) + " 秒"

lblIdleTime.Text = "系统空闲时间:" + Convert.ToString(IdleTicks / 1000) + " 秒"

End Sub

End Class

VB.net如何设置msgbox可以定时自动关闭?

MessageBox里的Show里没有自动关闭的方法,但是你可以自定义一个MessageBox,MessageBox就是一个窗体,你新建一个窗体Form2,添加一个public属性message和一个定时器timer1,timer1的interval设置成你想要的时间,在Form2的Load事件启动timer1,Timer1_Tick事件里关闭窗口Me.Close(),然后在需要显示Messagebox的时候,在主窗口Form1里设置messge属性,然后用show方法弹出窗口就可以了。

Form1程序:(添加了一个Button1)

Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim f2 As Form2 = New Form2

f2.Message = "提示"

f2.ShowDialog()

End Sub

End Class

Form2程序:(添加了一个Label1显示信息和一个Timer1用于计时,Form2可以自定义成你想要的样式,标题,按钮,窗体样式等)

Public Class Form2

'自定义属性 显示提示信息

Public WriteOnly Property Message As String

Set(value As String)

Label1.Text = value

End Set

End Property

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

Me.Close()

End Sub

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Timer1.Interval=3000 '定时3秒关闭窗口

Timer1.Enabled = True

End Sub

End Class

代码已在VS2017测试通过。

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中按需使用。

其他的我也不多说了,这样说已经很详细了,你应该能看懂。

用vb.net编写程序

系统托盘里显示图标的话用NotifyIcon组件,建立一个ContextMenuStrip控件与之关联。关联的位置在NotifyIcon.ContextMenuStrip。关机直接shell 命令列:rundll32.exe user.exe,exitwindows就可以,声音提示用My.Compurer.Audio.Play ("路径"),提示消息用Msgbox函数……通过判断返回值在确定是否关机……手头没有VB.Net……大概思路就是这样,不知道能不能对你有帮助……如果要代码的话,不忙的时候可以给你写


分享标题:vb.net自动关机 vb自动关机的代码
链接地址:http://cqcxhl.com/article/doooedp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP