Imports System.Data Imports System.Data.SqlClient Imports System.Security.Principal Imports System Public Class Form1 Private m_User As String Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim logonToken As IntPtr = LogonUser() m_User = GetUserName(logonToken) 'Now you can use the m_User in your app for reporting/doing stuff with the current user that is 'logged into with Windows Authentication End Sub Private Function LogonUser() As IntPtr Dim accountToken As IntPtr = WindowsIdentity.GetCurrent().Token Return accountToken End Function Function GetUserName(ByVal logonToken As IntPtr) As String Dim windowsIdentity As New WindowsIdentity(logonToken) Dim parts() As String = Split(windowsIdentity.Name, "\") Dim username As String = parts(1) Return username End Function
As an alternative approach in addition to the suggestions already made, have you thought about returning the user account from the Windows Authentication (WindowsIdentity)?
I use this in ALL of my ArcGIS applications because it's great to be able to throw around that user credential in many different components (for db logon, CrystalReporting, etc...). Anyway, below is a bit of code sampe that you might be able to use.Imports System.Data Imports System.Data.SqlClient Imports System.Security.Principal Imports System Public Class Form1 Private m_User As String Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim logonToken As IntPtr = LogonUser() m_User = GetUserName(logonToken) 'Now you can use the m_User in your app for reporting/doing stuff with the current user that is 'logged into with Windows Authentication End Sub Private Function LogonUser() As IntPtr Dim accountToken As IntPtr = WindowsIdentity.GetCurrent().Token Return accountToken End Function Function GetUserName(ByVal logonToken As IntPtr) As String Dim windowsIdentity As New WindowsIdentity(logonToken) Dim parts() As String = Split(windowsIdentity.Name, "\") Dim username As String = parts(1) Return username End Function