AllExperts > VB Script 
Search      
VB Script
Volunteer
Answers to thousands of questions
 Home · More VB Script Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Subbu
Expertise
I can answer VB Script questions which are related to Visual Basic / VBA / QTP Scripts.

Experience
8 Years

Education/Credentials
Master of Computer Applications

Awards and Honors
Established Member from QA Forums and Brainbench certification

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > vbs script to be modified

VB Script - vbs script to be modified


Expert: Subbu - 6/10/2009

Question
Hello,
I have this script:
This code prints the last logon timestamp for a user.
' ------ SCRIPT CONFIGURATION ------
strUserDN = "<UserDN>"  ' e.g. cn=rallen,ou=Sales,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------

set objUser =  GetObject("LDAP://" & strUserDN)
set objLogon = objUser.Get("lastLogonTimestamp")
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
WScript.Echo "Approx last logon timestamp: " & intLogonTime + #1/1/1601#

This script works perfectly for one user. I am asking for your help to modify this script to work for a list of users which i have in a txt(every user is on a new line in the txt) and to make an export of the result in a tab delimited file.
Can you help me?
Many thanks in advance.


Answer
Raducu,

create a text file and save as "userlist.txt" at "c:\" and past your all userdn.  Make sure there will be no header row in text file.  

Try below code and let me know if any issue there.

Subbu.

dim userDN
' Get a free file number
nFileNum = FreeFile
' Open a text file for input
Open "C:\userlist.txt" For Input As nFileNum
' Read the contents of the file
Do While Not EOF(nFileNum)
  Line Input #nFileNum, userDN
  'MsgBox snextline


------ SCRIPT CONFIGURATION ------
strUserDN = userDN  ' e.g. cn=rallen,ou=Sales,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------

set objUser =  GetObject("LDAP://" & strUserDN)
set objLogon = objUser.Get("lastLogonTimestamp")
intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
intLogonTime = intLogonTime / (60 * 10000000)
intLogonTime = intLogonTime / 1440
WScript.Echo "Approx last logon timestamp: " & intLogonTime + #1/1/1601#

Loop
' Close the file
Close nFileNum


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.