Solved

print the second-last logon pc

Posted on 2011-09-03
25
456 Views
Last Modified: 2014-10-21
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
0
Comment
Question by:DRRAM
  • 10
  • 9
  • 4
  • +1
25 Comments
 

Author Comment

by:DRRAM
Comment Utility
PLEASE HELP IS VERRY URGENT
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
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
 

Author Comment

by:DRRAM
Comment Utility
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
 
LVL 2

Expert Comment

by:atea_bjorn
Comment Utility
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
 

Author Comment

by:DRRAM
Comment Utility
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
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
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
 
LVL 2

Expert Comment

by:atea_bjorn
Comment Utility
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
 
LVL 2

Expert Comment

by:atea_bjorn
Comment Utility
Correction. the Value is DefaultUserName not LastLoggedOnUser

Cheers
Björn
0
 
LVL 2

Expert Comment

by:atea_bjorn
Comment Utility
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
 

Author Comment

by:DRRAM
Comment Utility
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
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
sounds like you didnt create it in notepad, or it had unicode set as type when saving it?
0
 

Author Comment

by:DRRAM
Comment Utility
it does not always work the same error
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
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
 
LVL 41

Expert Comment

by:graye
Comment Utility
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
 

Author Comment

by:DRRAM
Comment Utility
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
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
Comment Utility
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
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
Can't get onto domain machine at the mo. but tested on XP box with control-alt-delete style logon box enabled. OK.
0
 
LVL 41

Expert Comment

by:graye
Comment Utility
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
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
Did you get to try our suggestions here, do we need to look more?
0
 

Author Comment

by:DRRAM
Comment Utility
IT DOES NOT WORK
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
Thankyou for your helpful comments in debugging this.  goodbye.
0
 

Author Comment

by:DRRAM
Comment Utility
Sorry I replied to another question by mistake excuse me stp
in fact the script that you sent me works very well
thx
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
A better result than I expected then!
0
 

Author Comment

by:DRRAM
Comment Utility
YES THANK YOU ;-)
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
Updated version including Windows 7 etc. too:
http://scripts.dragon-it.co.uk/links/vbscript-reset-last-logged-on-user
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now