NiceBoy1234

Autoit modification date

9 posts in this topic

#1 ·  Posted (edited)

I am trying to dynamically get folders and their modification date, I was orientated by this:

; Initial Launch, grab current GetTime
$file1_1 = FileGetTime("X:\aescripts\testimg", 0, 1)

Timecheck()

Func Timecheck()

      $file1_2 = FileGetTime("X:\test\testimg", 0, 1)

      If $file1_1 == $file1_2 Then
         ConsoleWrite("Folder 1 not modified" & @CRLF);
      ElseIf $file1_1 <> $file1_2 Then
         ConsoleWrite("Folder 1 modified" & @CRLF)
      EndIf

; Initial Launch, grab current GetTime
$file1_1 = FileGetTime("X:\test\testimg", 0, 1)

EndFunc

; Initial Launch, grab current GetTime
$file1_1 = FileGetTime("X:\test\testimg", 0, 1)

While 1
    Sleep(5000)
    Timecheck()
WEnd


That works, but it is not dynamic.

So I did code following but it does not work properly.

 

   Local $sFootage_01 = "Z:\Footage\ClothImgs\"    

      Local $aFileListFootageFolder_01 = _FileListToArray($sFootage_01, "*")

      ; Initial Launch, grab current GetTime
      For $i = 0 To UBound($aFileListFootageFolder_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolder_01[$i]
         $getTimeNewFootageFolderInit_01 = FileGetTime($newFootageFolder_01, 0, 1)
         ConsoleWrite("First Filename " & $newFootageFolder_01 & @CRLF)
      Next

   Func Timecheck()

      Local $aFileListFootageFolderRe_01 = _FileListToArray($sFootage_01, "*")

      If @error = 1 Then
         ConsoleWrite("not valid path" & @CRLF)
         Exit
      EndIf
      If @error = 4 Then
         ConsoleWrite("could not find any data" & @CRLF)
         Exit
      EndIf

      For $i = 0 To UBound($aFileListFootageFolderRe_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolderRe_01[$i]
         ConsoleWrite("ArrH " & $aFileListFootageFolderRe_01[$i] & @CRLF)
         $getTimeNewFootageFolder_01 = FileGetTime($newFootageFolder_01, 0, 1)
         ConsoleWrite("ZZZ First Filename " & $newFootageFolder_01 & @CRLF)

         Local $aGetTimeNewFootageFolder_01 = _FileListToArray($newFootageFolder_01, "*")
         For $u = 0 To UBound($aGetTimeNewFootageFolder_01) -1
             If $getTimeNewFootageFolderInit_01 == $getTimeNewFootageFolder_01 Then
                ConsoleWrite($newFootageFolder_01 & " has not been changed" & @CRLF)
             ElseIf($getTimeNewFootageFolderInit_01 <> $getTimeNewFootageFolder_01 And $aGetTimeNewFootageFolder_01[0] == 11) Then
                ConsoleWrite("File 1 has been changed and has " & $aGetTimeNewFootageFolder_01[0] & " images" & @CRLF)
                ConsoleWrite("Time 1.1: " & $getTimeNewFootageFolderInit_01 & @CRLF & "1.2: " & $getTimeNewFootageFolder_01 & @CRLF)
                WinKill($hWnd, "")
                Sleep(8000)
                RunCm()
                ListFolders()
                ExitLoop
             ElseIf($getTimeNewFootageFolderInit_01 <> $getTimeNewFootageFolder_01 And $aGetTimeNewFootageFolder_01[0] <> 11) Then
                ConsoleWrite("Path " & $newFootageFolder_01 & " modification date has changed, number of images: " & $aGetTimeNewFootageFolder_01[0] & " files/folders" & @CRLF)
             Else
                ConsoleWrite("Else Statement" & @CRLF)
             EndIf
         Next
      Next


      $aFileListFootageFolderInit_01 = _FileListToArray($sFootage_01, "*")

      ; Initial Launch, grab current GetTime
      For $i = 0 To UBound($aFileListFootageFolder_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolder_01[$i]
         $getTimeNewFootageFolderInit_01 = FileGetTime($newFootageFolder_01, 0, 1)
      Next
   EndFunc

      $aFileListFootageFolderInit_01 = _FileListToArray($sFootage_01, "*")

      ; Initial Launch, grab current GetTime
      For $i = 0 To UBound($aFileListFootageFolder_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolder_01[$i]
         $getTimeNewFootageFolderInit_01 = FileGetTime($newFootageFolder_01, 0, 1)
      Next

   ; check every 5s if files in footage folder has been changed
   While 1
      Sleep(5000)
      ConsoleWrite("While Loop " & @CRLF)
      Timecheck()
   WEnd

It always goes to the first ElseIf Statement and tells me that the files have been changed.
So I printed out the modification dates and this varaible shows correctly the current modification date of the subfolder $getTimeNewFootageFolder_01 and this
$getTimeNewFootageFolder_01 does show another modification date of another folder which I do not understand.

Again the code (not dynmaic one) above works, but trying to make it dynmacly did not work.
 

Edited by NiceBoy1234

Share this post


Link to post
Share on other sites



Not exactly sure what you are wanting to do?
Are you just wanting the dates of all files in a folder?
To do a comparison with the same files in another folder?

And to be honest, I prefer things simple, so big long names and busy looking code does my head in.
I keep things simple, that I can understand at a glance, even if that means using extra steps and lines.
Similar names also don't help, as it takes me away, checking what they are all the time.
None of that is intuitive to holding an overall picture/map/structure in one's head.

But each to their own.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I Basically want to check if the modification date of a folder has changed.
I tried to make the code above dynamically, if you would copy the first part of the code and change the path you may would understand it better.

Edited by NiceBoy1234

Share this post


Link to post
Share on other sites

Not sure what you mean by dynamic?

Why are you checking every 5 seconds?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Are you wanting to continually monitor the same folder indefinitely for changes?

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I check every 5 seconds, because if the user creates another folder, that folder gets checked to.
I check for folders in the following path :

Z:\Footage\ClothImgs\

If there are folder I check for their file size ( in this case they got images ) and the modification date.
So if I delete a file or something similiar the modification date of that folder changes and I will do something ...

So Yeah one could say that I want to check indefinitely the folder/s for changes.

Edited by NiceBoy1234

Share this post


Link to post
Share on other sites

By my reckoning, you keep assigning to the same variable ($getTimeNewFootageFolderInit_01) for every sub-folder. And perhaps you also need to use a backslash between source folder and sub-folder? (i.e. $sFootage_01 & "\" & $aFileListFootageFolder_01[$i])

; Initial Launch, grab current GetTime
      For $i = 0 To UBound($aFileListFootageFolder_01) - 1
         $newFootageFolder_01 = $sFootage_01 & $aFileListFootageFolder_01[$i]
         $getTimeNewFootageFolderInit_01 = FileGetTime($newFootageFolder_01, 0, 1)
         ConsoleWrite("First Filename " & $newFootageFolder_01 & @CRLF)
      Next

Those two things strike me as issues that need dealing with.

But I don't know, I'm getting awfully muddled by your naming convention, which makes it hard to troubleshoot. It seems to me you might be getting things mixed up, but I'm not really sure.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Results of three hours working with less brainy brain:

File Monitor!

#include <File.au3>
#include <WinAPI.au3>
#include <WinAPIFiles.au3>

Opt('TrayAutoPause', 0)

Global Const $sPathtoCheck = @ScriptDir ; "Z:\Footage\ClothImgs\"

If Not FileExists($sPathtoCheck) Then
    DirCreate($sPathtoCheck)
    If Not FileExists($sPathtoCheck) Then
        MsgBox(48, 'Error', 'Unable to create folder.')
        Exit
    EndIf
EndIf

FileChangeDir($sPathtoCheck)
OnAutoItExitRegister('_OnExit')

Global $g_ahObj[2]
$g_ahObj[0] = _WinAPI_FindFirstChangeNotification($sPathtoCheck, $FILE_NOTIFY_CHANGE_FILE_NAME)
$g_ahObj[1] = _WinAPI_FindFirstChangeNotification($sPathtoCheck, $FILE_NOTIFY_CHANGE_LAST_WRITE)

If (Not $g_ahObj[0]) Or (Not $g_ahObj[1]) Then
    MsgBox(48, 'Error', 'Unable to create change notification.')
    Exit
EndIf

Local $tObjs = DllStructCreate('ptr;ptr')
Local $paObj = DllStructGetPtr($tObjs)
DllStructSetData($tObjs, 1, $g_ahObj[0])
DllStructSetData($tObjs, 2, $g_ahObj[1])

Global $aListFileChecked, $aListTimeFileChecked, $sOldFileTime
Global $aListFileToCheck, $aListTimeFileToCheck, $sCurFileTime
Global Const $aArray[1] = [0]

$aListFileChecked = _FileListToArray($sPathtoCheck, "*", $FLTA_FILES)
If Not IsArray($aListFileChecked) Then $aListFileChecked = $aArray
For $i = 1 To $aListFileChecked[0] - 1
    $aListFileChecked[$i] = $aListFileChecked[$i] & "|" & FileGetTime($aListFileChecked[$i], $FT_MODIFIED, $FT_STRING)
    ConsoleWrite("+ File: " & _RetunFileOrTime($aListFileChecked[$i], 0) & "  - Time: " & _RetunFileOrTime($aListFileChecked[$i], 1) & @CRLF)
Next

TraySetToolTip("Right click to me and Click Exit to Exit")
TrayTip("File Monitor", "Right click to TrayIcon and Click Exit to Exit", 3)

Local $iID
While 1
    Sleep(1)
    $iID = _WinAPI_WaitForMultipleObjects(2, $paObj, 0, 0)
    If $iID = 0 Or $iID = 1 Then
        _CheckFileTime()
        If Not _WinAPI_FindNextChangeNotification($g_ahObj[$iID]) Then
            MsgBox(48, 'Error', 'Unexpected error.')
            _OnExit()
        EndIf
    Else
        ContinueLoop
    EndIf
WEnd

Func _RetunFileOrTime($FileAndTime, $Type = 0); 1 Time
    ;ConsoleWrite("> " &$FileAndTime&" - "&$Type& @CRLF)
    If Not StringInStr($FileAndTime, "|") Then Return $FileAndTime
    If $Type <> 1 Then Return StringLeft($FileAndTime, StringInStr($FileAndTime, "|") - 1)
    Return StringTrimLeft($FileAndTime, StringInStr($FileAndTime, "|"));TIME
EndFunc   ;==>_RetunFileOrTime

Func _CheckFileTime()
    ConsoleWrite("- Some file is changed: Modified/Created/Deleted " & @CRLF)
    $aListFileToCheck = _FileListToArray($sPathtoCheck, "*", $FLTA_FILES, False)
    If Not IsArray($aListFileToCheck) Then $aListFileToCheck = $aArray
    For $i = 1 To $aListFileToCheck[0] - 1
        $aListFileToCheck[$i] = $aListFileToCheck[$i] & "|" & FileGetTime($aListFileToCheck[$i], $FT_MODIFIED, $FT_STRING)
        ;ConsoleWrite("! File: " &_RetunFileOrTime($aListFileToCheck[$i],0)&"  - Time: "& _RetunFileOrTime($aListFileToCheck[$i],1)& @CRLF)
        For $x = 1 To $aListFileChecked[0] - 1
            If _RetunFileOrTime($aListFileToCheck[$i], 0) = _RetunFileOrTime($aListFileChecked[$x], 0) Then
                If _RetunFileOrTime($aListFileToCheck[$i], 1) <> _RetunFileOrTime($aListFileChecked[$x], 1) Then
                    ConsoleWrite("! File is changed: " & _RetunFileOrTime($aListFileToCheck[$i], 0) & @CRLF)
                    ExitLoop
                EndIf
            EndIf
        Next
    Next
    $aListFileChecked = $aListFileToCheck
EndFunc   ;==>_CheckFileTime

Func _OnExit()
    For $i = 0 To 1
        If $g_ahObj[$i] Then
            _WinAPI_FindCloseChangeNotification($g_ahObj[$i])
        EndIf
    Next
    ;DirRemove($sPathtoCheck, 1)
EndFunc   ;==>_OnExit

 

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

.

Edited by NiceBoy1234

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • ur
      By ur
      I have date in the string format as "DD-MM-YYYY".
       
      I need to get yesterday's date from it.
      I tried converting this from _DateTimeFormat but not working.
      Is there any direct UDF available to get this.?
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
    • JSmith312
      By JSmith312
      Hello Everyone! 
      I'm attempting to create a checklist app that performs other functions. For performance, I would like to check the box, then have the button to the right enabled. After that button is pressed, the second checkbox is enabled, and ready to be checked, allowing the second button to be pressed. After the second button is pressed, the completion/exit button is enabled/shown. I have my code that currently creates the GUI, creates the checkbox, but when you check it it enables the button and the next checkbox. Can't seem to figure out a Case for GUISetOnEvent. Any assistance would be appreciated!
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <MsgBoxConstants.au3> ; Below is the GUI interface _DeploymentProcess() Func _DeploymentProcess() $aStep1 = GUICreate("Deployment Process", 475, 345, 500, 175) $CBcStep1 = GUICtrlCreateCheckbox("1. Step 01.", 15, 25, 300, 25) $BTNS1 = GUICtrlCreateButton("Email 01", 365, 25, 90, 20) $CBcStep2 = GUICtrlCreateCheckbox("2. Step 02.", 15, 50, 300, 25) $BTNS2 = GUICtrlCreateButton("Email 02", 365, 50, 90, 20) GUICtrlSetState($CBcStep2, $GUI_DISABLE) GUICtrlSetState($BTNS1, $GUI_DISABLE) $CBcStep3 = GUICtrlCreateButton("Hurray! You're Complete!", 85, 276, 300, 60) GUICtrlSetState($CBcStep3, $GUI_SHOW) ; Below are the button and checkbox enables/disables. GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($aStep1) Return ; Step 1 Case $CBcStep1 If GUICtrlRead($CBcStep1) = $GUI_CHECKED Then GUICtrlSetState($BTNS1, $GUI_ENABLE) GUICtrlSetState($CBcStep2, $GUI_ENABLE) Else GUICtrlSetState($BTNS1, $GUI_DISABLE) GUICtrlSetState($CBcStep2, $GUI_DISABLE) EndIf ; Step 2 Case $CBcStep2 If GUICtrlRead($CBcStep2) = $GUI_CHECKED Then GUICtrlSetState($BTNS2, $GUI_ENABLE) GUICtrlSetState($CBcStep3, $GUI_ENABLE) Else GUICtrlSetState($BTNS2, $GUI_DISABLE) GUICtrlSetState($CBcStep3, $GUI_DISABLE) EndIf Case $CBcStep3 If GUICtrlRead($CBcStep2) = $GUI_CHECKED Then GUICtrlSetState($BTNS10, $GUI_ENABLE) GUICtrlSetState($CBcStep3, $GUI_SHOW) Else GUICtrlSetState($CBcStep3, $GUI_EVENT_CLOSE) EndIf Case $GUI_EVENT_CLOSE, $CBcStep3 #comments-end Exit EndSwitch WEnd EndFunc  
    • ur
      By ur
      In some systems the date is displayed in the Taskbar as
      10-01-2018
      And in some systems it is like, 1/10/2018
      And in some it is, 10-Jan-2018
      And in different formats.
       
      I wrote my code to convert 1/10/2018 to 10-01-2018
      Func TodaysDate() $NewDate = _DateTimeFormat(_NowCalcDate(),1) $Array = StringSplit( $NewDate , ',' ) _ArrayDelete($Array, 0) _ArrayDelete($Array, 0) $Array1 = StringSplit($Array[0],' ') RemoveEmptyArrayLines($Array1) ;Will return the present day's date with format dd-mmm-yyyy ;$Date = StringStripWS($Array1[2]&"-"&StringLeft($Array1[1], 3)&"-"&$Array[1], $STR_STRIPALL) $Date = StringStripWS($Array1[2]&"-"&changeDateformat(StringLeft($Array1[1], 3))&"-"&$Array[1], $STR_STRIPALL) return $Date EndFunc Func RemoveEmptyArrayLines(ByRef $arrLines) $intCount = 1 While $intCount < UBound($arrLines) $arrLines[$intCount] = StringStripWS($arrLines[$intCount],$STR_STRIPLEADING + $STR_STRIPTRAILING) If StringLen($arrLines[$intCount])=0 Then _ArrayDelete($arrLines, $intCount) $intCount = $intCount - 1 EndIf $intCount = $intCount + 1 WEnd EndFunc ;To convert mmm to mm format Func changeDateformat($sText) Local $sMsg = StringStripWS($sText, $STR_STRIPALL) Switch $sMsg Case "Jan" $sMsg = "01" Case "Feb" $sMsg = "02" Case "Mar" $sMsg = "03" Case "Apr" $sMsg = "04" Case "May" $sMsg = "05" Case "Jun" $sMsg = "06" Case "Jul" $sMsg = "07" Case "Aug" $sMsg = "08" Case "Sep" $sMsg = "09" Case "Oct" $sMsg = "10" Case "Nov" $sMsg = "11" Case "Dec" $sMsg = "12" EndSwitch return $sMsg EndFunc But again it will work on machines only with 1/10/2018.
      Is there any direct function which will give only in the format 10-01-2018, whatever the system settings is.?
      I tried all the arguments for _DateTimeFormat, but showing machine dependent settings only.
      Google given these two links in AutoIT but these are also for specific formats only,like mine.
       
      Please suggest.
    • amphoric
      By amphoric
      Hi,
      I am struggling converting my 1D array to a 2D array and then showing that in my List View. Below is my current code, where I would like to take the array from the input box, and have that displayed as a list within the list view this is a list of computer names, and then update the 2nd column of each line once I have ran a ping and a registry change on each computer name, with either 'Completed' and 'Failed'
      I have checked out the AutoIt Arrays page here: https://www.autoitscript.com/wiki/Arrays , but unfortunately I cannot get my head around it. Any help would be greatly appreciated.
      I hope this makes sense.
      Thanks
       
      #include <Date.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <GUIListBox.au3> #include <GuiListView.au3> #Region ### $Form1 = GUICreate("Title", 515, 533, -1, -1) GUISetBkColor(0xFFFFFF) $Pic2 = GUICtrlCreatePic("Images\pic.jpg", 16, 16, 212, 28) $Label1 = GUICtrlCreateLabel("Label", 240, 16, 271, 33, $SS_CENTER) GUICtrlSetFont(-1, 17, 800, 0, "") $Combo1 = GUICtrlCreateCombo("", 256, 406, 241, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE)) $Label2 = GUICtrlCreateLabel("Please select the location", 45, 401, 210, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $ChangeButton = GUICtrlCreateButton("Change", 286, 487, 75, 25) $RePromptButton = GUICtrlCreateButton("Re-prompt User", 366, 487, 139, 25) $Checkbox1 = GUICtrlCreateCheckbox("I have ensured that my selection is correct.", 10, 487, 273, 25) GUICtrlSetFont(-1, 10, 400, 0, "") $ManLocation = GUICtrlCreateLabel("Please enter the location:", 59, 448, 189, 20, $SS_RIGHT) GUICtrlSetFont(-1, 10, 800, 0, "") GUICtrlSetState(-1, $GUI_HIDE) $ManLocInput = GUICtrlCreateInput("", 256, 445, 241, 24) GUICtrlSetState(-1, $GUI_HIDE) $Label5 = GUICtrlCreateLabel("for this device:", 138, 418, 109, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $Label3 = GUICtrlCreateLabel("Asset Number:", 98, 72, 107, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "") $Input1 = GUICtrlCreateInput("", 215, 69, 241, 24) $AddMulti = GUICtrlCreateLabel("Add Multiple Assets", 356, 55, 98, 13, $SS_RIGHT) GUICtrlSetFont(-1, 8, 400, 6, "") GUICtrlSetColor(-1, 0x808080) GUICtrlSetCursor (-1, 0) $List1 = GUICtrlCreateListView("", 16, 104, 481, 278) $Add = GUICtrlCreateButton("Add", 461, 68, 35, 25) GUISetState(@SW_SHOW) #EndRegion ### ;### StartForm ### $FormaMultiple = GUICreate("Title", 277, 418, -1, -1) GUISetBkColor(0xFFFFFF) $Label1 = GUICtrlCreateLabel("Please add 1 asset number per line.", 8, 11, 253, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $OK = GUICtrlCreateButton("OK", 56, 375, 75, 25) $Edit1 = GUICtrlCreateEdit("", 20, 40, 233, 329) $Cancel = GUICtrlCreateButton("Cancel", 136, 375, 75, 25) GUISetState(@SW_HIDE) ;### EndForm ### ;### Add List View Columns START ### ;### Add List View Columns END ### ;### Read Locations START ### ;Read the LOCAL ini file SECTIONS Global $aSections = IniReadSectionNames("Locations.ini") ;If the above succeeded, convert the array to a string with each item separated by a | (pipe) and set the default selected item to $aSections[1] If(Not @Error) Then GUICtrlSetData($Combo1, _ArraytoString($aSections, "|", 1), $aSections[1]) ;### Read Locations END ### ;### Require Admin START ### ;#RequireAdmin ;### Require Admin END ### While 1 $nMsg = GUIGetMsg() ;### Data Validation START ### ;Set Checkbox = ENABLE/DISABLE if not GUICtrlRead($Combo1) = "" AND GUICtrlRead($Combo1) = "Not In List" then if not GUICtrlRead($ManLocInput) = "" Then If not ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_ENABLE) Else If ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_DISABLE) EndIf Else if GUICtrlRead($Combo1) = "" Then If ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_DISABLE) Else If not ControlCommand($Form1, "", $Checkbox1, "IsEnabled") Then GUICtrlSetState($Checkbox1, $GUI_ENABLE) EndIf EndIf ;Set Button = ENABLE/DISABLE If GUICtrlRead($Checkbox1) = 1 Then If Not ControlCommand($Form1, "", $ChangeButton, "IsEnabled") Then GUICtrlSetState($ChangeButton, $GUI_ENABLE) Else If ControlCommand($Form1, "", $ChangeButton, "IsEnabled") Then GUICtrlSetState($ChangeButton, $GUI_DISABLE) EndIf ;### Data Validation END ### Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $Add Case $AddMulti GUISetState(@SW_SHOW, $FormaMultiple) Case $Cancel GUISetState(@SW_HIDE, $FormaMultiple) Case $OK $sText = GUICtrlRead($Edit1) $aText = StringSplit($sText, @CRLF, 1) $bText = _ArrayToString($aText, ";", 1, -1) $cText = StringStripWS($bText, $STR_STRIPALL ) $dText = StringReplace($cText,";;",";") GUICtrlSetData($Input1, $dText) GUICtrlSetData($Edit1, "") GUISetState(@SW_HIDE, $FormaMultiple) For $i = 1 To $aText[0] Next Case $Combo1 ; If the combo is actioned Switch GUICtrlRead($Combo1) Case "Not In List" ; Show the manual input controls GUICtrlSetState($ManLocation, $GUI_SHOW) GUICtrlSetState($ManLocInput, $GUI_SHOW) if ControlCommand($Form1, "", $Checkbox1, "IsChecked") then ControlCommand($Form1, "", $Checkbox1, "Uncheck") GUICtrlSetData($ManLocInput, "") Case Else ; Hide them GUICtrlSetState($ManLocation, $GUI_HIDE) GUICtrlSetState($ManLocInput, $GUI_HIDE) if ControlCommand($Form1, "", $Checkbox1, "IsChecked") then ControlCommand($Form1, "", $Checkbox1, "Uncheck") GUICtrlSetData($ManLocInput, "") EndSwitch Case $ChangeButton ChangeReg() Case $RePromptButton RemoveReg() EndSwitch WEnd Func ChangeReg() $MultiAssets = StringSplit(GUICtrlRead($Input1), ";", 1) For $i = 1 To $MultiAssets[0] ; Ping with a timeout of 250ms. Local $iPing = Ping($MultiAssets[$i], 250) If $iPing Then ; If a value greater than 0 was returned then do the following: if not GUICtrlRead($ManLocInput) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "# - " & GUICtrlRead($ManLocInput)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "# - " & GUICtrlRead($ManLocInput)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) MsgBox($MB_SYSTEMMODAL, "Completed", "Completed") Else If not GUICtrlRead($Input1) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", GUICtrlRead($Combo1)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", GUICtrlRead($Combo1)) RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC) MsgBox($MB_SYSTEMMODAL, "Completed", $MultiAssets[$i] & @CRLF & " Changed to: " & GUICtrlRead($Combo1)) Else MsgBox($MB_SYSTEMMODAL, "Error", "Please ensure all boxes are completed") EndIf EndIf Else MsgBox($MB_SYSTEMMODAL, "Error", "This asset may be OFFLINE, unable to complete") EndIf Next EndFunc ;==>PingReg Func RemoveReg() $MultiAssets = StringSplit(GUICtrlRead($Input1), ";", 1) For $i = 1 To $MultiAssets[0] ; Ping with a timeout of 250ms. Local $iPing = Ping($MultiAssets[$i], 250) If $iPing Then ; If a value greater than 0 was returned then do the following: if not GUICtrlRead($ManLocInput) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", "") MsgBox($MB_SYSTEMMODAL, "Completed", "Completed") Else If not GUICtrlRead($Input1) = "" Then RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "Location", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM\SOFTWARE\Location", "LocationLog", "REG_SZ", "") RegWrite("\\" & $MultiAssets[$i] & "\HKLM64\SOFTWARE\Location", "LocationLog", "REG_SZ", "") MsgBox($MB_SYSTEMMODAL, "Completed", $MultiAssets[$i] & @CRLF & "CLEARED") Else MsgBox($MB_SYSTEMMODAL, "Error", "Please ensure all boxes are completed") EndIf EndIf Else MsgBox($MB_SYSTEMMODAL, "Error", "This asset may be OFFLINE, unable to complete") EndIf Next EndFunc ;==>PingReg1