Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UserName from Registry Converting from VB6

Status
Not open for further replies.

UncleCake

Technical User
Feb 4, 2002
355
US
Hi, I am just now starting to program with VB.Net after using VB6 still for the past several years. One of the programs (Class) I am converting over gets the UserName from the registry. I have found the
Code:
  System.Environment.UserName

but I am getting a security warning when I am testing it on my computer. I currently also have a separate function for Win 2000. Is this needed for .Net? I have searched the net for a lot, but I couldn't find anything concrete on the best way to read the user name.
 
UncleCake,

Try the following code block.

Code:
Imports System
Imports System.Security

Public Module WindowUser
   Sub Main()
      Console.WriteLine("Current username: " & [b][COLOR=red]Principal.WindowsIdentity.GetCurrent.Name)[/color][/b]
   End Sub
End Module

Hope it helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top