Environ("username")

R

riso

Hi folks,

An IT administrator 'created' 10 PC with windows XP with 2 users,
namely "administrator" and "weakuser", with an imagedisc. Later
administrator logged in to every computer and changed the account name
of the user from 'weakuser' to the real name of a person who uses that
computer (e.g. Smith, Shepard, etc).

The interesting thing is that Environ("username") on every PC returns
'weakuser', not the real name. Is it possible to find the login (Smith
or Shepard or etc.) in VBA?

thanks
 
J

Jim Thomlinson

Give the windows API a whirl...

Private Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, ByRef nSize As Long) As Long

Function GetUser() As String
Dim Ret As Long
Dim UserName As String
Dim Buffer As String * 25
Ret = GetUserName(Buffer, 25)
UserName = Left$(Buffer, InStr(Buffer, Chr(0)) - 1)
GetUser = UserName
End Function

Sub test()
MsgBox GetUser
End Sub
 
R

riso

Hi,

I am sorry, Test() shows the same 'weakuser' as Environ("username").

thanks for your effort.

other solution?

riso
 
B

Bob Phillips

Have you logged off of those machines and logged back on since?

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
R

riso

Yes.

Environ("username") returns 'weakuser' for weeks. Users' computers are
turned off daily.

thanks
 
N

NickHK

Sounds like the Accounts' usernames were not changed "correctly" somehow.
Works for me with just log-off/on; correctly username is returned.
Are you sure the usernames were actually changed ?

NickHK
 
R

riso

I forgot .....

The same behaviour you can observe if you create an account as a XP
windows administrator with the name 'User1' and later rename that
account to User2 (via standart tools of XP windows administrator).

Environ("username") always returns User1 not User2.

I have seen a discusion similar to this one about .net
System.Environment.UserName (http://www.mcse.ms/message1250010.html).

The solution was to check the other properties of AD e.g. displayname,
CN, SN, givenName, userPrincipalName (sAMAccountName is the attribute
in AD that is the "username" used for logins
and such)

But I do not know how to utilise that solution in excel VBA.

riso
 
R

riso

Thank for your answer.

I have tried it myself. I logged on as XP windows administrator and
changed account name from weakuser to testuser.

In the login screen (that one with pictures and account names) is
written "administrator" and "testuser". When logged as testuser I have
started excel and try msgbox Environ("username"). It shows "weakuser".

Moreover. I have thought that it is related to usage of imagedisk. I
have created completely new account "user1", logged in, runned excel
and msgbox. It showed user1. logged off, logged in as administrator,
changed account name to user2, logged off, restarted computer, logged
in as user2 (it was showed in the login screen), runned excel and
msgbox. It shows user1. Still original account name.

Maybe it is related to corrupted XP windows, but I doubt.
 
R

riso

I have checked also user directories for these accounts.

C:\Documents and Settings\admin .... for user with administrator right
C:\Documents and Settings\weekuser .... for user Smith (his login name
is Smith)
C:\Documents and Settings\user1 ..... for user User2


Is something wrong with instalation of XP Windows?

thanks
 
N

NickHK

So you are talking about Active Directory ?

You example ("User1">"User2") give the correct result on W2K, local account.

Could not locate the server in the link you provided, so no idea that
context.

NickHK
 
R

riso

That's crazy, that page was available just yesterday.

try google site:site:mcse.ms/message1250010.html and see cached data.
Here is a direct link.

<http://209.85.129.104/search?q=cache:udSNSErNEMAJ:www.mcse.ms/
message1250010.html+site:mcse.ms/message1250010.html&hl=en&strip=1>

I am not sure if the topic "Wrong Username with
System.Environment.UserName" described as "Wrong Username with
System.Environment.UserName .NET Security." is really related to my
problem with excel VBA environ("username"). But the symptoms are the
same.

riso
 
R

riso

Maybe it is worth to add that system is Windows XP Home Edition SP2
czech version.
Could this problem be related only to the local versions (czech)?


Who knows? Not me. Bill? What about you, Bill?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top