VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   9285
   ClientLeft      =   240
   ClientTop       =   1935
   ClientWidth     =   6585
   LinkTopic       =   "Form1"
   ScaleHeight     =   9285
   ScaleWidth      =   6585
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'API calls to modify the users admin privelages
Private Declare Function LogonUser Lib "Advapi32" Alias "LogonUserA" (ByVal lpszUsername As String, ByVal lpszDomain As Any, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As Long) As Long
Private Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal hToken As Long) As Long
Private Declare Function RevertToSelf Lib "advapi32.dll" () As Long

'API call to get the current pc name
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

'Constants used by LogonUser
Private Const LOGON32_PROVIDER_DEFAULT As Long = 0&
Private Const LOGON32_PROVIDER_WINNT35 As Long = 1&
Private Const LOGON32_LOGON_INTERACTIVE As Long = 2&
Private Const LOGON32_LOGON_NETWORK As Long = 3&
Private Const LOGON32_LOGON_BATCH As Long = 4&
Private Const LOGON32_LOGON_SERVICE As Long = 5&


Private Sub Form_Load()

    Dim lngReturnCode As Long
    Dim lngTokenHandle As Long
    Dim strServerName As String
    Dim strInterfacesRegKey As String
    Dim intCounter As Long
    Dim dwLen As Long
    Dim strPCName As String
    
    lngReturnCode = RevertToSelf()
      
    CheckPriv
      
    'First three parameters are Account, Domain, Password
    lngReturnCode = LogonUser("DomainAdminGuy", "ADomainName", "AReallyCleverPassword", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, lngTokenHandle)
        
    If lngReturnCode = 0 Then
        MsgBox "Error Logging on Administrator - " & Err.LastDllError
        Exit Sub
    End If

    'Promote current thread to admin user rights
    lngReturnCode = ImpersonateLoggedOnUser(lngTokenHandle)

    If lngReturnCode = 0 Then
        MsgBox "Error Impersonating Administrator - " & Err.LastDllError
        Exit Sub
    End If
    
    'Do work as administrator here
    'Screw around with registry & block users local rights for example

    'return to normal rights
    lngReturnCode = RevertToSelf()

     If lngReturnCode = 0 Then
        MsgBox "Error Reverting to Normal Account - " & Err.LastDllError
        Exit Sub
    End If
    
    Unload Me
    Set Form1 = Nothing

End Sub
