Solved

print the second-last logon pc

Posted on 2011-09-03
25
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
  • 4
  • +1
25 Comments
 

Author Comment

by:DRRAM
ID: 36480107
PLEASE HELP IS VERRY URGENT
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36480134
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
ID: 36480178
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
Office 365 Training for IT Pros

Learn how to provision Office 365 tenants, synchronize your on-premise Active Directory, and implement Single Sign-On.

 
LVL 2

Expert Comment

by:atea_bjorn
ID: 36480227
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
ID: 36480313
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
ID: 36480350
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
ID: 36480388
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
ID: 36480389
Correction. the Value is DefaultUserName not LastLoggedOnUser

Cheers
Björn
0
 
LVL 2

Expert Comment

by:atea_bjorn
ID: 36480393
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
ID: 36480521
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
ID: 36480573
sounds like you didnt create it in notepad, or it had unicode set as type when saving it?
0
 

Author Comment

by:DRRAM
ID: 36480623
it does not always work the same error
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36480674
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
ID: 36484069
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
ID: 36485494
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
ID: 36486063
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
ID: 36486112
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
ID: 36486202
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
ID: 36527467
Did you get to try our suggestions here, do we need to look more?
0
 

Author Comment

by:DRRAM
ID: 36552135
IT DOES NOT WORK
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36552342
Thankyou for your helpful comments in debugging this.  goodbye.
0
 

Author Comment

by:DRRAM
ID: 36552398
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
ID: 36552481
A better result than I expected then!
0
 

Author Comment

by:DRRAM
ID: 36552514
YES THANK YOU ;-)
0
 
LVL 43

Expert Comment

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

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A hard and fast method for reducing Active Directory Administrators members.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

739 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