Jump to content

Recommended Posts

Posted

Example Script:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a checkbox control.
    Local $idCheckbox = GUICtrlCreateCheckbox("Checkbox 1", 10, 10, 185, 25)
    GUICtrlCreateCheckbox("Checkbox 2", 10, 40, 185, 25)
    GUICtrlCreateCheckbox("Checkbox 3", 10, 70, 185, 25)
    GUICtrlCreateCheckbox("Checkbox 4", 10, 100, 185, 25)
    GUICtrlCreateCheckbox("Checkbox 5", 10, 130, 185, 25)

    ; Check all Checkboxes
    For $i = 1 to 5
        GUICtrlSetState($idCheckbox + $i - 1, $GUI_CHECKED)
    Next
    Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

That's a quick and dirty example. With a little bit of effort I could create the Checkbox Controls in a loop as well ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Well, there it is. A cringe but functional GUI that can write and read LogonHours to AD.

Maybe one day someone will turn this into a pretty GUI. It needs some error catching here and there as well. But it's a start.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <AD\AD.au3>

_AD_Open()
    $SUserID1 = @UserName
    $SUserID2 = @LogonDomain & "\" & @UserName
    $SUserId3 = @UserName & "@" & @LogonDNSDomain
    $SDNSDomain = $sAD_DNSDomain
    $SHostServer = $sAD_HostServer
    $SConfiguration = $sAD_Configuration

            Global $logonhours = _AD_GetObjectAttribute("Username", "LogonHours")
            ;MsgBox(0,"",$logonhours)

$Form1 = GUICreate("Test", 765, 437, 192, 124)

$checkboxStart = 100
$checkboxHorizontalgap = 25
$Checkbox1 = GUICtrlCreateCheckbox("", $checkboxStart, 70, 17, 17)
 GUICtrlSetState(-1, $GUI_CHECKED)
For $i = 1 to 23
   $checkboxStart = $checkboxStart + $checkboxHorizontalgap
   GUICtrlCreateCheckbox("", $checkboxStart, 70, 17, 17)
   GUICtrlSetState(-1, $GUI_CHECKED)
Next

$checkboxStart = 100
For $i = 1 to 24
   GUICtrlCreateCheckbox("", $checkboxStart, 120, 17, 17)
   GUICtrlSetState(-1, $GUI_CHECKED)
   $checkboxStart = $checkboxStart + $checkboxHorizontalgap
Next

$checkboxStart = 100
For $i = 1 to 24
   GUICtrlCreateCheckbox("", $checkboxStart, 170, 17, 17)
   GUICtrlSetState(-1, $GUI_CHECKED)
   $checkboxStart = $checkboxStart + $checkboxHorizontalgap
Next

$checkboxStart = 100
For $i = 1 to 24
   GUICtrlCreateCheckbox("", $checkboxStart, 220, 17, 17)
   GUICtrlSetState(-1, $GUI_CHECKED)
   $checkboxStart = $checkboxStart + $checkboxHorizontalgap
Next

$checkboxStart = 100
For $i = 1 to 24
   GUICtrlCreateCheckbox("", $checkboxStart, 270, 17, 17)
   GUICtrlSetState(-1, $GUI_CHECKED)
   $checkboxStart = $checkboxStart + $checkboxHorizontalgap
Next

$checkboxStart = 100
For $i = 1 to 24
   GUICtrlCreateCheckbox("", $checkboxStart, 320, 17, 17)
   GUICtrlSetState(-1, $GUI_CHECKED)
   $checkboxStart = $checkboxStart + $checkboxHorizontalgap
Next

$checkboxStart = 100
For $i = 1 to 24
   GUICtrlCreateCheckbox("", $checkboxStart, 370, 17, 17)
   GUICtrlSetState(-1, $GUI_CHECKED)
   $checkboxStart = $checkboxStart + $checkboxHorizontalgap
   Next

$labelstart = 100
$labelHorizontalgap = 24
For $i = 0 to 24
   GUICtrlCreateLabel($i, $labelstart, 30, 40, 17)
   $labelstart = $labelstart + $labelHorizontalgap
   Next

$Label1 = GUICtrlCreateLabel("Sunday", 8, 70, 40, 17)
$Label2 = GUICtrlCreateLabel("Monday", 8, 120, 42, 17)
$Label3 = GUICtrlCreateLabel("Tuesday", 8, 170, 45, 17)
$Label4 = GUICtrlCreateLabel("Wednesday", 8, 220, 61, 17)
$Label5 = GUICtrlCreateLabel("Thursday", 8, 270, 48, 17)
$Label6 = GUICtrlCreateLabel("Friday", 8, 320, 32, 17)
$Label7 = GUICtrlCreateLabel("Saturday", 8, 370, 46, 17)
$ButtonSave = GUICtrlCreateButton("Save", 632, 400, 121, 33)
$ButtonRead = GUICtrlCreateButton("Read", 100, 400, 121, 33)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $ButtonSave
            Dim $box[169]
         For $i = 1 to UBound($box) -1
            If GUICtrlRead($Checkbox1 + $i -1) = 4 then
               $box[$i] = 0
            Else
               $box[$i] = 1
EndIf
         Next
         Dim $HexArray[21]
         $count = 0
         For $i = 0 to UBound($HexArray) -2
         $byte = $box[$count + 9] & $box[$count + 8] & $box[$count + 7] & $box[$count + 6] & $box[$count + 5] & $box[$count + 4] & $box[$count + 3] & $box[$count + 2]
         $HexArray[$i] = BinaryToHex($byte)
         $count = $count + 8
      Next
     $byte = $box[1] & $box[168] & $box[167] & $box[166] & $box[165] & $box[164] & $box[163] & $box[162]
$HexArray[20] = BinaryToHex($byte)
         ;_ArrayDisplay($HexArray)
         Local $adstring = ""
For $i = 0 to UBound($HexArray) -1
   $adstring = $adstring & $HexArray[$i]
Next
$adstring = "0x" & $adstring
_AD_ModifyAttribute("Username", "LogonHours", Binary($adstring))
MsgBox(0, @error, $adstring)


      Case $ButtonRead
$HexFromAD = $logonhours; "0xFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F"
Dim $box[169]

;$byte = StringLeft(StringRight($HexFromAD ,42), 2)
$lastfirst = StringReverse(HexToBin(StringRight($HexFromAD, 2))) ;first checkbox is the last binary of the last byte
$box[1] = StringRight($lastfirst, 1)

;$reversedbyte = StringReverse(HexToBin($byte))

$count = 1
$count2 = 0
$count3 = 1
For $i = 1 to 21
   $count = $count + 2
   $byte = StringMid($HexFromAD ,$count, 2)
;ConsoleWrite($byte & @CRLF)
   $reversedbyte = StringReverse(HexToBin($byte))
;ConsoleWrite($reversedbyte & @CRLF)
For $j = 1 to 8
      $count3 = $count3 + 1
     $count2 = $count2 + 1
     If $count2 = 9 Then $count2 = 1
     $box[$count3] = StringMid($reversedbyte, $count2, 1)
     ;ConsoleWrite($count3 & @CRLF)
     If $count3 = 168 Then
        ExitLoop
        EndIf
   Next
Next
;_ArrayDisplay($box)

$count = 0
For $i = 1 to UBound($box) -1
   If $box[$i] = 1 Then
      $state = 1
   Else
      $state = 4
   EndIf
;ConsoleWrite($state & @CRLF)
 GUICtrlSetState($Checkbox1 + $count, $state)
 $count = $count + 1
Next

EndSwitch
 WEnd




 Func BinaryToHex($BinIn)
$Bits = StringSplit($BinIn,"")
$dec = 0
For $x = $Bits[0] To 1 Step -1
    $dec +=  (2^($Bits[0]-$x)) * $Bits[$x]
Next
$hex = Hex(int($dec))
;ConsoleWrite("bin:" & $BinIn & "  Dec:" & $dec & "   Hex:" & $Hex & @CRLF)
Return(StringRight($hex, 2))
EndFunc

Func HexToBin($i)
$j = StringSplit($i,"")
$output = ""
For $k = 1 To $j[0]
    Select
    Case $j[$k] = "A"
        $j[$k] = 10
    Case $j[$k] = "B"
        $j[$k] = 11
    Case $j[$k] = "C"
        $j[$k] = 12
    Case $j[$k] = "D"
        $j[$k] = 13
    Case $j[$k] = "E"
        $j[$k] = 14
    Case $j[$k] = "F"
        $j[$k] = 15
    EndSelect

    If $j[$k] >= 8 Then
        $j[$k] -= 8
        $output = $output & 1
    Else
        $output = $output & 0
    EndIf
    If $j[$k] >= 4 Then
        $j[$k] -= 4
        $output = $output & 1
    Else
        $output = $output & 0
    EndIf
    If $j[$k] >= 2 Then
        $j[$k] -= 2
        $output = $output & 1
    Else
        $output = $output & 0
    EndIf
    If $j[$k] >= 1 Then
        $j[$k] -= 1
        $output = $output & 1
    Else
        $output = $output & 0
    EndIf
Next
return $output
EndFunc

 

Edited by crackdonalds
Posted

I have streamlined the GUI part of your script a little bit :)

#include <GUIConstantsEx.au3>
#include <AD.au3>

_AD_Open()
Global $sUser2Process = @UserName ; Current User
Global $sLogonhours = _AD_GetObjectAttribute($sUser2Process, "LogonHours")

; Variables to position the Checkboxes
Global $iCB_LeftPos = 100
Global $iCB_TopPos = 70
Global $iCB_Width = 17
Global $iCB_Height = 17
Global $iCB_HorizontalGap = 9
Global $iCB_VerticalGap = 30 ; 33
; Variables to position the top labels
Global $iLabel_CurrentLeftPos = $iCB_LeftPos
Global $iLabel_TopPos = 10
Global $iLabel_Height = 57
; Variables for the left labels
Global $aWeekDays[] = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
Global $iLabelLeft_Left = 25
Global $iLabelLeft_Top = 70
Global $iLabelLeft_Width = 61
; Variables to position the buttons
Global $iBtn_Width = 120
Global $iBtn_Height = 33
Global $iBtn_TopPos = 387

; Create the GUI and the first checkbox
GUICreate("Active Directory LogonHours", 750, 437, 192, 124)
Global $Checkbox1 = GUICtrlCreateCheckbox("", $iCB_LeftPos, $iCB_TopPos, $iCB_Width, $iCB_Height)
GUICtrlSetState(-1, $GUI_CHECKED)
Global $iCB_CurrentLeftPos = $iCB_LeftPos + $iCB_Width + $iCB_HorizontalGap
Global $iCB_CurrentTopPos = $iCB_TopPos
For $i = 2 To 168
    GUICtrlCreateCheckbox("", $iCB_CurrentLeftPos, $iCB_CurrentTopPos, $iCB_Width, $iCB_Height)
    GUICtrlSetState(-1, $GUI_CHECKED)
    If Mod($i, 24) = 0 Then
        $iCB_CurrentLeftPos = $iCB_LeftPos
        $iCB_CurrentTopPos = $iCB_CurrentTopPos + $iCB_Height + $iCB_VerticalGap
    Else
        $iCB_CurrentLeftPos = $iCB_CurrentLeftPos + $iCB_Width + $iCB_HorizontalGap
    EndIf
Next
; Create the top labels
For $i = 0 To 23
    GUICtrlCreateLabel($i & @CRLF & "to" & @CRLF & $i + 1, $iLabel_CurrentLeftPos, $iLabel_TopPos, $iCB_Width, $iLabel_Height)
    $iLabel_CurrentLeftPos = $iLabel_CurrentLeftPos + $iCB_Width + $iCB_HorizontalGap
Next
; Create the left labels
$iCurrent_TopPos = $iLabelLeft_Top
For $i = 0 To 6
    GUICtrlCreateLabel($aWeekDays[$i], $iLabelLeft_Left, $iCurrent_TopPos, $iLabelLeft_Width, $iCB_Height)
    $iCurrent_TopPos += ($iCB_Height + $iCB_VerticalGap)
Next
$ButtonSave = GUICtrlCreateButton("Save", $iCB_LeftPos + 24 * $iCB_Width + 23 * $iCB_HorizontalGap - $iBtn_Width, $iBtn_TopPos, $iBtn_Width, $iBtn_Height)
$ButtonRead = GUICtrlCreateButton("Read", $iCB_LeftPos, $iBtn_TopPos, $iBtn_Width, $iBtn_Height)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonSave
            Dim $box[169]
            For $i = 1 To UBound($box) - 1
                If GUICtrlRead($Checkbox1 + $i - 1) = 4 Then
                    $box[$i] = 0
                Else
                    $box[$i] = 1
                EndIf
            Next
            Dim $HexArray[21]
            $count = 0
            For $i = 0 To UBound($HexArray) - 2
                $byte = $box[$count + 9] & $box[$count + 8] & $box[$count + 7] & $box[$count + 6] & $box[$count + 5] & $box[$count + 4] & $box[$count + 3] & $box[$count + 2]
                $HexArray[$i] = BinaryToHex($byte)
                $count = $count + 8
            Next
            $byte = $box[1] & $box[168] & $box[167] & $box[166] & $box[165] & $box[164] & $box[163] & $box[162]
            $HexArray[20] = BinaryToHex($byte)
            ;_ArrayDisplay($HexArray)
            Local $adstring = ""
            For $i = 0 To UBound($HexArray) - 1
                $adstring = $adstring & $HexArray[$i]
            Next
            $adstring = "0x" & $adstring
            _AD_ModifyAttribute($sUser2Process, "LogonHours", Binary($adstring))
            MsgBox(0, @error, $adstring)


        Case $ButtonRead
            $HexFromAD = $sLogonhours ; "0xFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7F"
            Dim $box[169]

            ;$byte = StringLeft(StringRight($HexFromAD ,42), 2)
            $lastfirst = StringReverse(HexToBin(StringRight($HexFromAD, 2))) ;first checkbox is the last binary of the last byte
            $box[1] = StringRight($lastfirst, 1)

            ;$reversedbyte = StringReverse(HexToBin($byte))

            $count = 1
            $count2 = 0
            $count3 = 1
            For $i = 1 To 21
                $count = $count + 2
                $byte = StringMid($HexFromAD, $count, 2)
                ;ConsoleWrite($byte & @CRLF)
                $reversedbyte = StringReverse(HexToBin($byte))
                ;ConsoleWrite($reversedbyte & @CRLF)
                For $j = 1 To 8
                    $count3 = $count3 + 1
                    $count2 = $count2 + 1
                    If $count2 = 9 Then $count2 = 1
                    $box[$count3] = StringMid($reversedbyte, $count2, 1)
                    ;ConsoleWrite($count3 & @CRLF)
                    If $count3 = 168 Then
                        ExitLoop
                    EndIf
                Next
            Next
            ;_ArrayDisplay($box)

            $count = 0
            For $i = 1 To UBound($box) - 1
                If $box[$i] = 1 Then
                    $state = 1
                Else
                    $state = 4
                EndIf
                ;ConsoleWrite($state & @CRLF)
                GUICtrlSetState($Checkbox1 + $count, $state)
                $count = $count + 1
            Next

    EndSwitch
WEnd

Func BinaryToHex($BinIn)
    $Bits = StringSplit($BinIn, "")
    $dec = 0
    For $x = $Bits[0] To 1 Step -1
        $dec += (2 ^ ($Bits[0] - $x)) * $Bits[$x]
    Next
    $hex = Hex(Int($dec))
    ;ConsoleWrite("bin:" & $BinIn & "  Dec:" & $dec & "   Hex:" & $Hex & @CRLF)
    Return (StringRight($hex, 2))
EndFunc   ;==>BinaryToHex

Func HexToBin($i)
    $j = StringSplit($i, "")
    $output = ""
    For $k = 1 To $j[0]
        Select
            Case $j[$k] = "A"
                $j[$k] = 10
            Case $j[$k] = "B"
                $j[$k] = 11
            Case $j[$k] = "C"
                $j[$k] = 12
            Case $j[$k] = "D"
                $j[$k] = 13
            Case $j[$k] = "E"
                $j[$k] = 14
            Case $j[$k] = "F"
                $j[$k] = 15
        EndSelect

        If $j[$k] >= 8 Then
            $j[$k] -= 8
            $output = $output & 1
        Else
            $output = $output & 0
        EndIf
        If $j[$k] >= 4 Then
            $j[$k] -= 4
            $output = $output & 1
        Else
            $output = $output & 0
        EndIf
        If $j[$k] >= 2 Then
            $j[$k] -= 2
            $output = $output & 1
        Else
            $output = $output & 0
        EndIf
        If $j[$k] >= 1 Then
            $j[$k] -= 1
            $output = $output & 1
        Else
            $output = $output & 0
        EndIf
    Next
    Return $output
EndFunc   ;==>HexToBin

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

NB.: Your script works when the week starts with Sunday. In a lot of countries the week starts with Monday.
I have found a VBS script to handle this problem: https://www.faq-o-matic.net/2010/03/17/anmeldezeiten-fr-ad-benutzer-per-skript-ausgeben/

The problem is discussed here as well: https://richardspowershellblog.wordpress.com/2012/01/26/setting-a-users-logon-hours/

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted
21 hours ago, water said:

I have streamlined the GUI part of your script a little bit :)

Cool :D

20 hours ago, water said:

NB.: Your script works when the week starts with Sunday. In a lot of countries the week starts with Monday.
I have found a VBS script to handle this problem: https://www.faq-o-matic.net/2010/03/17/anmeldezeiten-fr-ad-benutzer-per-skript-ausgeben/

The problem is discussed here as well: https://richardspowershellblog.wordpress.com/2012/01/26/setting-a-users-logon-hours/

Pity. I'll try to look into it tomorrow. gonna be annoying without system to test it on but we'll see how it goes.

Posted

I was wrong in my above posts.
The script does not fix the Sunday/Monday problem as start of the week.
It fixes the local time problem. AD returns all data in UTC. So your script has to take the local time offset into account.
At the moment I do not know how to determine the first day of the week for the local system.
Will do some more investigation.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Ah, I think the bytes are not stored differently in AD depending when the first day of the week is different. It's just that the first byte represents a different day. so it would be a matter of re-arranging the labels in the GUI so that it shows Monday on top and Sunday on the bottom. If that is the case then we only need a way to determine the first day of the week.

The time slots seem to have no problem. I'm at UTC +1 and checkboxes are filled correctly.

Posted
17 minutes ago, crackdonalds said:

If that is the case then we only need a way to determine the first day of the week.

That's how I understand it as well. But I haven't found a way to determine the first day of the week :(

 

18 minutes ago, crackdonalds said:

The time slots seem to have no problem. I'm at UTC +1 and checkboxes are filled correctly.

I wonder why it works for you because AD returns UTC. There needs to be some code to calculate the local time. Maybe it works by accident 🤔
Can you test in a time zone that is more than just +1 hour off UTC?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

I've tried multiple different timezones, up to +5 but the result stayed the same (correct result). Domain controller is also at +1

 

changing the first day of the week to monday on my system also didnt make any difference to the output of the script

Edited by crackdonalds
Posted

That's great. The VBS I posted before had to do take the bias into account.
Seems momething has changed.

Good job 👍🏻

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted
40 minutes ago, water said:

That's great. The VBS I posted before had to do take the bias into account.
Seems momething has changed.

Good job 👍🏻

yea I didn't really look at it. I wanted to try my own approach first and if I fail, look at their stuff. Luckily, now we don't have to deal with the timezones :D

Posted

:D 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • 2 months later...
Posted

Version 1.6.1.0 of the UDF has been released.

Please test before using in production!

For download please see my signature.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • 5 months later...
Posted

I find bug.

If the connection with AD ends between AD_Open and AD_ObjectExists, the script ends with an error:  Variable must by of type "Object".

In AD_Close missing:

If IsObj($__oAD_Command) Then $__oAD_Connection.Close()

+

$__oAD_Command = 0

In AD_ObjectExists missing:

If Not IsObj($__oAd_Command) Then Return SetError(1,0,0)

 

Posted

Why would you lose the connection to AD?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

It's important?

It happens sometimes.

I turned on several thousand stations via WakeOnLan and then different things happen. 😀 The script runs on startup.

 

Posted (edited)
10 hours ago, JKFN said:

I find bug.

 

8 hours ago, JKFN said:

It's important?

Yes, because before I start to modify my UDF I need to be sure it really is a bug.

If _AD_Open was successful then only _AD_Close can drop the $__oAD.Connection or $__oAD_Command object.
Do you always check the value of @error after _AD_Open?

I have added a check to make sure $__oAD_Connection is an object.

Can you please test?

; #FUNCTION# ====================================================================================================================
; Name...........: _AD_Close
; Description ...: Closes the connection established to Active Directory by _AD_Open.
; Syntax.........: _AD_Close()
; Parameters ....: None
; Return values .: Success - 1
;                  Failure - 0, sets @error to:
;                  |1 - Closing the connection to the AD failed. @extended returns the error code received by the COM error handler
;                  |2 - $__oAD_Connection is not an object
; Author ........: Jonathan Clelland
; Modified.......: water
; Remarks .......: Even if closing the connection wasn't successfull and @error is set all used variables have been reset.
; Related .......: _AD_Open
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _AD_Close()
    Local $iError = 0
    If IsObj($__oAD_Connection) Then
        $__oAD_Connection.Close() ; Close Connection
        If @error Then $iError = 1
    Else
        $iError = 2
    EndIf
    ; Reset all Global Variables
    $__iAD_Debug = 0
    $__sAD_DebugFile = @ScriptDir & "\AD_Debug.txt"
    $__oAD_MyError = 0
    $__oAD_Connection = 0
    $sAD_DNSDomain = ""
    $sAD_HostServer = ""
    $sAD_Configuration = ""
    $__oAD_OpenDS = 0
    $__oAD_RootDSE = 0
    $__oAD_Command = 0
    $__oAD_Bind = 0
    $__bAD_BindFlags = 0
    $sAD_UserId = ""
    $sAD_Password = ""
    If $iError <> 0 Then Return SetError($iError, @error, 0) ; Error returned by connection close
    Return 1
EndFunc   ;==>_AD_Close

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

I fixed it myself and wrote how. And yes, it's tested.

The main problem is in the func _AD_ObjectExists.

; #FUNCTION# ====================================================================================================================
; Name...........: _AD_ObjectExists
; Description ...: Returns 1 if exactly one object exists for the given property in the local Active Directory Tree.
; Syntax.........: _AD_ObjectExists([$sObject = @UserName[, $sProperty = ""]])
; Parameters ....: $sObject   - [optional] Object (user, computer, group, OU) to check (default = @UserName)
;                  $sProperty - [optional] Property to check. If omitted the function tries to determine whether to use sAMAccountname or FQDN
; Return values .: Success - 1, Exactly one object exists for the given property in the local Active Directory Tree
;                  Failure - 0, sets @error to:
;                  |1 - No object found for the specified property
;                  |x - More than one object found for the specified property. x is the number of objects found
; Author ........: Jonathan Clelland
; Modified.......: water
; Remarks .......: Checking on a computer account requires a "$" (dollar) appended to the sAMAccountName.
;                  To check the existence of an OU use the FQDN of the OU as first parameter because an OU has no SamAccountName.
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _AD_ObjectExists($sObject = @UserName, $sProperty = "")
    If $sObject = Default Then $sObject = @UserName
    If $sProperty = "" Or $sProperty = Default Then
        $sProperty = "samAccountName"
        If StringMid($sObject, 3, 1) = "=" Then $sProperty = "distinguishedName"
    EndIf
    If IsObj($__oAD_Command) Then
        $__oAD_Command.CommandText = "<LDAP://" & $sAD_HostServer & "/" & $sAD_DNSDomain & ">;(" & $sProperty & "=" & $sObject & ");ADsPath;subtree"
        Local $oRecordSet = $__oAD_Command.Execute ; Retrieve the ADsPath for the object, if it exists
        If IsObj($oRecordSet) Then
            If $oRecordSet.RecordCount = 1 Then
                Return 1
            ElseIf $oRecordSet.RecordCount > 1 Then
                Return SetError($oRecordSet.RecordCount, 0, 0)
            Else
                Return SetError(1, 0, 0)
            EndIf
        Else
            Return SetError(1, 0, 0)
        EndIf
    Else
        Return SetError(1, 0, 0)
    EndIf

EndFunc   ;==>_AD_ObjectExists

+ The solution _AD_Close() see above.

Posted

But I still do not understand where $__oAD_Command should get reset.
The UDF is designed that _AD_Open creates the connection to a domain controller and_AD_Close drops this connection and resets all variables.
Even when the connection to the DC drops for any reason variable $__oAD_Command still holds the (then invalid) object. But it should still be an object and hence raise other error messages.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • 1 year later...
Posted

Version 1.6.3.0 of the UDF has been released.

Please test before using in production!

For download please see my signature.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...