Results 1 to 7 of 7

Thread: windows reboot [resolved]

  1. #1

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090

    windows reboot [resolved]

    How do you make VB reboot windows?
    while you're answering this, how do you make windows shutdown and how do you make it log out?
    Last edited by Acidic; Dec 1st, 2003 at 03:46 PM.
    Have I helped you? Please Rate my posts.

  2. #2
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    shutdown or reboot:

    VB Code:
    1. ' Shutdown Flags
    2. Const EWX_LOGOFF = 0
    3. Const EWX_SHUTDOWN = 1
    4. Const EWX_REBOOT = 2
    5. Const EWX_FORCE = 4
    6. Const SE_PRIVILEGE_ENABLED = &H2
    7. Const TokenPrivileges = 3
    8. Const TOKEN_ASSIGN_PRIMARY = &H1
    9. Const TOKEN_DUPLICATE = &H2
    10. Const TOKEN_IMPERSONATE = &H4
    11. Const TOKEN_QUERY = &H8
    12. Const TOKEN_QUERY_SOURCE = &H10
    13. Const TOKEN_ADJUST_PRIVILEGES = &H20
    14. Const TOKEN_ADJUST_GROUPS = &H40
    15. Const TOKEN_ADJUST_DEFAULT = &H80
    16. Const SE_SHUTDOWN_NAME = "SeShutdownPrivilege"
    17. Const ANYSIZE_ARRAY = 1
    18. Private Type LARGE_INTEGER
    19.     lowpart As Long
    20.     highpart As Long
    21. End Type
    22. Private Type Luid
    23.     lowpart As Long
    24.     highpart As Long
    25. End Type
    26. Private Type LUID_AND_ATTRIBUTES
    27.     'pLuid As Luid
    28.     pLuid As LARGE_INTEGER
    29.     Attributes As Long
    30. End Type
    31. Private Type TOKEN_PRIVILEGES
    32.     PrivilegeCount As Long
    33.     Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
    34. End Type
    35. Private Declare Function InitiateSystemShutdown Lib "advapi32.dll" Alias "InitiateSystemShutdownA" (ByVal lpMachineName As String, ByVal lpMessage As String, ByVal dwTimeout As Long, ByVal bForceAppsClosed As Long, ByVal bRebootAfterShutdown As Long) As Long
    36. Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
    37. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    38. Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LARGE_INTEGER) As Long
    39. Private 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
    40. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    41. Private Declare Function GetLastError Lib "kernel32" () As Long
    42. Public Function InitiateShutdownMachine(ByVal Machine As String, Optional Force As Variant, Optional Restart As Variant, Optional AllowLocalShutdown As Variant, Optional Delay As Variant, Optional Message As Variant) As Boolean
    43.     Dim hProc As Long
    44.     Dim OldTokenStuff As TOKEN_PRIVILEGES
    45.     Dim OldTokenStuffLen As Long
    46.     Dim NewTokenStuff As TOKEN_PRIVILEGES
    47.     Dim NewTokenStuffLen As Long
    48.     Dim pSize As Long
    49.     If IsMissing(Force) Then Force = False
    50.     If IsMissing(Restart) Then Restart = True
    51.     If IsMissing(AllowLocalShutdown) Then AllowLocalShutdown = False
    52.     If IsMissing(Delay) Then Delay = 0
    53.     If IsMissing(Message) Then Message = ""
    54.     'Make sure the Machine-name doesn't start with '\\'
    55.     If InStr(Machine, "\\") = 1 Then
    56.         Machine = Right(Machine, Len(Machine) - 2)
    57.     End If
    58.     'check if it's the local machine that's going to be shutdown
    59.     If (LCase(GetMyMachineName) = LCase(Machine)) Then
    60.         'may we shut this computer down?
    61.         If AllowLocalShutdown = False Then Exit Function
    62.         'open access token
    63.         If OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, hProc) = 0 Then
    64.             MsgBox "OpenProcessToken Error: " & GetLastError()
    65.             Exit Function
    66.         End If
    67.         'retrieve the locally unique identifier to represent the Shutdown-privilege name
    68.         If LookupPrivilegeValue(vbNullString, SE_SHUTDOWN_NAME, OldTokenStuff.Privileges(0).pLuid) = 0 Then
    69.             MsgBox "LookupPrivilegeValue Error: " & GetLastError()
    70.             Exit Function
    71.         End If
    72.         NewTokenStuff = OldTokenStuff
    73.         NewTokenStuff.PrivilegeCount = 1
    74.         NewTokenStuff.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
    75.         NewTokenStuffLen = Len(NewTokenStuff)
    76.         pSize = Len(NewTokenStuff)
    77.         'Enable shutdown-privilege
    78.         If AdjustTokenPrivileges(hProc, False, NewTokenStuff, NewTokenStuffLen, OldTokenStuff, OldTokenStuffLen) = 0 Then
    79.             MsgBox "AdjustTokenPrivileges Error: " & GetLastError()
    80.             Exit Function
    81.         End If
    82.         'initiate the system shutdown
    83.         If InitiateSystemShutdown("\\" & Machine, Message, Delay, Force, Restart) = 0 Then
    84.             Exit Function
    85.         End If
    86.         NewTokenStuff.Privileges(0).Attributes = 0
    87.         'Disable shutdown-privilege
    88.         If AdjustTokenPrivileges(hProc, False, NewTokenStuff, Len(NewTokenStuff), OldTokenStuff, Len(OldTokenStuff)) = 0 Then
    89.             Exit Function
    90.         End If
    91.     Else
    92.         'initiate the system shutdown
    93.         If InitiateSystemShutdown("\\" & Machine, Message, Delay, Force, Restart) = 0 Then
    94.             Exit Function
    95.         End If
    96.     End If
    97.     InitiateShutdownMachine = True
    98. End Function
    99. Function GetMyMachineName() As String
    100.     Dim sLen As Long
    101.     'create a buffer
    102.     GetMyMachineName = Space(100)
    103.     sLen = 100
    104.     'retrieve the computer name
    105.     If GetComputerName(GetMyMachineName, sLen) Then
    106.         GetMyMachineName = Left(GetMyMachineName, sLen)
    107.     End If
    108. End Function
    109. Private Sub Form_Load()
    110.     'KPD-Team 2000
    111.     'URL: [url]http://www.allapi.net/[/url]
    112.     'E-Mail: [email][email protected][/email]
    113.     InitiateShutdownMachine GetMyMachineName, True, True, True, 60, "You initiated a system shutdown..."
    114. End Sub
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    Last edited by adzzzz; Dec 1st, 2003 at 03:42 PM.

  4. #4

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    wow, much longer than I thought, but what the heck. Thx.
    Have I helped you? Please Rate my posts.

  5. #5
    Addicted Member Para80d's Avatar
    Join Date
    Oct 2003
    Location
    Denton, TX
    Posts
    160
    what are you making? earlier weren't you asking how to disable the ctrl alt del keys? some kind of trojan of somesort? need some cd rom ejector code?
    C++/VB6&.NET/QBasic/HTML/PHP/MySQL/SQLServer2k

    I'm the guy your little brother looks a lot alike. Tell your mom i said thanks.

    naked in vegas

  6. #6
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506

    LOL



    VB Code:
    1. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
    2.   (ByVal lpstrCommand As String, _
    3.   ByVal pstrReturnString As String, _
    4.   ByVal uReturnLength As Long, _
    5.   ByVal wndCallback As Long) As Long
    6.  
    7. Private Sub Form_Load()
    8.   Call mciSendString("Set CDAudio Door Open", 0, 0, 0)
    9. End Sub

    -adehh

  7. #7
    Addicted Member Para80d's Avatar
    Join Date
    Oct 2003
    Location
    Denton, TX
    Posts
    160
    I feel like an ass. that wasn't you acidic.

    sorry.
    C++/VB6&.NET/QBasic/HTML/PHP/MySQL/SQLServer2k

    I'm the guy your little brother looks a lot alike. Tell your mom i said thanks.

    naked in vegas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width