#179963 - 2007-08-30 08:25 AM
Convert vbs Script to kix
|
Tömu
Lurker
Registered: 2007-08-30
Posts: 1
|
Hello together
I have a vbs Script that i want to convert into a kix script. I used the vbs2kix UDF but this doesn't convert all the code into kix. Can someone help me?
The vbs code is the following:
********************************************************************** On Error Resume Next
'set variables Dim objConnection, objCommand, objRootDSE, strDNsndgov, strDNgsvbs Dim strFilter, strQuery, objRecordSet, objArgs Dim objShell, WSHNetwork, strStatus, IE
Dim objUserGSVBS, objUserSND, oldpasswd, newpasswd, userstring Const wshYes = 6 Const wshNo = 7 Const wshYesNoDialog = 4 Const wshQuestionMark = 32
Set objShell = CreateObject("Wscript.Shell") Set WSHShell = WScript.CreateObject("WScript.Shell") Set WSHNetwork = WScript.CreateObject("WScript.Network") 'userstring = WSHNetwork.UserName userstring = "test_cfb"
'Connect to AD Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOOBject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection 'strBase = "<LDAP://rintra.ruag.com>" strBase = "<LDAP://tsb.ruag.com>"
'Set Filter to samAccountName strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" & userstring & "))"
'Set Attribute to DN strAttributes = "distinguishedName,sn,GivenName"
'Find DN strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" objCommand.CommandText = strQuery objCommand.Properties("Page Size") = 99999 objCommand.Properties("Timeout") = 300 objCommand.Properties("Cache Results") = False Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Do Until objRecordSet.EOF strDNsndgov = objRecordSet.Fields("distinguishedName") strDNname = objRecordSet.Fields("sn") strDNvorname = objRecordSet.Fields("GivenName") objRecordSet.MoveNext Loop
'======================================== ' First, get the domain policy. '======================================== Dim oDomain Dim oUser Dim maxPwdAge Dim numDays Dim pass_last_change, pass_expire 'wscript.echo strDNsndgov 'strDomainDN = "RINTRA.RUAG.COM" strDomainDN = "TSB.RUAG.COM" strUserDN = strDomainDN & "/" & strDNsndgov wscript.echo strUserDN Set oDomain = GetObject("LDAP://" & strDomainDN) Set maxPwdAge = oDomain.Get("maxPwdAge")
'======================================== ' Calculate the number of days that are ' held in this value. '======================================== numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + _ maxPwdAge.LowPart) / CCur(-864000000000) WScript.Echo "Maximum Password Age: " & numDays '======================================== ' Determine the last time that the user ' changed his or her password. '======================================== Set oUser = GetObject("LDAP://" & strUserDN)
'======================================== ' Add the number of days to the last time ' the password was set. '======================================== whenPasswordExpires = DateAdd("d", numDays, oUser.PasswordLastChanged) 'WScript.Echo "Password Last Changed: " & oUser.PasswordLastChanged 'WScript.Echo "Password Expires On: " & whenPasswordExpires pass_last_change = FormatDateTime(oUser.PasswordLastChanged, 2) pass_expire = FormatDateTime(whenPasswordExpires, 2) WScript.Echo "Password Expires On: " & pass_expire datum = DateDiff("d",now,pass_expire) wscript.echo datum If datum < 13 Then WScript.Echo("Password expires in Days: " & DateDiff("d",now,pass_expire)) WScript.Quit(1) Else Wscript.echo "Passwort noch nicht unter 12 Tagen" WScript.Quit(0) End If '======================================== ' Clean up. '======================================== Set oUser = Nothing Set maxPwdAge = Nothing
'Close AD Connection objConnection.Close
'Clear Variables Set objConnection = Nothing Set objCommand = Nothing Set objRootDSE = Nothing Set objRecordSet = Nothing **********************************************************************
Thanks... bye tömu
|
Top
|
|
|
|
#179965 - 2007-08-30 09:29 AM
Re: Convert vbs Script to kix
[Re: Tömu]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Hi, next time use [ code ] tags, I've converted your code to kix however it will not work because some functions are not defined such ass "CCur" and "DateDiff" in the original code.
;set variables
Dim $objConnection, $objCommand, $objRootDSE, $strDNsndgov, $strDNgsvbs
Dim $strFilter, $strQuery, $objRecordSet, $objArgs
Dim $objShell, $WSHNetwork, $strStatus, $IE
Dim $objUserGSVBS, $objUserGSVBS, $oldpasswd, $newpasswd, $userstring
$wshYes = 6
$wshNo = 7
$wshYesNoDialog = 4
$wshQuestionMark = 32
$objShell = CreateObject("Wscript.Shell")
$WSHShell = CreateObject("WScript.Shell")
$WSHNetwork = CreateObject("WScript.Network")
;$userstring = $WSHNetwork.UserName
$userstring = "test_cfb"
;Connect to AD
$objConnection = CreateObject("ADODB.Connection")
$objCommand = CreateObject("ADODB.Command")
$objConnection.Provider = "ADsDSOOBject"
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection
;$strBase = "<LDAP://rintra.ruag.com>"
$strBase = "<LDAP://tsb.ruag.com>"
;Set Filter to samAccountName
$strFilter = "(+(objectCategory=person)(objectClass=user)(sAMAccountName=" + $userstring + "))"
;Set Attribute to DN
$strAttributes = "distinguishedName,sn,GivenName"
;Find DN
$strQuery = $strBase + ";" + $strFilter + ";" + $strAttributes + ";subtree"
$objCommand.CommandText = $strQuery
$objCommand.Properties("Page Size").Value = 99999
$objCommand.Properties("Timeout").Value = 300
$objCommand.Properties("Cache Results").Value = 0
$objRecordSet = $objCommand.Execute
$objRecordSet.MoveFirst
Do Until $objRecordSet.EOF
$strDNsndgov = $objRecordSet.Fields("distinguishedName").Value
$strDNname = $objRecordSet.Fields("sn").Value
$strDNvorname = $objRecordSet.Fields("GivenName").Value
$objRecordSet.MoveNext
Loop
;========================================
; First, get the domain policy.
;========================================
Dim $oDomain
Dim $oUser
Dim $maxPwdAge
Dim $numDays
Dim $pass_last_change, $pass_expire
;wscript.echo $strDNsndgov
;$strDomainDN = "RINTRA.RUAG.COM"
$strDomainDN = "TSB.RUAG.COM"
$strUserDN = $strDomainDN + "/" + $strDNsndgov
? $strUserDN
$oDomain = GetObject("LDAP://" + $strDomainDN)
$maxPwdAge = $oDomain.Get("maxPwdAge")
;========================================
; Calculate the number of days that are
; held in this value.
;========================================
$numDays = CCur(($maxPwdAge.HighPart * 2 ^ 32) + $maxPwdAge.LowPart) / CCur(-864000000000)
? "Maximum Password Age: " + $numDays
;========================================
; Determine the last time that the user
; changed his or her password.
;========================================
$oUser = GetObject("LDAP://" + $strUserDN)
;========================================
; Add the number of days to the last time
; the password was set.
;========================================
$whenPasswordExpires = DateAdd("d", $numDays, $oUser.PasswordLastChanged)
;? "Password Last Changed: " + $oUser.PasswordLastChanged
;? "Password Expires On: " + $whenPasswordExpires
$pass_last_change = FormatDateTime($oUser.PasswordLastChanged, 2)
$pass_expire = FormatDateTime($whenPasswordExpires, 2)
? "Password Expires On: " + $pass_expire
$datum = DateDiff("d",now,$pass_expire)
? $datum
If $datum < 13
? "Password expires in Days: " + DateDiff("d",now,$pass_expire)
Exit 1
Else
? "Passwort noch nicht unter 12 Tagen"
Exit 0
EndIf
;========================================
; Clean up.
;========================================
$oUser = ""
$maxPwdAge = ""
;Close AD Connection
$objConnection.Close
;Clear Variables
$objConnection = ""
$objCommand = ""
$objRootDSE = ""
$objRecordSet = ""
|
Top
|
|
|
|
#180041 - 2007-09-01 11:11 AM
Re: Convert vbs Script to kix
[Re: Jochen]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 259 anonymous users online.
|
|
|