Results 1 to 2 of 2

Thread: What api dll used in XP?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Location
    Philippines
    Posts
    9

    Question What api dll used in XP?

    Hi everybody,
    I am new at this forum. I liek to ask if anyone knows how to programatically shutdowns, reset pc? I am using Windows XP. Also, controlling the audio on /off and its volume. What are the api used to control this functionalities in VB.net or C#?

    den2005

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: What api dll used in XP?

    Welcome to the forums.

    Try this:
    VB Code:
    1. Option Explicit
    2.  
    3.     Private Const EWX_LogOff As Long = 0
    4.     Private Const EWX_SHUTDOWN As Long = 1
    5.     Private Const EWX_REBOOT As Long = 2
    6.     Private Const EWX_FORCE As Long = 4
    7.     Private Const EWX_POWEROFF As Long = 8
    8.  
    9. 'The ExitWindowsEx function either logs off, shuts down, or shuts
    10. 'down and restarts the system.
    11.  
    12. Private Declare Function ExitWindowsEx Lib "user32" _
    13.     (ByVal dwOptions As Long, _
    14.     ByVal dwReserved As Long) As Long
    15.  
    16. 'The GetLastError function returns the calling thread's last-error
    17. 'code value. The last-error code is maintained on a per-thread basis.
    18. 'Multiple threads do not overwrite each other's last-error code.
    19. Private Declare Function GetLastError Lib "kernel32" () As Long
    20.  
    21. Private Const mlngWindows95 = 0
    22. Private Const mlngWindowsNT = 1
    23. Public glngWhichWindows32 As Long
    24. 'The GetVersion function returns the operating system in use.
    25. Private Declare Function GetVersion Lib "kernel32" () As Long
    26.  
    27. Private Type LUID
    28.     UsedPart As Long
    29.     IgnoredForNowHigh32BitPart As Long
    30. End Type
    31.  
    32. Private Type LUID_AND_ATTRIBUTES
    33.     TheLuid As LUID
    34.     Attributes As Long
    35. End Type
    36. Private Type TOKEN_PRIVILEGES
    37.     PrivilegeCount As Long
    38.     TheLuid As LUID
    39.     Attributes As Long
    40. End Type
    41. 'The GetCurrentProcess function returns a pseudohandle for the
    42. 'current process.
    43. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    44. 'The OpenProcessToken function opens the access token associated with
    45. 'a process.
    46. Private Declare Function OpenProcessToken Lib "advapi32" _
    47.     (ByVal ProcessHandle As Long, _
    48.     ByVal DesiredAccess As Long, _
    49.     TokenHandle As Long) As Long
    50. 'The LookupPrivilegeValue function retrieves the locally unique
    51. 'identifier (LUID) used on a specified system to locally represent
    52. 'the specified privilege name.
    53. Private Declare Function LookupPrivilegeValue Lib "advapi32" _
    54.     Alias "LookupPrivilegeValueA" _
    55.     (ByVal lpSystemName As String, _
    56.     ByVal lpName As String, _
    57.     lpLuid As LUID) As Long
    58. 'The AdjustTokenPrivileges function enables or disables privileges
    59. 'in the specified access token. Enabling or disabling privileges
    60. 'in an access token requires TOKEN_ADJUST_PRIVILEGES access.
    61. Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
    62.     (ByVal TokenHandle As Long, _
    63.     ByVal DisableAllPrivileges As Long, _
    64.     NewState As TOKEN_PRIVILEGES, _
    65.     ByVal BufferLength As Long, _
    66.     PreviousState As TOKEN_PRIVILEGES, _
    67.     ReturnLength As Long) As Long
    68.     Private Declare Sub SetLastError Lib "kernel32" _
    69.     (ByVal dwErrCode As Long)
    70. Private Sub AdjustToken()
    71. 'This procedure sets the proper privileges to allow a log off or a
    72. 'shut down to occur under Windows NT.
    73. Const TOKEN_ADJUST_PRIVILEGES = &H20
    74. Const TOKEN_QUERY = &H8
    75. Const SE_PRIVILEGE_ENABLED = &H2
    76. Dim hdlProcessHandle As Long
    77. Dim hdlTokenHandle As Long
    78. Dim tmpLuid As LUID
    79. Dim tkp As TOKEN_PRIVILEGES
    80. Dim tkpNewButIgnored As TOKEN_PRIVILEGES
    81. Dim lBufferNeeded As Long
    82. 'Set the error code of the last thread to zero using the
    83. 'SetLast Error function. Do this so that the GetLastError
    84. 'function does not return a value other than zero for no
    85. 'apparent reason.
    86.     SetLastError 0
    87. 'Use the GetCurrentProcess function to set the hdlProcessHandle
    88. 'variable.
    89.     hdlProcessHandle = GetCurrentProcess()
    90.     If GetLastError <> 0 Then
    91.         systemMessage.AddItem "GetCurrentProcess Error==" & GetLastError
    92.     End If
    93.     OpenProcessToken hdlProcessHandle, _
    94.         (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle
    95.     If GetLastError <> 0 Then
    96.         systemMessage.AddItem "OpenProcessToken Error==" & GetLastError
    97.     End If
    98. 'Get the LUID for shutdown privilege
    99.     LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
    100.     If GetLastError <> 0 Then
    101.         systemMessage.AddItem "LookupPrivilegeValue Error==" & GetLastError
    102.     End If
    103.     tkp.PrivilegeCount = 1    ' One privilege to set
    104.     tkp.TheLuid = tmpLuid
    105.     tkp.Attributes = SE_PRIVILEGE_ENABLED
    106. 'Enable the shutdown privilege in the access token of this process
    107.     AdjustTokenPrivileges hdlTokenHandle, _
    108.     False, _
    109.     tkp, _
    110.     Len(tkpNewButIgnored), _
    111.     tkpNewButIgnored, _
    112.     lBufferNeeded
    113.     If GetLastError <> 0 Then
    114.         systemMessage.AddItem "AdjustTokenPrivileges Error==" & GetLastError
    115.     End If
    116. End Sub
    117. Private Sub cmdLogoff_Click()
    118.     ExitWindowsEx (EWX_LogOff), &HFFFF
    119.     systemMessage.AddItem "ExitWindowsEx's GetLastError " & GetLastError
    120. End Sub
    121. Private Sub cmdForceLogoff_Click()
    122.     ExitWindowsEx (EWX_LogOff Or EWX_FORCE), &HFFFF
    123.     systemMessage.AddItem "ExitWindowsEx's GetLastError " & GetLastError
    124. End Sub
    125. Private Sub cmdShutdown_Click()
    126.     If glngWhichWindows32 = mlngWindowsNT Then
    127.         AdjustToken
    128.         systemMessage.AddItem "Post-AdjustToken GetLastError " & GetLastError
    129.     End If
    130.     ExitWindowsEx (EWX_SHUTDOWN), &HFFFF
    131.     systemMessage.AddItem "ExitWindowsEx's GetLastError " & GetLastError
    132. End Sub
    133. Private Sub cmdForceShutdown_Click()
    134.     If glngWhichWindows32 = mlngWindowsNT Then
    135.         AdjustToken
    136.         systemMessage.AddItem "Post-AdjustToken GetLastError " & GetLastError
    137.     End If
    138.     ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE), &HFFFF
    139.     systemMessage.AddItem "ExitWindowsEx's GetLastError " & GetLastError
    140. End Sub
    141. Private Sub exit_Click()
    142.     Unload Me
    143. End Sub
    144. Private Sub Form_Load()
    145. 'When the project starts, check the operating system used by
    146. 'calling the GetVersion function.
    147. Dim lngVersion As Long
    148.     lngVersion = GetVersion()
    149.     If ((lngVersion And &H80000000) = 0) Then
    150.         glngWhichWindows32 = mlngWindowsNT
    151.         systemType.Text = "Windows NT"
    152.     Else
    153.         glngWhichWindows32 = mlngWindows95
    154.         systemType.Text = "Windows 95"
    155.     End If
    156. End Sub

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