' Get User Information gui.vbs
' Revision history
' Initialize the variable farm
Dim objUserName, objUserDomain, oGroup, objUser, gList, WshShell, sMessage, sTitle
Dim objDomain, vDomain, vUserName
Dim objChangePwdTrue, objChangePwd, objUserProfile
Dim objPwdExpiresTrue, objFlags
Dim objAcctDisabled, intPwdExpired, objPwdExpiredTrue
' Set WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
' Pull Environment variables for domain/user
vdomain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
vUserName = WshShell.ExpandEnvironmentStrings("%USERNAME%")
SysTest ' sub routine to check for Script Version/ADSI installed
GetInfo ' sub routing to get user information
on error resume Next
' Define user then retrieve and store groups in a list
For Each oGroup In objUser.Groups
If gList = "" Then
gList = oGroup.Name
Else
gList = gList & ", " & oGroup.Name
End If
Next
'check for expired password
intPwdExpired = objUser.Get("PasswordExpired")
If intPwdExpired = 1 Then
objPwdExpiredTrue = "Yes"
Else objPwdExpiredTrue = "No"
End If
'Check for Must Change Password Flag
objFlags = objUser.Get("UserFlags")
If (objFlags And &H00040) <> 0 Then
objChangePwdTrue = "No"
Else objChangePwdTrue = "Yes"
End If
' Is password set to NEVER expire?
objPwdExpires = objUser.Get("UserFlags")
If (objPwdExpires And &H10000) <> 0 Then
objPwdExpiresTrue = "Yes"
Else objPwdExpiresTrue = "No"
End If
' Is the account disabled?
If objUser.AccountDisabled = True Then
objAccountDisabled = "Yes"
Else objAccountDisabled = "No"
End If
'How many wrong logins?
objBadLogins = objUser.BadLoginCount
' How old is the current password?
oPwdAge = objUser.Get("PasswordAge")
objPwdAge = FormatNumber(((oPwdAge/60)/60)/24, 0)
' Set Profile path to tabs if blank
If objUserProfile = "" Then
objUserProfile= "" & vbTab
Else objUserProfile = objUserProfile
End If
' Set sMessage box variables to null
sMessage =""
'popup user information: each line broken up for better reading
sMessage = sMessage & "Domain: " & objDomain & vbTab & "User Name: " & objUserName & _
vbTab & "Full Name: " & objUser.FullName & vbTab & vbTab & "Description: " & _
objUser.Description & vbCrLf & vbCrLf
sMessage = sMessage & "Password Expired: " & objPwdExpiredTrue & vbTab & _
"User can change Pwd: " & objChangePwdTrue & vbTab & "Account Disabled: " & _
objAccountDisabled & vbTab & vbTab & "Account Locked Out: " & objUser.IsAccountLocked & _
vbTab & "Password Age: " & objPwdAge & vbCrLf & vbCrLf
sMessage = sMessage & "Bad Logins: " & objBadLogins & vbTab & vbTab & "Last logon: " & _
objUser.LastLogin & vbTab & "Password Never Expires: " & objPwdExpiresTrue & _
vbTab & "Password Minimum Length: " & objUser.PasswordMinimumLength & vbCrLf & vbCrLf
sMessage = sMessage & "User Profile Path: " & objUserProfile & "Home Directory: " & _
objUser.HomeDirectory & vbTab & "Login Script: " & objUser.LoginScript & vbCrLf & vbCrLf
sMessage = sMessage & "User Groups: " & vbCrLf & vbCrLf & gList & vbCrLf
' Display User Information!
WshShell.Popup sMessage,0,"User Information for: " & objUserName & " in " & objDomain
Sub GetInfo()
' Retrieve Domain from user
sMessage = "Please enter the domain to search." & vbCrLf & vbCrLf & _
"Default is: " & vDomain & vbCrLf & vbCrLf
sMessage = sMessage & "Hit Cancel or enter a blank to quit"
sTitle = "Domain to Search"
'get resource domain name, domain default
objDomain = InputBox(sMessage, sTitle, vDomain)
' Evaluate the user input.
If objDomain = "" Then ' Cancelled by the user
WScript.quit
End If
' Set sMessage box variables to null
ssMessage = ""
ssTitle = ""
on error resume Next
' Define username dialog box variables.
sMessage = "Please enter the USER Login ID" & vbCrLf & vbCrLf & _
"Default is: " & vUserName & vbCrLf & vbCrLf
sMessage = sMessage & "Hit Cancel or enter a blank to quit"
sTitle = "USER Login ID"
'get resource domain name, domain default via input box
objUserName = InputBox(sMessage, sTitle, vUserName)
' Evaluate the user input.
If objUserName = "" Then ' Cancelled by the user
WScript.quit
End If
' Display Just a minute!
sMessage = "This may take a few seconds. . ."
WshShell.Popup sMessage,2,"One moment please. . . "
sMessage = ""
'Attempt to bind to the user
Set objUser = GetObject("WinNT://"& objDomain &"/"& objUserName & "",user)
If Err Then
msgNoUser = "Error: Could not bind to the following user: " & vbCrLf _
& vbCrLf & "WinNT://" & objDomain &"/"& objUserName & vbCrLf & vbCrLf _
& "Please verify your domain and user name and try again"
WshShell.Popup msgNoUser,0,"Error retrieving information",vbCritical
GetInfo
Else
msgConnected = "Connected to user WinNT://" & objDomain &"/"& objUserName & vbCrLf
WshShell.Popup msgConnected,0,"Connected To " & objUserName & " in " & objDomain, vbInformation
End If
End Sub
Sub SysTest()
on error resume Next
' WSH version tested
Major = (ScriptEngineMinorVersion())
Minor = (ScriptEngineMinorVersion())/10
Ver = major + minor
'Need version 5.5
If err.number or ver = 5.6 then
message = "You must load Version 5.5 (or later) of Windows Script Host" & vbCrLf &_
vbCrLf & "Located at: \\servername\share\scr56en.exe"
WScript.Quit
End If
'Test for ADSI
err.clear
key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{E92B03AB-B707-11d2-9CBD-0000F87A369E}\version"
key2 = WshShell.RegRead (key)
if Err <> 0 then
message = message & "ADSI 5.2 must be installed on local workstation to continue" & vbCrLf &_
vbCrLf & "Located at: \\servername\share\adsi5.2.exe"
WshShell.Popup message,0,"Workstation Setup Error",vbCritical
WScript.Quit
End If
'Test whether the host is CScript.exe.
'G. Born code...
If IsBatch = "TRUE" Then
If (Not IsCScript()) Then
message = "You must set default host to cscript to run as a batch." &vbcrlf &_
"Use the command wscript //h:cscript" 'popup closes to avoid desktop hell
WshShell.Popup message,3,"Workstation Setup Error",vbCritical
WScript.Quit ' Terminate script.
End If
End if
End Sub
Function IsCScript()
' Check whether CScript.exe is the host.
If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then
IsCScript = True
Else
IsCScript = False
End If
End Function
'**** Script Ends
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!