Tömu
(Lurker)
2007-08-30 08:25 AM
Convert vbs Script to kix

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


Arend_
(MM club member)
2007-08-30 09:29 AM
Re: Convert vbs Script to kix

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.

 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 = ""


Witto
(MM club member)
2007-08-30 10:17 AM
Re: Convert vbs Script to kix

Can a moderator move this to the basic scripting forum as this not a User Defined Function?

Arend_
(MM club member)
2007-08-30 10:20 AM
Re: Convert vbs Script to kix

 Originally Posted By: Witto
Can a moderator move this to the basic scripting forum as this not a User Defined Function?

Haw, didn't even see that \:\)
Should move to Com Scripting


JochenAdministrator
(KiX Supporter)
2007-08-30 11:42 AM
Re: Convert vbs Script to kix

 Originally Posted By: Witto
Can a moderator move this to the basic scripting forum as this not a User Defined Function?


Done..


Arend_
(MM club member)
2007-08-30 04:29 PM
Re: Convert vbs Script to kix

 Originally Posted By: Jochen
 Originally Posted By: Witto
Can a moderator move this to the basic scripting forum as this not a User Defined Function?


Done..

Should be moved to the "COM Scripting" forum....


JochenAdministrator
(KiX Supporter)
2007-08-31 09:53 AM
Re: Convert vbs Script to kix

 Originally Posted By: apronk
 Originally Posted By: Jochen
 Originally Posted By: Witto
Can a moderator move this to the basic scripting forum as this not a User Defined Function?


Done..

Should be moved to the "COM Scripting" forum....


Oh well, you're right


Arend_
(MM club member)
2007-09-01 11:11 AM
Re: Convert vbs Script to kix

\:D

LonkeroAdministrator
(KiX Master Guru)
2007-09-03 12:59 AM
Re: Convert vbs Script to kix

why should it be moved?
it's in com-forum already! \:o


Arend_
(MM club member)
2007-09-03 10:02 AM
Re: Convert vbs Script to kix

Now it is, yeah :P
Went from UDF > Basic > COM Scripting