How to get the User Name?

  • Thread starter Thread starter kiros
  • Start date Start date
K

kiros

Hi all
I build the XPE image with two accounts.
One is "Adminsitrator" and the other is "User".
Default logon is "User".
Now i want to setup or upgrade my application automatically.
So i design some simple rules to do that.

As below:
1.Default logon is "User" and check if you want to update or not.

2.If "Yes", i will reboot and logon with "Administrator".
And when you finish that, it will reboot again and logon
with "User" automatically.
PS: I can set the registry key of "DefaultUserName" to autologon
with "Administrator" or "User".

3.If "No", nothing to do.

It can be done and works fine.
But now i have some problem. If i have 10 machines with XPE.
The "User" name is different with each machine.
For example, "User1", "User2", "User3",...
The "Administrator" name is the same with each machine.
So when i upgrade finished, i must logon with "User" again.
But now the "User" name of each machine is different.
So i want to know the "User" name with each machine and set the
registry key to autologn.

How do i get the "User" name?

Thanks
Kiros
 
Kiros,

It sounds a bit weird that you have UserX different user names on your machines with the same image. Why not the same user name for
all?

Another thing to mention is you don't necessarily have to reboot if you changed Autologon settings and want to apply the new
settings.
All you have to do is:
- change the Autologon settings
- logoff (there is a bunch of way to do that but easiest - search Net for logoff.exe or use "shutdown -l" command)
- Make sure this STRING registry value is set to "1": [HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon],
"ForceAutoLogon".

Anyway, to answer your question.. You have many ways to know the current logon user name but the easiest ones would be:
- use GetUserName[Ex] API: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getusername.asp
- read the following reg.value directly: [HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer],"Logon User Name".

KM
 
hi

it seems that all logon and logoff actions are just about to upgrade
some software/settings, i think runas service is a good choice for your
purpose, no matter who is the current user, just do what you want to do
running as administrators group member. and we've been taking advatage of it
for quite a while.

nick
 
Hi KM
Thanks for you advice.
Yes, I have different user names on the machines with the same image.
For some reason, i must assign different UserX name.
I will try these ways, thanks.
But i still have one question.
How do i get the UserX name in the "Administrator" account?
Because i have two accounts in my XPE image.
Thanks

Kiros
Kiros,

It sounds a bit weird that you have UserX different user names on
your machines with the same image. Why not the same user name for
all?

Another thing to mention is you don't necessarily have to reboot if
you changed Autologon settings and want to apply the new
settings.
All you have to do is:
- change the Autologon settings
- logoff (there is a bunch of way to do that but easiest - search
Net for logoff.exe or use "shutdown -l" command)
- Make sure this STRING registry value is set to "1":
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon],
"ForceAutoLogon".

Anyway, to answer your question.. You have many ways to know the
current logon user name but the easiest ones would be:
[HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer],"Logon User
Name".
 
Kiros,

Are you asking how to rename the Administrator account?
AFAIK, you can only do that at run time (with command line tools or GUI).

Or you can add UserX account to Admin group (look at the cmiUserGroup property of "User Account" component).

KM
Hi KM
Thanks for you advice.
Yes, I have different user names on the machines with the same image.
For some reason, i must assign different UserX name.
I will try these ways, thanks.
But i still have one question.
How do i get the UserX name in the "Administrator" account?
Because i have two accounts in my XPE image.
Thanks

Kiros
Kiros,

It sounds a bit weird that you have UserX different user names on
your machines with the same image. Why not the same user name for
all?

Another thing to mention is you don't necessarily have to reboot if
you changed Autologon settings and want to apply the new
settings.
All you have to do is:
- change the Autologon settings
- logoff (there is a bunch of way to do that but easiest - search
Net for logoff.exe or use "shutdown -l" command)
- Make sure this STRING registry value is set to "1":
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon],
"ForceAutoLogon".

Anyway, to answer your question.. You have many ways to know the
current logon user name but the easiest ones would be:
[HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer],"Logon User
Name".
 
Hi KM
Thanks for your advice.
I think i don't need to rename the Adminsitrator account or User
account.
Because i must upgrade some application with "Administrator"
account.(Logon with "Administrator")
When i upgrade finished, i must reboot and logon with "User"
automatically.(Logon with "UserX")
So i have to know what user name with "User" account and i can set the
registry key of autologon
and let the machine autologon with "UserX".
So how do i get the UserX name when i already logon with the
"Administrator" account?

Thanks
Kiros

Kiros,

Are you asking how to rename the Administrator account?
AFAIK, you can only do that at run time (with command line tools or GUI).

Or you can add UserX account to Admin group (look at the cmiUserGroup
property of "User Account" component).
KM
Hi KM
Thanks for you advice.
Yes, I have different user names on the machines with the same image.
For some reason, i must assign different UserX name.
I will try these ways, thanks.
But i still have one question.
How do i get the UserX name in the "Administrator" account?
Because i have two accounts in my XPE image.
Thanks

Kiros
Kiros,

It sounds a bit weird that you have UserX different user names on
your machines with the same image. Why not the same user name for
all?

Another thing to mention is you don't necessarily have to reboot
if
you changed Autologon settings and want to apply the new
settings.
All you have to do is:
- change the Autologon settings
- logoff (there is a bunch of way to do that but easiest -
search
Net for logoff.exe or use "shutdown -l" command)
- Make sure this STRING registry value is set to "1":
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon],
"ForceAutoLogon".

Anyway, to answer your question.. You have many ways to know the
current logon user name but the easiest ones would be:
- use GetUserName[Ex] API:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getusername.asp
- read the following reg.value directly:
[HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer],"Logon User
Name".
KM

Hi all
I build the XPE image with two accounts.
One is "Adminsitrator" and the other is "User".
Default logon is "User".
Now i want to setup or upgrade my application automatically.
So i design some simple rules to do that.

As below:
1.Default logon is "User" and check if you want to update or not.

2.If "Yes", i will reboot and logon with "Administrator".
And when you finish that, it will reboot again and logon
with "User" automatically.
PS: I can set the registry key of "DefaultUserName" to autologon
with "Administrator" or "User".

3.If "No", nothing to do.

It can be done and works fine.
But now i have some problem. If i have 10 machines with XPE.
The "User" name is different with each machine.
For example, "User1", "User2", "User3",...
The "Administrator" name is the same with each machine.
So when i upgrade finished, i must logon with "User" again.
But now the "User" name of each machine is different.
So i want to know the "User" name with each machine and set the
registry key to autologn.

How do i get the "User" name?

Thanks
Kiros
 
Kiros,

You have a few ways to accomplish what you want.

The most proper way:
- You can enumerate folder names under "%SystemDrive%\Documents and Settings" (more exactly, this path is stored under
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList],"ProfilesDirectory").
Although sometimes (depends on the system designer wish) the folder names may nto reflect the actual user names.
So you will be interested in the user registry hive: %SystemDrive%\Documents and Settings\LocalService\NTUSER.DAT.

or

- You can enumerate registry keys under [HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList]. each subkey there
reflects a user account setting. Read ProfileImagePath value from a subkey.


After any of the enumeration above, you read user profile image (%SystemDrive%\Documents and Settings\LocalService\NTUSER.DAT)
with reg.exe tool and then just read [Software\Microsoft\Windows\CurrentVersion\Explorer],"Logon User Name" value of the loaded
profile hive. This way you know the profile user name.

I believe there are even easier ways to know otehr user account names.

For example, you you enumarate registry value names under [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths],
you will get all the user names.

Or using WMI interfaces you can get the user name list from a script or a program.

KM
Hi KM
Thanks for your advice.
I think i don't need to rename the Adminsitrator account or User
account.
Because i must upgrade some application with "Administrator"
account.(Logon with "Administrator")
When i upgrade finished, i must reboot and logon with "User"
automatically.(Logon with "UserX")
So i have to know what user name with "User" account and i can set the
registry key of autologon
and let the machine autologon with "UserX".
So how do i get the UserX name when i already logon with the
"Administrator" account?

Thanks
Kiros

Kiros,

Are you asking how to rename the Administrator account?
AFAIK, you can only do that at run time (with command line tools or GUI).

Or you can add UserX account to Admin group (look at the cmiUserGroup
property of "User Account" component).
KM
Hi KM
Thanks for you advice.
Yes, I have different user names on the machines with the same image.
For some reason, i must assign different UserX name.
I will try these ways, thanks.
But i still have one question.
How do i get the UserX name in the "Administrator" account?
Because i have two accounts in my XPE image.
Thanks

Kiros

KM wrote:
Kiros,

It sounds a bit weird that you have UserX different user names on
your machines with the same image. Why not the same user name for
all?

Another thing to mention is you don't necessarily have to reboot if
you changed Autologon settings and want to apply the new
settings.
All you have to do is:
- change the Autologon settings
- logoff (there is a bunch of way to do that but easiest - search
Net for logoff.exe or use "shutdown -l" command)
- Make sure this STRING registry value is set to "1":
[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon],
"ForceAutoLogon".

Anyway, to answer your question.. You have many ways to know the
current logon user name but the easiest ones would be:
- use GetUserName[Ex] API:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getusername.asp
- read the following reg.value directly:
[HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer],"Logon User
Name".

KM

Hi all
I build the XPE image with two accounts.
One is "Adminsitrator" and the other is "User".
Default logon is "User".
Now i want to setup or upgrade my application automatically.
So i design some simple rules to do that.

As below:
1.Default logon is "User" and check if you want to update or not.

2.If "Yes", i will reboot and logon with "Administrator".
And when you finish that, it will reboot again and logon
with "User" automatically.
PS: I can set the registry key of "DefaultUserName" to autologon
with "Administrator" or "User".

3.If "No", nothing to do.

It can be done and works fine.
But now i have some problem. If i have 10 machines with XPE.
The "User" name is different with each machine.
For example, "User1", "User2", "User3",...
The "Administrator" name is the same with each machine.
So when i upgrade finished, i must logon with "User" again.
But now the "User" name of each machine is different.
So i want to know the "User" name with each machine and set the
registry key to autologn.

How do i get the "User" name?

Thanks
Kiros
 
KM

sorry, i forgot to mention such things. and sure we wrapped runas that
can feed password to it.

thanks

nick
 
Back
Top