Link to home
Start Free TrialLog in
Avatar of DRRAM
DRRAM

asked on

print the second-last logon pc

Please, can you help me to write a script
I would like to know how to print the second-last logon pc (xp) user session in the DC (Active directory Win 2003) instead of printing last user session
Avatar of DRRAM
DRRAM

ASKER

PLEASE HELP IS VERRY URGENT
Avatar of Steve Knight
Well... you will need to store some information IMO.

Best bet would be have a share which can be accessed by all for writing, e.g. \\server\info$

For this simple exercise suggest creating dirs under this share:

lastlogon
prevlogon

then in your login script add:

REM Remove the previous session if it exists
del \\server\info$\prevlogon\%username%.txt 2>NUL

REM If it exists move the last logon details to the previous logon folder
if exist \\server\info$\lastlogon\%username%.txt move \\server\info$\lastlogon\%username%.txt \\server\info$\prevlogon

REM Create an entry in the lastlogon folder for each user called username.txt
echo %date%,%time%,%username%,%computername% > \\server\info$\lastlogon\%username%.txt

You could also add to that with other recording, e.g. all users of each computer, all computers logged into:

Create two more subdirs called computer and user


REM Append to a file in the users and computer
echo %date%,%time%,%username%,%computername% >> \\server\info$\computer\%computername%.txt
echo %date%,%time%,%username%,%computername% >> \\server\info$\user\%username%.txt

Now... you will have a file based on the username in the \\server\info$\prevlogon directory based on the users' name.

If you just want to display this information to a user during logon you only need to keep the "last" logon, show them that and then write the current information to that file for next time.

Is that what you mean?

Steve
Avatar of DRRAM

ASKER

you do not have an easier methode  (its not clear)
please view the attachment you will find the normal logon window
but me I need to have in place of last logon "user: test1" I want "user: test0" before the last logon
please help me
logon.png
What you want to do is pretty much impossible to do. What you can do is to have the Username box empty whenever anyone wants to logon. And then you need to force your users to actuly remember there usernames ;).

Or you can set this to a standard username that is going to be there all the time like "Change Me Before Logging On" or something similar.

Cheers
Björn
Avatar of DRRAM

ASKER

how  I can set this to a standard username that is going to be there all the time like "Change Me Before Logging On" or something similar.

please
right... So you want a default logon name in the logon box, not to print the second last logon name somewhere.... Understanding now, I guess something was lost a bit in the translation - somewhat better than my school French though mind!

I know there are some similar registry entries for autologons etc. but cant think of one that does that speciically .... A typical solution is a sticker on the keyboard saying to logon as xxxxx!

Will have a poke through my docs from when we rolled out XP etc. years ago.
Hi, this is the reg key you need to set

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\

The value in LastLoggedOnUser is what is shown in the logon box when you startup your Windows

So you can use GPO to set this on a machine level by making your own GPO definition file.

I do not have that kind of GPO right now, but I can get a more rigid instruction for you by tomorrow.

Cheers
Björn
Correction. the Value is DefaultUserName not LastLoggedOnUser

Cheers
Björn
Dim sDomName
Set oWshShell = CreateObject(“WScript.Shell”)
sDomName = “Change this to whatever username you want”
oWshShell.RegWrite “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName”, sDomName

Open in new window


This is a VBScript to set DefaultUserName
Avatar of DRRAM

ASKER

I created a file.vbs that contains:
Dim sDomName
Set oWshShell = CreateObject(“WScript.Shell”)
sDomName = “ra”
oWshShell.RegWrite “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName”, sDomName

I execute the script : cscript file.vbs

i have an erreur after execute ::: Microsoft VBScript compilation error: invalid character
sounds like you didnt create it in notepad, or it had unicode set as type when saving it?
Avatar of DRRAM

ASKER

it does not always work the same error
Actually sorry I can see the issue... The characters " " have been converted into different double quotes.  Make sure they are just " (shift 2 on Uk keyboard).

i.e.

Dim sDomName
Set oWshShell = CreateObject("WScript.Shell")
sDomName = "ra"
oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", sDomName

or just amend it regedit

Steve
I've got a utility called UserRestore that does precisely what you're talking about...  Here is the Readme.text file

When administrators use their accounts to log onto a client's PC, they "leave behind" their
user name in the login screen as the last user that logged onto that PC.  This can confuse some
users who are used to only seeing their own name in the login screen... and the administrator's
account gets locked out due to unsuccessful login attempts.

This program is used in the login batch file on Administrator accounts only.  It will save the
previous user's name and restore that name as the "last user" in the login screen.  You can
also mannually pick another name to display.

BTW: C2 ratings require that the last user name not be shown, so this program would have no
purpose in that scenario.

The application is available only as VB.Net source code, so that means you'll have to use Visual Studio to compile it into an application.

http://www.emmet-gray.com/Temp/UserRestore.zip
Avatar of DRRAM

ASKER

Please Graye
that's exactly what I need but the machines xp installed and complicated on each machine install the vb.net please you have any solutions in .vbs or .bat or .exe Thank you very much
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can't get onto domain machine at the mo. but tested on XP box with control-alt-delete style logon box enabled. OK.
No, you just compile it once (on any PC that has Visual Studio).  After compiling it becomes a normal *.exe file (with an associated *.exe.config file).

You take those two file that are generated during the compiling and copy them to the location where the GPO login script resides.  No need to install anything on the client PCs at all (er, well... I *am* assuming that the client PCs have some flavor of the .Net Framework installed).

You can download and install a free version of Visual Basic.... but quite frankly, it would make more since to take it to someone who already has visual studio installed, and ask them to compile it.
Did you get to try our suggestions here, do we need to look more?
Avatar of DRRAM

ASKER

IT DOES NOT WORK
Thankyou for your helpful comments in debugging this.  goodbye.
Avatar of DRRAM

ASKER

Sorry I replied to another question by mistake excuse me stp
in fact the script that you sent me works very well
thx
A better result than I expected then!
Avatar of DRRAM

ASKER

YES THANK YOU ;-)