klaro ... hier mal den code :
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Diagnostics" %>
<%@ import Namespace="System.Runtime.InteropServices" %>
<%@ import Namespace="System.Security.Principal" %>
<%@ Page Language="VB" Debug="true"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="css/format.css" rel="styleSheet" type="text/css" />
<title>ASP.NET Testseite</title>
<!-- VB.Net für die dynamischen Funktionen, hat nix mit JS zu tun -->
<script language="vb" runat="server">
'##############################################################################
'##############################################################################
'
' unmanaged CODE
'
'**********************
#Region "API Structures / Enums"
Const GENERIC_ALL As Int32 = &H10000000
Enum TOKEN_TYPE As Integer
TokenPrimary = 1
TokenImpersonation = 2
End Enum
Enum SECURITY_IMPERSONATION_LEVEL As Integer
SecurityAnonymous = 0
SecurityIdentification = 1
SecurityImpersonation = 2
SecurityDelegation = 3
End Enum
<StructLayout(LayoutKind.Sequential)> _
Structure STARTUPINFO
Dim cb As Int32
Dim lpReserved As String
Dim lpDesktop As String
Dim lpTitle As String
Dim dwX As Int32
Dim dwY As Int32
Dim dwXSize As Int32
Dim dwYSize As Int32
Dim dwXCountChars As Int32
Dim dwYCountChars As Int32
Dim dwFillAttribute As Int32
Dim dwFlags As Int32
Dim wShowWindow As Int16
Dim cbReserved2 As Int16
Dim lpReserved2 As IntPtr
Dim hStdInput As IntPtr
Dim hStdOutput As IntPtr
Dim hStdError As IntPtr
End Structure
<StructLayout(LayoutKind.Sequential)> _
Structure PROCESS_INFORMATION
Dim hProcess As IntPtr
Dim hThread As IntPtr
Dim dwProcessId As Int32
Dim dwThreadId As Int32
End Structure
<StructLayout(LayoutKind.Sequential)> _
Structure SECURITY_ATTRIBUTES
Dim nLength As Int32
Dim lpSecurityDescriptor As IntPtr
Dim bInheritHandle As Boolean
End Structure
'-----------------NEU------------------
<StructLayout(LayoutKind.Sequential)> _
Structure PROFILEINFO
Dim dwSize As Integer
Dim dwFlags As Integer
Dim lpUserName As String
Dim lpProfilePath As String
Dim lpDefaultPath As String
Dim lpServerName As String
Dim lpPolicyPath As String
Dim hProfile As IntPtr
End Structure
'------------------------------
#End Region
'**********************
#Region "API Functions"
' CloseHandle Funkion
<DllImport("kernel32.dll", EntryPoint:="CloseHandle", SetLastError:=True, _
CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function CloseHandle(ByVal hObject As IntPtr) As Boolean
End Function
'DuplicateTokenEx Funktion
<DllImport("advapi32.dll", EntryPoint:="DuplicateTokenEx", SetLastError:=True, _
CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function DuplicateTokenEx( _
ByVal hExistingToken As IntPtr, _
ByVal dwDesiredAccess As Int32, _
ByRef lpTokenAttributes As SECURITY_ATTRIBUTES, _
ByVal ImpersonationLevel As SECURITY_IMPERSONATION_LEVEL, _
ByVal TokenType As TOKEN_TYPE, _
ByRef phNewToken As IntPtr) As Boolean
End Function
<DllImport("userenv.dll", EntryPoint:="LoadUserProfileA", SetLastError:=True, _
CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function LoadUserProfileA(ByVal hToken As Long, _
ByVal lpProfileInfo As PROFILEINFO) As Boolean
End Function
#End Region
'**********************
'*************************************************************************************************
Public Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)
Dim Token As New IntPtr(0)
Dim dupToken As New IntPtr(0)
Dim bRet As Boolean = False
Dim sa As New SECURITY_ATTRIBUTES
Dim si As New STARTUPINFO
Dim pi As New PROCESS_INFORMATION
Dim UserProfile As PROFILEINFO
Dim bResult As Boolean
Token = WindowsIdentity.GetCurrent().Token
Identity.Text &= "<BR>" & WindowsIdentity.GetCurrent().Name.ToString()
sa.bInheritHandle = False
sa.nLength = Marshal.SizeOf(sa)
sa.lpSecurityDescriptor = IntPtr.Zero
Token = WindowsIdentity.GetCurrent().Token
bRet = DuplicateTokenEx(Token, GENERIC_ALL, sa, SECURITY_IMPERSONATION_LEVEL.SecurityDelegation, _
TOKEN_TYPE.TokenPrimary, dupToken)
If (bRet = False) Then
Duplicate.Text &= "<BR>DuplicateTokenEx failed with " & Marshal.GetLastWin32Error().ToString()
Else
Duplicate.Text &= "<BR>DuplicateTokenEx SUCCESS"
End If
UserProfile = New PROFILEINFO()
UserProfile.lpUserName = "RSINT\EICKEL_S_ADMIN"
UserProfile.dwSize = Marshal.SizeOf(UserProfile)
bResult = LoadUserProfileA(dupToken, UserProfile)
If Not bResult Then
userPro.Text = "Error loading user profile : " & Marshal.GetLastWin32Error().ToString()
Else : userPro.Text = "The handle to the user profile is : " & UserProfile.hProfile.ToString
End If
bRet = CloseHandle(dupToken)
If (bRet = False) Then
CloseH.Text &= "<BR>CloseHandle of dupToken failed with " & Marshal.GetLastWin32Error().ToString()
Else
CloseH.Text &= "<BR>CloseHandle of dupToken SUCCESS"
End If
'*************************************************************************************************
</script>
</head>
</html>
hoffe du kannst mir helfen
gruß
daytalker