|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: |
Private Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal hToken As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _
ByRef TokenHandle As Long) As Boolean
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Boolean, ByVal dwAppProcessId As Long) As Long
Private Const READ_CONTROL As Long = &H20000
Private Const STANDARD_RIGHTS_ALL As Long = &H1F0000
Private Const STANDARD_RIGHTS_EXECUTE As Long = (READ_CONTROL)
Private Const STANDARD_RIGHTS_READ As Long = (READ_CONTROL)
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const STANDARD_RIGHTS_WRITE As Long = (READ_CONTROL)
Private Const TOKEN_ASSIGN_PRIMARY As Long = &H1
Private Const TOKEN_DUPLICATE As Long = &H2
Private Const TOKEN_IMPERSONATE As Long = &H4
Private Const TOKEN_QUERY As Long = &H8
Private Const TOKEN_QUERY_SOURCE As Long = &H10
Private Const TOKEN_ADJUST_PRIVILEGES As Long = &H20
Private Const TOKEN_ADJUST_GROUPS As Long = &H40
Private Const TOKEN_ADJUST_DEFAULT As Long = &H80
Private Const TOKEN_ALL_ACCESS As Long = TOKEN_ASSIGN_PRIMARY _
+ TOKEN_DUPLICATE + TOKEN_IMPERSONATE + TOKEN_QUERY _
+ TOKEN_QUERY_SOURCE + TOKEN_ADJUST_PRIVILEGES _
+ TOKEN_ADJUST_GROUPS + TOKEN_ADJUST_DEFAULT
Private Const TOKEN_READ As Long = (STANDARD_RIGHTS_READ Or TOKEN_QUERY)
Private Const TOKEN_WRITE As Long = (STANDARD_RIGHTS_WRITE Or TOKEN_ADJUST_PRIVILEGES Or _
TOKEN_ADJUST_GROUPS Or TOKEN_ADJUST_DEFAULT)
Private Const TOKEN_EXECUTE As Long = (STANDARD_RIGHTS_EXECUTE)
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
Function main(ByVal agrs() As String) As Integer
Dim ret As Integer = 0
Dim lToken As Long = GetTokenOfLoggedOnUser()
Console.WriteLine("The lToken is " + CStr(lToken))
If lToken = -1 Then
Return 99
End If
ImpersonateLoggedOnUser(lToken)
Dim cmdLine As String = Environment.CommandLine.Substring(Environment.GetCommandLineArgs(0).Length + 1)
Shell(cmdLine)
Return ret
End Function
Function ExplorerPID() As Long
Dim ret As Long = -1
Dim UObj, colComputer, objComputer As Object
Dim Task As String
Try
UObj = GetObject("winmgmts:" _
+ "{impersonationLevel=impersonate}!\\.\root\cimv2")
colComputer = UObj.ExecQuery _
("Select * from Win32_Process")
Task = "None"
For Each objComputer In colComputer
Task = objComputer.Name
If Task.ToLower.Contains("explorer") Then
ret = objComputer.ProcessID
End If
Next
Catch ex As Exception
ret = -1
End Try
Return ret
End Function
Function GetTokenOfLoggedOnUser() As Long
Dim epid As Long = ExplorerPID()
Dim hProcess As Long = OpenProcess(PROCESS_ALL_ACCESS, True, epid)
Dim hToken As Long = 0
Dim optResult As Boolean = OpenProcessToken(hProcess, TOKEN_EXECUTE Or TOKEN_READ _
Or TOKEN_QUERY Or TOKEN_ASSIGN_PRIMARY Or TOKEN_QUERY_SOURCE Or TOKEN_WRITE Or TOKEN_DUPLICATE, _
hToken)
If hToken < 1 Or Not optResult Then
Return -1
End If
Return hToken
End Function
|
Advertisement
| Hall of Fame |