I am trying to retrieve the username from the registry which unless there is a better one I used HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name the problem is I can't figure out how to deal with the spaces I tried retrieving other keys without the spaces and they are just fine. Is there a String function or something that I can put in to deal with the spaces or is there a better registry key for the user currently logged into the system
Heres the code I got.
Dim regKey As RegistryKey = Registry.CurrentUser
regKey = regKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer", False)
Dim strUsername As String = regKey.GetValue("Logon User Name", "Unknown User").ToString

Registry Keys with spaces
Mitch Walker - MSFT
My.User.Name
It returns the Name of the currently logged on user
&#59;lkj&#59;lk
fscarpa58
What error are you getting or problem are you having ...I tested your code "AS IS" on my machine and the messagebox showed my name
Dim
regKey As RegistryKey = Registry.CurrentUser regKey = regKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer", False) Dim strUsername As String = regKey.GetValue("Logon User Name", "Unknown User").ToString MessageBox.Show(strUsername)WAG: make sure your application is setup as a full trust app
crash33
well, it is not an issue with spaces in the key name...because like I said...it works for me...have you opened regedit and checked to make sure you have a value in the key
Another option you may want to look into:
System.Security.Principal.WindowsIdentity.GetCurrent().Name
nelpasa
I must admit that I haven't worked with SQL projects, but can't you use the T-SQL command SYSTEM_USER
Best regards,
Johan Stenberg
Socrates Kapetaneas
ClydeCoulter
Wayne Sepega