Solved

Is there another command like %USERNAME%?

Posted on 2004-09-17
31
1,087 Views
Last Modified: 2008-01-09
Lets say I have a user Object:

First Name = Bart
Last Name = Simpson
Usr Name = b.simpson

%USERNAME% returns a value of b.simpson

What if I dont want this but I want the value of the First name.. would it be %FIRSTNAME%?

Is there a command for this and if so what is it?
0
Comment
Question by:mrchaos101
  • 16
  • 11
  • 3
  • +1
31 Comments
 
LVL 3

Assisted Solution

by:Pasdargent
Pasdargent earned 250 total points
ID: 12084937
You can query Active Directory for the givenName (first name) or the sn (last name) of a user.  I don't know of a % variable that would list what you are requesting, though.

A VBScript for such a typical query of AD for the things I mentioned would be like this:
strUsername = inputBox("What is the username you are querying?","Enter username")
Const ADS_SCOPE_SUBTREE = 2
Const ForAppending = 8
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select * from 'LDAP://DC=YOURDOMAIN,DC=COM' where sn='" & strUsername & "'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
      msgBox strUsername & ": " & vbTab & objRecordset("givenName")
      objRecordSet.MoveNext
Loop

Save the above text to a .VBS file and run it.  Be sure to change the YOURDOMAIN and COM to your actual DC information (the distinguished name of the AD domain).

Hope this is something you can use.  Let me know if you need more assistance.
0
 
LVL 34

Expert Comment

by:PsiCop
ID: 12084942
What environment is this? Give us a break - we're Experts, not mindreaders.
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12085093
It is for a logon.bat script

I thought is was a simple question.

ECHO Welcome %USER% to the BLA BLA BLA network. Have a nice day.

I would like it to welcome them by their fist name.

And thank you Pasdargent for your kindness.  Would you know how to do it in a batch file by any chance?
0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12085264
Funnily enough, I already have a script that does just that and used it in an answer here on EE already.  This is what I created to provide a "welcome" to the user when they logon (again, save as a VBS and run or use as the logon script for your users):

#############################
on error resume next
myMonth = month(now())
myMonthName = monthname(myMonth)
myYear = year(now())
myDay = day(now())
myWeekday = Weekday(myDay)
myWeekdayName = weekdayname(myWeekday)
myHour = hour(time())
myMinute = minute(time())
myAMPM = split(now()," ")
IF myAMPM(2) = "AM" THEN
      myGreeting = "Good morning, "
ELSE
      myGreeting = "Good afternoon, "
End If

ComputerName = "."
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName & ""
Set UserSet = GetObject( winmgmt1 ).InstancesOf ("Win32_ComputerSystem")
if err = 0 then
for each User in UserSet
      msgBox myGreeting & User.UserName & "." & vbcrlf & "Today is " & myWeekdayName & ", " & myMonthName & " " & myDay & ", " & myYear & "." & vbcrlf & "The current time is " & time()
Next
else if err <> 0 THEN msgBox "Welcome to the network."
end if
#################################

Let me know if this helps or not.
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12085401
Pasdargent,

Im a noob so for give the ignorance here... but that last script you poste still apears to b vbSricpt?

Im not sure how to use this.  What iM looking for is somthing simple...

rem +++ DISPLAY WELCOME

echo.
ECHO Welcome to the Atltek Systems, Inc. Network, %USERNAME%.
echo.
ECHO You are at computer %COMPUTERNAME% running Windows XP Pro os.
echo.
ECHO Please wait, authenticating %USERNAME% with the %USERDOMAIN% domain.
echo.


I want to replace the  %USERNAME% with what have shows the FIRST NAME for that use vs. the user logon id.

Thanks
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12085412
save as a VBS and run or use as the logon script for your users

just seen this let me try lol sorry
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12085421
err.. not sure if that will work for me.. my logon.bat looks like this:


REM logon.bat
@echo off
cls
call welcome.bat
call Mapdrives.bat


and the WELCOME suff is in the welcome.bat
0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12085425
To get something like that, you are most likely going to have to use VBScript in some capacity.  I don't think a batch file will take care of what you are looking for.  I may be wrong, though.
0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12085471
You could call the vbscript from your batch file by doing something like this:
wscript logon.vbs
This will have the script interpreter run the logon.vbs script I posted above.
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12085476
can I call a vb script?


Can I say  call welcome.vbs  and it work?
0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12085487
I don't know about "call" working in a batch, but the wscript line should do it.
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12085576
Ok I got it to try to call the vbs file  logon.bat looks like this:

REM logon.bat
@echo off
cls
wscript welcome.vbs
call Mapdrives.bat


NOW... when you do wscript does it look to the same DIR that he logn.bat is in as that is where it is being called from?
I got an error box that said it could not find the welcome.vbs file and it showed a path pointing to the clints LOCLAL hd and user mydocuments.

I need it to look in the same spot that the logon.bat is in.
0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12085668
Then what you need to do is specify the exact location of the logon.vbs script.  For instance:

wscript "C:\My Folder\logon.vbs"
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12085782
OK I got a new error:

Execution of Windows Script host failed. (Not enough storage is available to complete tis operaion)

Currently my Logon.bat looks like this:

REM logon.bat
@echo off
cls
wscript "\\Server2003\NETLOGON\welcome.vbs"
call Mapdrives.bat


and the welcome.vbs is your cod with no ****** in it

0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12085866
Check your event log on the Server2003 server and see if you have any 2020 event ID errors.  This error sometimes appears and will make a server act as though there is not enough disk space.  Reboot your server first chance you get and try this again.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:mrchaos101
ID: 12085999
I didn't see any 2020 erros. I rebooted it any way.

I still get that same message.
0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12086018
try running the vbscript from its location after you have logged on to see if you still get that message
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12086106
ERRRR fustrating.

It runs just fine on the server if I dbl click it.

I rebooted the clinet.  It still gives me that error message.
0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12086140
Egad.  I don't quite understand that one!  But the script does do what you are looking for, right?
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12086190
Well no.  When the client computer logs on it gets that error.

If I log on localy to the server it works fine.
0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12086209
Does the user account have at least read access to the location of the VBScript?
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12086222
yes as the  welcome.bat file runs just fine.

0
 
LVL 3

Expert Comment

by:Pasdargent
ID: 12086245
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12086326
Ok so y ou are saying you feel it is an issue with teh CLIENT pc then and not the sever right?
0
 

Expert Comment

by:hirschy
ID: 12086620
I'm not sure about the vbscript stuff, but these are common %% calls I use:

The following keywords are currently recognized by UserManagemeNT:

Keyword
 Description
 
%DEPARTMENT%
 The department selected within an unit ;
 
%DOMAIN%
 The domain of the current user;
 
%FULL_NAME%
 The full name of the current user;
 
%OU%
 The selected unit ;
 
%OU_LOCATION%
 The location selected within an unit ;
 
%SERVER_LOCATION%
 The location of the selected home-server;
 
%SERVERNAME%
 The home server of the current user;
 
%USERNAME%
 The username of the current user.
 
%FIRST_NAME%
 The first part of the full name of the current user.
 
%INITIALS%
 The middle part of the full name of the current user
 
%LAST_NAME%
 The last part of the full name of the current user
 
When a keyword corresponds with multiple values, the values are concatenated.
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12086621
Well Im still confused at it works loccaly on the server but not the client.
Seems a lot of trouble just to get the the FRIST name of the user on the screen vs their login name LOL
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12086665
hirschy,

cls
echo.
ECHO Welcome to the Network, %FIRST_NAME%.
echo.
ECHO You are at computer %COMPUTERNAME% running Windows XP Pro os.
echo.
ECHO Please wait, authenticating %USERNAME% with the %USERDOMAIN% domain.
echo.
sleep 10

It omits the %FIRST_NAME% and shows jut the "."
From what you see should it work or am I missing something?
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12086723

When the code runs above, this is what is showed in the box:


Welcome to the Network, .

You are at computer IT running Windows XP Pro os.

Please wait, authenticating b.simpson with the TEST domain.

 
0
 
LVL 1

Author Comment

by:mrchaos101
ID: 12087039
Upping points as I want to get this figured out.  I like the vb.. but would rather make the batch commands work.
0
 

Expert Comment

by:hirschy
ID: 12087160
Sorry, I am re-looking for the site I found the above list at.
It have been a while since I used them, and I guess that commnad is invalid.
I am looking again.
0
 

Accepted Solution

by:
hirschy earned 250 total points
ID: 12087438
here is the link I found this info at
http://www.tools4ever.com/resources/manual/usermanagement/Keyword_in_names.htm
I guess you would have to buy and configure UsermanagemeNT to use that %first_name% option.
Sorry again for getting your hopes up.  
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

I was recently sitting at a desk at work with one of my colleagues and needed some information on my home computer. He watched as I turned on my home computer, established a remote session into it, got the information I needed and then shut it down …
Lets look at the default installation and configuration of FreeProxy 4.10 REQUIREMENTS 1. FreeProxy 4.10 Application - Can be downloaded here (http://www.handcraftedsoftware.org/index.php?page=download) 2. Ensure that you disable the windows fi…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

18 Experts available now in Live!

Get 1:1 Help Now