ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Environ("username") (https://www.excelbanter.com/excel-programming/384658-environ-username.html)

riso

Environ("username")
 
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


Jim Thomlinson

Environ("username")
 
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
--
HTH...

Jim Thomlinson


"riso" wrote:

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



riso

Environ("username")
 
Hi,

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

thanks for your effort.

other solution?

riso

On Mar 6, 9:17 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
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
--
HTH...

Jim Thomlinson



"riso" wrote:
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- Hide quoted text -


- Show quoted text -




Bob Phillips

Environ("username")
 
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)



"riso" wrote in message
ups.com...
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




riso

Environ("username")
 
Yes.

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

thanks


On Mar 6, 10:22 pm, "Bob Phillips" wrote:
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)

"riso" wrote in message

ups.com...



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- Hide quoted text -


- Show quoted text -




NickHK

Environ("username")
 
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

"riso" wrote in message
oups.com...
Yes.

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

thanks


On Mar 6, 10:22 pm, "Bob Phillips" wrote:
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)

"riso" wrote in message

ups.com...



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- Hide quoted text -


- Show quoted text -






riso

Environ("username")
 
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

On Mar 6, 10:22 pm, "Bob Phillips" wrote:
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)

"riso" wrote in message

ups.com...



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- Hide quoted text -


- Show quoted text -




riso

Environ("username")
 
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.



On Mar 8, 9:23 am, "NickHK" wrote:
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

"riso" wrote in message

oups.com...



Yes.


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


thanks


On Mar 6, 10:22 pm, "Bob Phillips" wrote:
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)

"riso" wrote in message


oups.com...


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- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -




riso

Environ("username")
 
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



On Mar 8, 9:45 am, "riso" wrote:
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.

On Mar 8, 9:23 am, "NickHK" wrote:



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


"riso" wrote in message


roups.com...


Yes.


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


thanks


On Mar 6, 10:22 pm, "Bob Phillips" wrote:
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)


"riso" wrote in message


oups.com...


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- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -




NickHK

Environ("username")
 
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

"riso" wrote in message
s.com...
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

On Mar 6, 10:22 pm, "Bob Phillips" wrote:
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)

"riso" wrote in message

ups.com...



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- Hide quoted text -


- Show quoted text -






riso

Environ("username")
 
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...J: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

On Mar 8, 9:56 am, "NickHK" wrote:
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

"riso" wrote in message

s.com...



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


On Mar 6, 10:22 pm, "Bob Phillips" wrote:
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)

"riso" wrote in message


oups.com...


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- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -




riso

Environ("username")
 
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?


On Mar 6, 9:06 pm, "riso" wrote:
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





All times are GMT +1. The time now is 05:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com