Hi,
I need to retrieve the logged-in user from a computer system, and found a WMI-query, but with the result I like to retrieve some userobjects like displayname, telnr and mail.
I was able to make a VBScript, but I have one little problem, I use LDAP to retrieve the userobjects, but with my knowledge of VBS I can manage to have read 1 OU from Active Directory, by using the variable I made from the WMIquery (see code for the complet script)
what I like to achieve is the VB lookvia LDAP for everything inside: OU=RootOU
no matter how many subOU's there are until it finds the variable logonname
strComputer = inputbox("Please enter the name of the computer:")
' Check that user entered a value
if strComputer = "" then
wscript.quit
end if
ON ERROR RESUME NEXT ' Handle errors connecting to the computer (Not switched on, permissions error etc)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
if err <> 0 then ' Check for error
wscript.echo "Error connecting to specified computer: " & err.description
wscript.quit
end if
ON ERROR GOTO 0 ' Turn off resume next error handling
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
'Wscript.Echo "Logged-on user: " & objComputer.UserName
logonname = MID(objComputer.UserName,(instr(objComputer.UserName,"\")+1),LEN(objComputer.UserName))
Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://CN=" & logonname & ",OU=SubOU1,OU=RootOU,DC=domainname,DC=local")
WScript.echo "User loggod on to" & vbCrLf _& vbCrLf _& "Computer" & VBTAB & " : " & strComputer & vbCrLf _& "UserID" & VBTAB & " : " & logonname & vbCrLf _& "Gebruiker" & VBTAB & " : " & objUser.displayName & vbCrLf _& "Telefoon" & VBTAB & " : " & objUser.telephoneNumber & vbCrLf _& "Mobiel" & VBTAB & " : " & objUser.mobile & vbCrLf _& "E-Mail" & VBTAB & " : " & objUser.EmailAddressGreetz Fred