谢谢!俺需要一个定关机代码,可俺不会,能帮帮吗,再次感谢谢各位老大!

解决方案 »

  1.   

    Option Explicit
    Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPublic 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 = 1Type LUID
    lowpart As Long
    highpart As Long
    End TypeType LUID_AND_ATTRIBUTES
    pLuid As LUID
    Attributes As Long
    End TypeType TOKEN_PRIVILEGES
    PrivilegeCount As Long
    Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
    End TypeDeclare 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'这个函数就是用于NT关机中使用的
    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 LonghdlProcessHandle = GetCurrentProcess()
    OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _
    TOKEN_QUERY), hdlTokenHandleLookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
    tkp.PrivilegeCount = 1
    tkp.Privileges(0).pLuid = tmpLuid
    tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLEDAdjustTokenPrivileges hdlTokenHandle, False, tkp, _
    Len(tkpNewButIgnored), tkpNewButIgnored, _
    lBufferNeeded
    End Sub加个TIMER控件不就OK了
      

  2.   

    在 baidu 搜一下会有好多的!帮你up
      

  3.   

    如何关闭/重新启动计算机?  16位Windows用ExitWindows() API函数,而32位Windows则用ExitWindowsEx().32位版本比16位版本多了更多的控制及选项,包括注销及关机。 Declare Function ExitWindows Lib "user" (ByVal uFlags As Long, ByVal _ 
    dwReserved As integer) As integer 
    Const EW_REBOOTSYSTEM = &H43 
    Const EW_RESTARTWINDOWS = &H42 Sub Command1_Click() Dim iAns As Integer 
    Dim rVal As Integer 
    Dim iButtonType as Integer iButtonType = 4 + 32 ' vbYesNo + vbQuestion ' Ask if the user is sure they want to exit. 
    iAns = MsgBox("Are you sure you want to exit windows?", iButtonType, _ 
    "Exit Windows") 
    If iAns = 6 Then ' Yes pressed 
    ' Call the exit function to Reboot. 
    rVal = ExitWindows(EW_REBOOTSYSTEM, 0) 
    End If End Sub ***** 32位的例子 ***** 
    In a project with 1 commandbutton, place the following code: 
    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 Sub Command1_Click() Dim iAns As Integer 
    Dim rVal As Long ' Ask if the user is sure they want to exit. 
    iAns = MsgBox("Are you sure you want to exit windows?", vbQuestion Or _ 
    vbYesNo, "Exit Windows") 
    If iAns = vbYes Then 
    rVal = ExitWindowsEx(EWX_SHUTDOWN, 0&) 
    End If End Sub 
      

  4.   

    定时关机倒是听说过,至于这个定时开机呢,呵呵,好像通过程序来实现的还没有见识过,试想一下,关机的时候连操作系统都没有运行,你的程序难道还能在COM下面运行吗?
      

  5.   

    就是我想也是,只能注销了或者是关机要是开机没有听过,不过你可以用一种特别的ATX电源和长城网络还原大师(还有其他的我只知道这个了)它可以定时开关机。
      

  6.   

    Private Sub Form_Load()
    Shell "Command.com /C shutdown -s -a"
    End SubNT 管用的,简单吧,你自己做个时钟在里边加上
    Shell "Command.com /C shutdown -s -a"就行了