vb自动关机程序

原创 2010年05月26日 14:08:00

Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
Private closeTime As String

Sub AdjustTokenPrivilegesForNT()
   
    Dim hdlProcessHandle As Long
    Dim hdlTokenHandle As Long
    Dim tmpLuid As LUID
    Dim tkp As TOKEN_PRIVILEGES
    Dim tkpNewButIgnored As TOKEN_PRIVILEGES
    Dim lBufferNeeded As Long
   
    hdlProcessHandle = GetCurrentProcess()
    OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _
    TOKEN_QUERY), hdlTokenHandle
   
    LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
    tkp.PrivilegeCount = 1
    tkp.Privileges(0).pLuid = tmpLuid
    tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
   
    AdjustTokenPrivileges hdlTokenHandle, False, tkp, _
    Len(tkpNewButIgnored), tkpNewButIgnored, _
    lBufferNeeded
End Sub

Private Sub Form_Load()
 Dim fso As New FileSystemObject
    Dim ts As TextStream
    Dim txt, iniFilePath As String
    iniFilePath = App.Path & "/" & "system.ini"
     If fso.FileExists(iniFilePath) Then
       Set ts = fso.OpenTextFile(App.Path & "/" & "system.ini")
       closeTime = ts.ReadLine
       ts.Close
       Set ts = Nothing
       If Len(Trim(closeTime)) = 0 Then
            Set ts = fso.CreateTextFile(iniFilePath)
            ts.WriteLine "23:00"
            ts.Close
            Set ts = Nothing
            closeTime = "23:00"
       End If
    Else
       Set ts = fso.CreateTextFile(iniFilePath)
       ts.WriteLine "23:00"
       ts.Close
       closeTime = "23:00"
    End If
    Timer1.Enabled = True
    Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
If Trim(Hour(Now) & ":" & Minute(Now)) = Trim(closeTime) Then
    AdjustTokenPrivilegesForNT '在95/98中调用没作用,但为了和NT兼容,写上无妨
    ExitWindowsEx EWX_SHUTDOWN, 0
End If
End Sub

'模块

Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

'ExitWindowsEx的参数uflags,有四个对应值,分别是:

Public Const EWX_LOGOFF = 0 '退出(注销)
Public Const EWX_SHUTDOWN = 1 '关机
Public Const EWX_REBOOT = 2 '重启动
Public Const EWX_FORCE = 4 '强制关机,即不通知现在活动应用程序让其先自我关闭

Public Const TOKEN_ADJUST_PRIVILEGES = &H20
Public Const TOKEN_QUERY = &H8
Public Const SE_PRIVILEGE_ENABLED = &H2
Public Const ANYSIZE_ARRAY = 1

Type LUID
lowpart As Long
highpart As Long
End Type

Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type

Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type

Declare Function GetCurrentProcess Lib "kernel32" () As Long
Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long

 

VB程序设计入门基础

VB入门基础。
  • 2017年09月11日 21:04

vb搞笑的关机源代码

  • 2008年11月01日 19:19
  • 530B
  • 下载

<em>vb</em> 快速<em>关机</em> 代码

<em>VB</em>.Net<em>程序设计</em>:自动<em>关机程序</em> 立即下载 上传者: 沐NeMo 时间: 2007-07-14 ...<em>vb恶搞</em>代码 立即下载 上传者: x_x_x_x_ 时间: 2014-06-19 综合评分: ...
  • 2018年04月14日 00:00

弹窗式恶搞网页的设计与发布

这个idea是我在去年春节的时候想起来的。原因是之前收到一个qq红包,看起来像真的一样,打开一看,却遭到弹窗的恶搞。弹窗的机制导致我怎么退也退不出去,只能够乖乖看完,或者关机重启。诶,后来转念一想,大...
  • lusongno1
  • lusongno1
  • 2016-02-25 21:50:49
  • 2254

vb自动关机程序

Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long)...
  • goushaoping04
  • goushaoping04
  • 2010-05-26 14:08:00
  • 452

<em>VB</em> windows<em>关机</em>代码

<em>VB</em>.Net<em>程序设计</em>:自动<em>关机程序</em> 立即下载 上传者: 沐NeMo 时间: 2007-07-14 ...<em>VB</em>定时关机代码 <em>VB关机程序</em>--包括注销、重启、关机 <em>vb恶搞</em>代码 立即下载 上...
  • 2018年04月14日 00:00

C语言写的控制台关机小程序

用C语言写的一个关机小程序,通过VC6.0调试运行。
  • rl529014
  • rl529014
  • 2016-01-03 16:36:49
  • 1406

vb 快速关机 代码

  • 2008年09月07日 16:34
  • 294B
  • 下载

VB自动关机源码.rar

  • 2009年10月23日 11:58
  • 1.03MB
  • 下载

vb写的 自动关机程序

  • 2009年11月13日 21:00
  • 63KB
  • 下载
收藏助手
不良信息举报
您举报文章:vb自动关机程序
举报原因:
原因补充:

(最多只允许输入30个字)