#182712 - 2007-11-15 06:54 PM
VBS to KIX
|
golfbuddy
Fresh Scripter
Registered: 2005-12-16
Posts: 12
|
How do I or can someone convert this VBS so I can run it within my KIX script?
Thank you very much for the help!
Dim RootDSE, strDomain, strSamID
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
'get logon SAM name
strSamID = WshShell.Environment("Process").Item("USERNAME")
'get domain naming context
Set RootDSE = GetObject("LDAP://RootDSE")
strDomain = RootDSE.Get("DefaultNamingContext")
'open AD provider object
Set objADOConnection = CreateObject("ADODB.Connection")
objADOConnection.Open "Provider=ADsDSOObject;"
Set objADOCommand = CreateObject("ADODB.Command")
objADOCommand.ActiveConnection = objADOConnection
objADOCommand.Properties("Page Size") = 1000
objADOCommand.Properties("Size Limit") = 1000
'If Err.Number <> 0 Then
' WScript.Echo "ERROR: Unable to open AD provider"
' WScript.Quit(1)
'End If
'get DistName for SamID
objADOCommand.CommandText = "<LDAP://" & strDomain & ">;(&(objectCategory=user)(sAMAccountName=" & strSamID & "));distinguishedName;subtree"
Set objADORecordset = objADOCommand.Execute
If objADORecordset.EOF Then
' WScript.Echo "ERROR: Unable to find SamID"
WScript.Quit (1)
Else
Err.Clear
Set objItem = GetObject("LDAP://" & FixLDAPQuery(objADORecordset.Fields("distinguishedName")))
If Err.Number <> 0 Then
' WScript.Echo "ERROR: Unable to find DistName"
WScript.Quit (1)
Else
strBadLogonCount = objItem.Get("bcbsscPreviousBadLogonCount")
strLastLogon = Replace(objItem.Get("bcbsscPreviousLogonDateString"), Chr(34), "")
If strBadLogonCount <> "" And strLastLogon <> "" Then
MsgBox "Your last logon To AD was on " & strLastLogon & "." & vbCrLf & _
"There were " & strBadLogonCount & " invalid logon attempts noted since your last logon.",, _
"Active Directory Security Notice"
Else
' WScript.Echo "Data not valid"
End If
End If
End If
Function FixLDAPQuery(strIn)
strIn = Replace(strIn, "'", "''")
strIn = Replace(strIn, "\", "\\")
strIn = Replace(strIn, "/", "\/")
FixLDAPQuery = strIn
End Function
Edited by NTDOC (2007-11-15 09:00 PM) Edit Reason: Placed code within code tags
|
Top
|
|
|
|
#182718 - 2007-11-15 10:53 PM
Re: VBS to KIX
[Re: golfbuddy]
|
golfbuddy
Fresh Scripter
Registered: 2005-12-16
Posts: 12
|
Ok... I was able to research a little more and downloaded VBS2KIX.VBS. Even going with the conversion sample, I am keep getting error. No luck in converting.
I have everything in c:\temp. Here is my .kix to convert: vbs2KiX(c:\temp+"\logonbanner.vbs",c:\temp+"\logonbanner.kix")
What am I doing wrong?
|
Top
|
|
|
|
#182719 - 2007-11-15 11:16 PM
Re: VBS to KIX
[Re: golfbuddy]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Here is a general start, however we probably have already written UDFs to obtain just about anything you want from the AD.
http://www.kixtart.or/udf
Example....
Dim $RootDSE, $strDomain, $strSamID
$WshShell = CreateObject("WScript.Shell")
;get logon SAM name
$strSamID = $WshShell.Environment("Process").Item("USERNAME")
;get domain naming context
$RootDSE = GetObject("LDAP://RootDSE")
$strDomain = $RootDSE.Get("DefaultNamingContext")
;open AD provider object
$objADOConnection = CreateObject("ADODB.Connection")
$objADOConnection.Open "Provider=ADsDSOObject;"
$objADOCommand = CreateObject("ADODB.Command")
$objADOCommand.ActiveConnection = ($objADOConnection)
$objADOCommand.Properties("Page Size") = 1000
$objADOCommand.Properties("Size Limit") = 1000
If @ERROR <> 0
"ERROR: Unable to open AD provider" ?
Quit(@ERROR)
EndIf
|
Top
|
|
|
|
#182727 - 2007-11-16 10:14 AM
Re: VBS to KIX
[Re: NTDOC]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
You can get the user object (and it's properties) very simply:
$oADInfo=CreateObject("ADSystemInfo")
$oUser=GetObject("LDAP://"+$oADInfo.UserName)
" Last login =" $oUser.LastLogin ?
"Last failed login =" $oUser.LastFailedLogin ?
" Bad login count=" $oUser.BadLoginCount ?
I don't recognise the properties that you are using though, are they some sort or proprietary extension?
Specifically I've not seen bcbsscPreviousBadLogonCount or bcbsscPreviousLogonDateString before, and I can't find any reference by googling.
|
Top
|
|
|
|
#182761 - 2007-11-17 11:31 PM
Re: VBS to KIX
[Re: Richard H.]
|
golfbuddy
Fresh Scripter
Registered: 2005-12-16
Posts: 12
|
Thanks for the information. Since I'm a newbie, I have a mscript.kix to run during logons and display logon information, how do I incorporate your sample into my script to display those information onto my message box?
Richard H. - They are proprietary extensions since we did not know where to look in AD.
Edited by golfbuddy (2007-11-17 11:46 PM)
|
Top
|
|
|
|
#182762 - 2007-11-17 11:48 PM
Re: VBS to KIX
[Re: golfbuddy]
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
Personal opinion, do not display anything during a logon, users just get annoyed and ignore it anyway's.
If you have to display the information however, then you can put the elements that you have collected into a messagebox quite readily.
MESSAGEBOX Action
Displays a standard dialog box in Windows.
Syntax
MESSAGEBOX ("message", "title", style, time-out)
Parameters
Message
The message to display in the dialog box.
Title
The title of the dialog box.
Style
Optional numeric expression that is the sum of values specifying the number and type of buttons to display, the icon style to use, the identity of the default button, and the modality. The following table illustrates the values used and the meaning of each group of values.
Buttons to display
Value Meaning 0 Display OK button only. 1 Display OK and Cancel buttons. 2 Display Abort, Retry, and Ignore buttons. 3 Display Yes, No, and Cancel buttons. 4 Display Yes and No buttons. 5 Display Retry and Cancel buttons.
Icon to display
Value Meaning 16 Stop symbol 32 Question mark 48 Exclamation mark 64 Information symbol
Default button
Value Meaning 0 First button is default. 256 Second button is default. 512 Third button is default.
Modality
Value Meaning 0 Application-modal. The user must respond to the message box before continuing work in the application. 4096 System-modal. All applications are suspended until the user responds to the message box.
When adding numbers to create a final value for the argument type, use only one number from each group. If style is omitted, a default value of 0 is assumed.
Time-out
Optional numeric expression representing the number of seconds after which to close the dialog box.
Note
The time-out feature only works if the MESSAGEBOX dialog box is the active window for the duration of the time-out. If the user switches away from KiXtart and activates another application, the MESSAGEBOX dialog box is not closed.
Remarks
MESSAGEBOX displays a maximum of 1024 characters in application-modal dialog boxes. Longer messages are truncated after the 1024th character. Message strings longer than 255 characters with no intervening spaces are truncated after the 255th character. For system-modal dialog boxes, the number of characters you can display depends on screen resolution and number of lines in the message.
MESSAGEBOX breaks lines automatically at the right edge of the dialog box. If you want to set line breaks yourself, place a linefeed (ANSI character 10) before the first character of the text that is to begin each new line.
Returns
The value returned by MESSAGEBOX indicates which button was selected, as shown in the following table.
Value Meaning -1 User did not respond to the dialog box within the specified time-out period. 1 OK button selected. 2 Cancel button selected. 3 Abort button selected. 4 Retry button selected. 5 Ignore button selected. 6 Yes button selected. 7 No button selected.
If the dialog box contains a Cancel button, pressing esc has the same effect as choosing Cancel.
Example
$Selection = MessageBox("Do you want to continue ?", "KiXtart", 36)
If $Selection = 6
? "Yes selected, continuing...."
Endif
_________________________
Today is the tomorrow you worried about yesterday.
|
Top
|
|
|
|
#182763 - 2007-11-18 12:00 AM
Re: VBS to KIX
[Re: Gargoyle]
|
golfbuddy
Fresh Scripter
Registered: 2005-12-16
Posts: 12
|
I do have a standard message box displaying common information about the logon. I want to add the display of 'lastlogon', 'lastbadlogon', and 'badlogoncount' onto my existing script.
Ok, I also just looked at 'how to use UDF' but just not getting it.
Thanks for the help.
Edited by golfbuddy (2007-11-18 12:04 AM)
|
Top
|
|
|
|
#182771 - 2007-11-18 12:32 PM
Re: VBS to KIX
[Re: golfbuddy]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Not having read the entire thread, my translation attempt (didn't test)
$WshShell = WScript.CreateObject("WScript.Shell")
;get logon SAM name
$strSamID = $WshShell.Environment("Process").Item("USERNAME")
;get domain naming context
$RootDSE = GetObject("LDAP://RootDSE")
$strDomain = $RootDSE.Get("DefaultNamingContext")
;open AD provider object
$objADOConnection = CreateObject("ADODB.Connection")
$objADOConnection.Open("Provider=ADsDSOObject;")
$objADOCommand = CreateObject("ADODB.Command")
$objADOCommand.ActiveConnection = $objADOConnection
$objADOCommand.Properties("Page Size").Value = 1000
$objADOCommand.Properties("Size Limit").Value = 1000
;If @ERROR <> 0
; ? "ERROR: Unable to open AD provider"
; Quit(1)
;EndIf
;get DistName for SamID
$objADOCommand.CommandText = "<LDAP://" + $strDomain + ">;(+(objectCategory=user)(sAMAccountName=" + $strSamID + "));distinguishedName;subtree"
$objADORecordset = $objADOCommand.Execute
If $objADORecordset.EOF
; ? "ERROR: Unable to find SamID"
Quit (1)
Else
@ERROR = 0
$objItem = GetObject("LDAP://" + FixLDAPQuery($objADORecordset.Fields("distinguishedName")))
If @ERROR <> 0
; ? "ERROR: Unable to find DistName"
Quit (1)
Else
$strBadLogonCount = $objItem.Get("bcbsscPreviousBadLogonCount")
$strLastLogon = Replace($objItem.Get("bcbsscPreviousLogonDateString"), Chr(34), "")
If $strBadLogonCount <> "" And $strLastLogon <> ""
$=MessageBox("Your last logon To AD was on " + $strLastLogon + "." + @CrLf + "There were " + $strBadLogonCount + " invalid logon attempts noted since your last logon.","Active Directory Security Notice")
Else
; ? "Data not valid"
EndIf
EndIf
EndIf
Function FixLDAPQuery($strIn)
$strIn = Replace($strIn, "'", "''")
$strIn = Replace($strIn, "\", "\\")
$strIn = Replace($strIn, "/", "\/")
$FixLDAPQuery = $strIn
EndFunction
Function Replace($string,$a,$b)
$Replace=Join(Split($string,$a),$b)
EndFunction
|
Top
|
|
|
|
#182799 - 2007-11-19 06:40 PM
Re: VBS to KIX
[Re: Arend_]
|
golfbuddy
Fresh Scripter
Registered: 2005-12-16
Posts: 12
|
Here is the message display requirement: User would be presented an information screen noting the last date the user had logged on and the number of bad attemps since the last logon date.
Hope this clear up some of my prior confussed verbiages.
Richard H. - I'd inserted your code into my script and I can see the output when running from DOS. I already have a message display other information from my script, how do I get this information to display in the same message box?
Apronk - I get an 'unexpected error!' on line 4. Any thought?
Thanks so much guys/gals.
Edited by golfbuddy (2007-11-19 06:51 PM)
|
Top
|
|
|
|
#182805 - 2007-11-20 08:23 AM
Re: VBS to KIX
[Re: Gargoyle]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Line 4 should probably be changed from:
$strSamID = $WshShell.Environment("Process").Item("USERNAME") To:
$strSamID = $WshShell.Environment("Process").Item("USERNAME").Value
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 436 anonymous users online.
|
|
|