| 2 |
rsolanki |
1 |
VERSION 1.0 CLASS
|
|
|
2 |
BEGIN
|
|
|
3 |
MultiUse = -1 'True
|
|
|
4 |
Persistable = 0 'NotPersistable
|
|
|
5 |
DataBindingBehavior = 0 'vbNone
|
|
|
6 |
DataSourceBehavior = 0 'vbNone
|
|
|
7 |
MTSTransactionMode = 0 'NotAnMTSObject
|
|
|
8 |
END
|
|
|
9 |
Attribute VB_Name = "ImpersonateUser"
|
|
|
10 |
Attribute VB_GlobalNameSpace = False
|
|
|
11 |
Attribute VB_Creatable = True
|
|
|
12 |
Attribute VB_PredeclaredId = False
|
|
|
13 |
Attribute VB_Exposed = True
|
|
|
14 |
'Code for Class Module:
|
|
|
15 |
|
|
|
16 |
Option Explicit
|
|
|
17 |
|
|
|
18 |
Const LOGON32_LOGON_INTERACTIVE = 2
|
|
|
19 |
Const LOGON32_LOGON_NETWORK = 3
|
|
|
20 |
Const LOGON32_LOGON_BATCH = 4
|
|
|
21 |
Const LOGON32_LOGON_SERVICE = 5
|
|
|
22 |
|
|
|
23 |
Const LOGON32_PROVIDER_DEFAULT = 0
|
|
|
24 |
Const LOGON32_PROVIDER_WINNT35 = 1
|
|
|
25 |
Const LOGON32_PROVIDER_WINNT40 = 2
|
|
|
26 |
Const LOGON32_PROVIDER_WINNT50 = 3
|
|
|
27 |
''''''''''''''''''''''''''''''''''''''''''''
|
|
|
28 |
Const INTERNET_OPTION_END_BROWSER_SESSION = 42
|
|
|
29 |
|
|
|
30 |
Private Declare Function InternetSetOption Lib "wininet.dll" Alias "InternetSetOptionA" _
|
|
|
31 |
(ByVal hInternet As Long, ByVal lOption As Long, ByRef sBuffer As Any, ByVal lBufferLength As Long) As Integer
|
|
|
32 |
|
|
|
33 |
Public Function flushCredentials() As Integer
|
|
|
34 |
Dim h As Integer
|
|
|
35 |
h = InternetSetOption(0, INTERNET_OPTION_END_BROWSER_SESSION, 0, 0)
|
|
|
36 |
flushCredentials = h
|
|
|
37 |
End Function
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
Public Function Logon(ByVal strAdminUser As String, ByVal strAdminPassword As String, _
|
|
|
41 |
ByVal strAdminDomain As String) As Long
|
|
|
42 |
Dim lngTokenHandle, lngLogonType, lngLogonProvider As Long
|
|
|
43 |
Dim blnResult As Boolean
|
|
|
44 |
|
|
|
45 |
lngLogonType = LOGON32_LOGON_INTERACTIVE
|
|
|
46 |
lngLogonProvider = LOGON32_PROVIDER_DEFAULT
|
|
|
47 |
|
|
|
48 |
blnResult = RevertToSelf()
|
|
|
49 |
|
|
|
50 |
blnResult = LogonUser(strAdminUser, strAdminDomain, strAdminPassword, _
|
|
|
51 |
lngLogonType, lngLogonProvider, _
|
|
|
52 |
lngTokenHandle)
|
|
|
53 |
Logon = Err.LastDllError
|
|
|
54 |
|
|
|
55 |
'blnResult = ImpersonateLoggedOnUser(lngTokenHandle)
|
|
|
56 |
'Logon = blnResult
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
End Function
|
|
|
61 |
|
|
|
62 |
Public Sub Logoff()
|
|
|
63 |
Dim blnResult As Boolean
|
|
|
64 |
|
|
|
65 |
blnResult = RevertToSelf()
|
|
|
66 |
End Sub
|
|
|
67 |
|
|
|
68 |
Public Function AuthenticateUser(ByVal strUser As String, _
|
|
|
69 |
ByVal strPassword As String, _
|
|
|
70 |
ByVal strDomain As String) As Long
|
|
|
71 |
|
|
|
72 |
AuthenticateUser = Logon(strUser, strPassword, strDomain)
|
|
|
73 |
|
|
|
74 |
Call Logoff
|
|
|
75 |
|
|
|
76 |
End Function
|