Page 1 of 1 1
Topic Options
#179963 - 2007-08-30 08:25 AM Convert vbs Script to kix
Tömu Offline
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_ Moderator Offline
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.

 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
#179967 - 2007-08-30 10:17 AM Re: Convert vbs Script to kix [Re: Arend_]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Can a moderator move this to the basic scripting forum as this not a User Defined Function?
Top
#179968 - 2007-08-30 10:20 AM Re: Convert vbs Script to kix [Re: Witto]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
 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

Top
#179972 - 2007-08-30 11:42 AM Re: Convert vbs Script to kix [Re: Witto]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
 Originally Posted By: Witto
Can a moderator move this to the basic scripting forum as this not a User Defined Function?


Done..
_________________________



Top
#179995 - 2007-08-30 04:29 PM Re: Convert vbs Script to kix [Re: Jochen]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
 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....

Top
#180013 - 2007-08-31 09:53 AM Re: Convert vbs Script to kix [Re: Arend_]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
 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
_________________________



Top
#180041 - 2007-09-01 11:11 AM Re: Convert vbs Script to kix [Re: Jochen]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
\:D
Top
#180053 - 2007-09-03 12:59 AM Re: Convert vbs Script to kix [Re: Arend_]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
why should it be moved?
it's in com-forum already! \:o
_________________________
!

download KiXnet

Top
#180058 - 2007-09-03 10:02 AM Re: Convert vbs Script to kix [Re: Lonkero]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Now it is, yeah :P
Went from UDF > Basic > COM Scripting

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.059 seconds in which 0.024 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org