Domain Name

  • Thread starter Thread starter Stephen Costanzo
  • Start date Start date
S

Stephen Costanzo

When I log onto my workstation, I select my system domain (KRUSTY -- can you tell we have simpson fans as networking??) and my user name, so when I look at the CTRL+ALT+DEL screen it is KRUSTY\scostanz. However when I do
sTemp = Environment.UserDomainName & "\" & Environment.UserName
sTemp is = "SCOSTANZO-XP\scostanz" which is my computer name and my user name. Is there another namespace I should be hitting? I remember that there was an API as well in VB 6.

Thanks in advance.
 
One method would be to use:
Environment.GetEnvironmentVariable("USERDOMAIN") & "\" &
Environment.UserName

AFAIK, this will only work on NT based systems, and not 95/98/ME.

When I log onto my workstation, I select my system domain (KRUSTY -- can you
tell we have simpson fans as networking??) and my user name, so when I look
at the CTRL+ALT+DEL screen it is KRUSTY\scostanz. However when I do
sTemp = Environment.UserDomainName & "\" & Environment.UserName
sTemp is = "SCOSTANZO-XP\scostanz" which is my computer name and my user
name. Is there another namespace I should be hitting? I remember that there
was an API as well in VB 6.
 
Thanks, now the big question, why? I mean one would think that the
environment variable of UserDomain would also point to the UserDomainName
value.

Also, is there a place in the help file which lists those values so I can
see what else I can pick out of it?

Thanks Jim
 
Hi Stephen,

I can not reproduce the problem. I tested on Windows XP+sp1, .NET framework
1.1,VS.NET 2003
Module Module1
Sub Main()
Dim sTemp As String
sTemp = Environment.UserDomainName & "\" & Environment.UserName
Console.WriteLine(sTemp)
sTemp = Environment.GetEnvironmentVariable("USERDOMAIN") & "\" &
Environment.UserName()
Console.WriteLine(sTemp)
End Sub
End Module

I will get the same result in the two line output
above.(<DOMAIN>\<USERNAME>)
Which OS are your using?

As the msdn said,

Environment.UserDomainName Property

Requirements
Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000,
Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemenvironmentclassuserdomainnametopic.asp

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Peter, I was able to reproduce Stephen's issue on Windows 2000 Server Sp4
with Framework 1.1, VS Net 2003, that's why I suggested the workaround.

TextBox1.Text = Environment.UserDomainName & "\" & Environment.UserName
TextBox1.Text += vbcrlf & Environment.GetEnvironmentVariable("USERDOMAIN") &
"\" & Environment.UserName
Returned

COMPUTERNAME\jim
DOMAINNAME\jim

The server is a member of an Active Directory domain and I am logged in as a
AD user.

Stephen, GetEnvironmentVariable returns a the contents of the environment
variables that are set from My Computer | Properties | Advanced |
Environment Variables plus some that are set automaticaly like USERDOMAIN.
Open a Command Prompt and type SET to see the full list.
 
Framework: NetFramework 1.1
Workstation: XP SP 1
Server: Windows 2000

I do not know if we have AD.
 
Hi Stephen,

Thank you for you report.

After I have done a deeper research, the behavior will occur only if there
is a same local account with the domain account. i.e. when you have a
domain account domain\user1 and a local account user1.
When you logon to the domain with the domain account domain\user1, the
problem will persists.

I have reported the problem to our product team, but I can not guarantee if
or when it will be fixed.

Now you can follow the Jim's workaround
or
Environment.ExpandEnvironmentVariables("%USERDOMAIN%")

If you have concern on this issue,please post here.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks for your research Peter!

I can confirm that I did have two accounts using the same name in the domain
and on the workstation. I renamed the local account and
Environment.UserDomainName now returns the correct result.
 
I will try that as well Jim as we, as a general practice, keep a local
account on the machine (if its a laptop) with the same credentials, i.e.
Username/password
 
Hi Stephen,

I look forward to hearing from you after you have a test.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top