用VB编写自动关机
找一编程高手帮写一脚本,当鼠标或键盘60分无反应时,关闲计算机,我晕啊别说的这么复杂啊直接上答案啊...
找一编程高手帮写一脚本,当鼠标或键盘60分无反应时,关闲计算机,
我晕啊别说的这么复杂啊直接上答案啊 展开
我晕啊别说的这么复杂啊直接上答案啊 展开
5个回答
展开全部
在窗体内加入控件Timer1,然后复制下面代码,编译后运行即可:
Option Explicit
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Dim lii As LASTINPUTINFO
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
lii.cbSize = Len(lii)
End Sub
Private Sub Timer1_Timer()
If GetLastInputInfo(lii) Then
If (GetTickCount - lii.dwTime) / 60000 >= 1 Then '60分钟后
Shell "shutdown -s -t 0" '关机
End If
End If
End Sub
Option Explicit
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Dim lii As LASTINPUTINFO
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
lii.cbSize = Len(lii)
End Sub
Private Sub Timer1_Timer()
If GetLastInputInfo(lii) Then
If (GetTickCount - lii.dwTime) / 60000 >= 1 Then '60分钟后
Shell "shutdown -s -t 0" '关机
End If
End If
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一群神经病。代码写在Timer里,一个计数变量i,首先,利用GetCursorPos确定指针位置,位置改变i清0,否则加一,GetKeyboardState判断按键,处理同上,当i*timer.interval=60000'一分钟,就调用OpenProcessToken获得令牌,AdjustTokenPrivilege提升关机权限,底位19,高位0,数量1属性2,ExitWindowsEx关机
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private CIdle As LASTINPUTINFO
Private LastTime As Long
Private StopTime As Long
Private PIdle As Long
Private Sub Timer1_Timer()
CIdle.cbSize = Len(CIdle)
GetLastInputInfo CIdle
If CIdle.dwTime <> PIdle Then
PIdle = CIdle.dwTime
StopTime = GetTickCount
LastTime = 0
End If
LastTime = LastTime + Timer1.Interval
If LastTime >= 3000 Then
Shell "shutdown /s /t 3"
MsgBox "3秒后自动关机"
End If
End Sub
把以上内容写到代码里
需要一个timer控件,interval不为0就可以了
按要求修改这里的代码
If LastTime >= 3000 Then '这里的数字是毫秒数,1000毫秒=1秒,按你的要求应该设成60000
Shell "shutdown /s /t 3" '这里是执行的命令,为3秒钟后关机,可以把3改成零,意思就是到时候直接关机,不再延迟
MsgBox "3秒后自动关机" '这里是提示框,不用的话可以删掉
End If
cbSize As Long
dwTime As Long
End Type
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private CIdle As LASTINPUTINFO
Private LastTime As Long
Private StopTime As Long
Private PIdle As Long
Private Sub Timer1_Timer()
CIdle.cbSize = Len(CIdle)
GetLastInputInfo CIdle
If CIdle.dwTime <> PIdle Then
PIdle = CIdle.dwTime
StopTime = GetTickCount
LastTime = 0
End If
LastTime = LastTime + Timer1.Interval
If LastTime >= 3000 Then
Shell "shutdown /s /t 3"
MsgBox "3秒后自动关机"
End If
End Sub
把以上内容写到代码里
需要一个timer控件,interval不为0就可以了
按要求修改这里的代码
If LastTime >= 3000 Then '这里的数字是毫秒数,1000毫秒=1秒,按你的要求应该设成60000
Shell "shutdown /s /t 3" '这里是执行的命令,为3秒钟后关机,可以把3改成零,意思就是到时候直接关机,不再延迟
MsgBox "3秒后自动关机" '这里是提示框,不用的话可以删掉
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
简单啊, 加一个timer 直接复制下面的..
Dim i As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Timer1.Enabled = False
i = 0
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Me.BorderStyle = 0
Me.WindowState = 2
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
i = i + 1
If i >= 3600 Then
Shell "shutdown -s -t 0", 0
End If
End Sub
Dim i As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Timer1.Enabled = False
i = 0
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Me.BorderStyle = 0
Me.WindowState = 2
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Timer1.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
i = i + 1
If i >= 3600 Then
Shell "shutdown -s -t 0", 0
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VBS编写这种脚本不好,需要一直循环,占用大量系统资源
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询