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
DRRAMAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
OK, how about this VBScript.  Paste into Notepad, Save As, change to "All files" and save it as "resetuser.vbs" or something.

When you double click and run it from Explorer, maybe from network drive or shortcut on desktop of your admin user it will prompt for the logon and then reset the default username / default domain for the next logon.

Haven't tried it on Vista / 7 etc. but should be OK on 2000/XP at least... only had a test 2000 box to try it on for now.

Steve
' Set default logon user
' Simple script to read a user name from prompt and set the default user name in the registry so that after a logoff/logon it will be the one shown
' Also sets the domain name in case the last account used was a local account, please customise
' Steve Knight.  5 Sep 2011  http://www.dragon-it.co.uk/

Dim objWShell, username,version

version="1.01"
set objWShell = WScript.CreateObject( "WScript.Shell" )

domain="EN"  ' Change to YOUR-DOMAIN-NAME
username=Inputbox("Please Enter Username","REVERT USERNAME")

if username <>"" then
  call objWShell.RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", username, "REG_SZ")
  call objWShell.RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName", domain, "REG_SZ")
else
  wscript.quit
end if

Open in new window

0
 
DRRAMAuthor Commented:
PLEASE HELP IS VERRY URGENT
0
 
Steve KnightIT ConsultancyCommented:
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
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
DRRAMAuthor Commented:
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
0
 
atea_bjornCommented:
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
0
 
DRRAMAuthor Commented:
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
0
 
Steve KnightIT ConsultancyCommented:
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.
0
 
atea_bjornCommented:
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
0
 
atea_bjornCommented:
Correction. the Value is DefaultUserName not LastLoggedOnUser

Cheers
Björn
0
 
atea_bjornCommented:
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
0
 
DRRAMAuthor Commented:
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
0
 
Steve KnightIT ConsultancyCommented:
sounds like you didnt create it in notepad, or it had unicode set as type when saving it?
0
 
DRRAMAuthor Commented:
it does not always work the same error
0
 
Steve KnightIT ConsultancyCommented:
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
0
 
grayeCommented:
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
0
 
DRRAMAuthor Commented:
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
0
 
Steve KnightIT ConsultancyCommented:
Can't get onto domain machine at the mo. but tested on XP box with control-alt-delete style logon box enabled. OK.
0
 
grayeCommented:
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.
0
 
Steve KnightIT ConsultancyCommented:
Did you get to try our suggestions here, do we need to look more?
0
 
DRRAMAuthor Commented:
IT DOES NOT WORK
0
 
Steve KnightIT ConsultancyCommented:
Thankyou for your helpful comments in debugging this.  goodbye.
0
 
DRRAMAuthor Commented:
Sorry I replied to another question by mistake excuse me stp
in fact the script that you sent me works very well
thx
0
 
Steve KnightIT ConsultancyCommented:
A better result than I expected then!
0
 
DRRAMAuthor Commented:
YES THANK YOU ;-)
0
 
Steve KnightIT ConsultancyCommented:
Updated version including Windows 7 etc. too:
http://scripts.dragon-it.co.uk/links/vbscript-reset-last-logged-on-user
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.