Jump to content
Valnurat

Return of error code to my exe file.

Recommended Posts

Valnurat

Is there any change that I can return a code for success or not success in my script?

I have a script that look in a SQL db and write to the registry.

I want to return some kind of a control, because I will call my script *.exe from VBScript.

_Main()

Func _Main()
    Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';', $sQUERY, $oRecordset, $aRecordsetArray, $aRecordset_inner
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)
    If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)
    $sQUERY = "Select Shipdate from " & $sTableName & " where ComputerName = '" & @ComputerName & "'"
    $oRecordset = _ADO_Execute($oConnection, $sQUERY)
    $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False)
    $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\ComputerInfo", "Shipdate", "REG_SZ", $aRecordset_inner[0][0])
EndFunc

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
benners

If you want to return a code from your AutoIt exe to the VB script you can set the exit value to what you want by using the exit function and setting the return code parameter

Exit (1)

 

Share this post


Link to post
Share on other sites
Valnurat

So I just do this:

_Main()

Func _Main()
    Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';', $sQUERY, $oRecordset, $aRecordsetArray, $aRecordset_inner
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)
    If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)
    $sQUERY = "Select Shipdate from " & $sTableName & " where ComputerName = '" & @ComputerName & "'"
    $oRecordset = _ADO_Execute($oConnection, $sQUERY)
    $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False)
    $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\ComputerInfo", "Shipdate", "REG_SZ", $aRecordset_inner[0][0])
    Exit(1)
EndFunc

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water
1 hour ago, Valnurat said:

Is there any change that I can return a code for success or not success in my script?

To achieve this you would first need to decide if the function worked or didn't. Best way is to check every _ADO* function for an error code.
You now only check once (after _ADO_Connection_OpenConString). Do it after every call.

I would drop "Exit(1)" as this always ends your script. End the script in the main function.

_Main()
If @error Then Exit MsgBox(0, "Error", "Script ended with @error = " & @error)
; More code to execute
Exit

Func _Main()
    Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';', $sQUERY, $oRecordset, $aRecordsetArray, $aRecordset_inner
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)
    If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)
    $sQUERY = "Select Shipdate from " & $sTableName & " where ComputerName = '" & @ComputerName & "'"
    $oRecordset = _ADO_Execute($oConnection, $sQUERY)
    If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)
    $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False)
    If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)
    $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray)
    If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\ComputerInfo", "Shipdate", "REG_SZ", $aRecordset_inner[0][0])
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

Ok, but how can I receive the status code if I call the exe file from VBScript?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

Then you need Exit.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

Like this:

_Main()
Exit(1)

Func _Main()
    Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';', $sQUERY, $oRecordset, $aRecordsetArray, $aRecordset_inner
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)
    If @error Then SetError(@error, @extended, $ADO_RET_FAILURE)
    $sQUERY = "Select Shipdate from " & $sTableName & " where ComputerName = '" & @ComputerName & "'"
    $oRecordset = _ADO_Execute($oConnection, $sQUERY)
    If @error Then SetError(@error, @extended, $ADO_RET_FAILURE)
    $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False)
    If @error Then SetError(@error, @extended, $ADO_RET_FAILURE)
    $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray)
    If @error Then SetError(@error, @extended, $ADO_RET_FAILURE)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\ComputerInfo", "Shipdate", "REG_SZ", $aRecordset_inner[0][0])
EndFunc

 

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

Would the calling VBS need to know if there was an error in your AutoIt script?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

Yes, because I would like to create a txtfile with controlinfo if it fails.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

Then you need to use something like this and return different values.
On success the return value is set to 0, else it holds the error code returned by any of the _ADO* functions.

_Main()
Exit(0)

Func _Main()
    Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';', $sQUERY, $oRecordset, $aRecordsetArray, $aRecordset_inner
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)
    If @error Then Exit(@error)
    $sQUERY = "Select Shipdate from " & $sTableName & " where ComputerName = '" & @ComputerName & "'"
    $oRecordset = _ADO_Execute($oConnection, $sQUERY)
    If @error Then Exit(@error)
    $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False)
    If @error Then Exit(@error)
    $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray)
    If @error Then Exit(@error)
    RegWrite("HKEY_CURRENT_USER\SOFTWARE\ComputerInfo", "Shipdate", "REG_SZ", $aRecordset_inner[0][0])
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

It does return 0 as  you said, even thogh if $aRecordset_inner[0][0] is empty. :)

I would like to return a exitcode if $aRecordset_inner[0][0] is empty.

How can I do that?

EDIT: In my VBScript I check the registry and if it's empty I will run my exefile. Right now my exefile just return 0 no matter if $aRecordset_inner[0][0] is empty or not. I don't want to check the registry 2 times in my VBScript before creating a txtfile with controlinfo.

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water
31 minutes ago, Valnurat said:

I would like to return a exitcode if $aRecordset_inner[0][0] is empty.

You already did half of the coding ;)

If $aRecordset_inner[0][0] = "" Then Exit(99) ; Or whatever return value you like

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

Aha. Very simpel. :>

Thank you.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Valnurat

Sorry, for returning to this ticket, but I don't understand why my VBScript is returning errrorcode 0, when I can see my AutoIT errorcode is 99.

; SetUP internal ADO.au3 UDF COMError Handler
_ADO_ComErrorHandler_UserFunction(_ADO_COMErrorHandler)

_Main()
Exit(0)


Func _Main()
    Local $sConnectionString = 'DRIVER={' & $sDriver & '};SERVER=' & $sServer & ';DATABASE=' & $sDatabase & ';UID=' & $sUser & ';PWD=' & $sPassword & ';', $sQUERY, $oRecordset, $aRecordsetArray, $aRecordset_inner
    Local $oConnection = _ADO_Connection_Create()
    _ADO_Connection_OpenConString($oConnection, $sConnectionString)
    If @error Then SetError(@error, @extended, $ADO_RET_FAILURE)
    $sQUERY = "Select Shipdate from " & $sTableName & " where ComputerName = '" & @ComputerName & "'"
    $oRecordset = _ADO_Execute($oConnection, $sQUERY)
    If @error Then SetError(@error, @extended, $ADO_RET_FAILURE)
    $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False)
    If @error Then SetError(@error, @extended, $ADO_RET_FAILURE)
    $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray)
    If @error Then SetError(@error, @extended, $ADO_RET_FAILURE)
    if IsArray($aRecordset_inner) Then
        If $aRecordset_inner[0][0] = '' or $aRecordset_inner[0][0] = Null Then Exit(99)
        RegWrite("HKEY_CURRENT_USER\SOFTWARE\ComputerInfo", "Shipdate", "REG_SZ", $aRecordset_inner[0][0])
    Else
        Exit(99)
    EndIf
EndFunc

Capture.JPG

My VBScript is this:

Sub RegComputerInfo
 	Const HKEY_CURRENT_USER = &H80000001
	Dim lstrKeyPath, lstrValueName, lstrValue, outFile, objFile, oExec
	lstrKeyPath = "SOFTWARE\ComputerInfo\"
	lstrValueName = "Shipdate"
	if ADHelper.IsCurrentUserMember("AllUsers") and (ADHelper.strComputerType <> "Server") then
		objReg.GetStringValue HKEY_CURRENT_USER,lstrKeyPath,lstrValueName,lstrValue
		if IsNull(lstrValue) then
			set oExec = WSHShell.exec(strScriptPath & "\Support\Script\ComInventory\GetShipdate.exe") ' Read a SQL DB
			msgbox "Test1 " & oExec.ExitCode		
			if oExec.ExitCode <> 0 then
				outFile = "\\servername\install\Log\ComputerInfo\" & WSHNetwork.ComputerName & ".txt"
				Set objFile = objFSO.CreateTextFile(outFile,True)
				objFile.Write strUsername & "|" & strModel & "|" & ServiceTag
				objFile.Close
			else
				msgbox "Test " & oExec.ExitCode		
			End if	
		End If	
	End if
End Sub 'FindShipDate

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
Valnurat

If I put this in my VBScript I do get my errorcode = 99

My VBScript is this:

Sub RegComputerInfo
 	Const HKEY_CURRENT_USER = &H80000001
	Dim lstrKeyPath, lstrValueName, lstrValue, outFile, objFile, oExec
	lstrKeyPath = "SOFTWARE\ComputerInfo\"
	lstrValueName = "Shipdate"
	if ADHelper.IsCurrentUserMember("AllUsers") and (ADHelper.strComputerType <> "Server") then
		objReg.GetStringValue HKEY_CURRENT_USER,lstrKeyPath,lstrValueName,lstrValue
		if IsNull(lstrValue) then
			set oExec = WSHShell.exec(strScriptPath & "\Support\Script\ComInventory\GetShipdate.exe") ' Read a SQL DB
			Do While oExec.Status = 0			<-----
     			WScript.Sleep 100				<-----
			Loop						<-----
			WScript.Echo oExec.Statusmsgbox "Test1 " & oExec.ExitCode		
			if oExec.ExitCode <> 0 then
				outFile = "\\servername\install\Log\ComputerInfo\" & WSHNetwork.ComputerName & ".txt"
				Set objFile = objFSO.CreateTextFile(outFile,True)
				objFile.Write strUsername & "|" & strModel & "|" & ServiceTag
				objFile.Close
			else
				msgbox "Test " & oExec.ExitCode		
			End if	
		End If	
	End if
End Sub 'FindShipDate

But should I really do that?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
Valnurat

Sorry, if I step on some toes here, but is there someone who could help me?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
Juvigy

Why do you need a VBS? Do everything with Autoit. It will be simpler and the problem with return codes will be gone!

Share this post


Link to post
Share on other sites
Valnurat

True, but as you can see in my VBS I create a txtfile on a server, if the exitcode is not 0.

In the future that server might not exists anymore and then I have to modify my autoit to the new server.

I would like to avoid to modify my autoit code.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
water

Store the variable information (server address etc.) in an INI-file. So you can easily move to another server and only need to modify the config INI file.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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

    • nooneclose
      By nooneclose
      Hey. I'm working on a new project and was wondering if there is a better way to "update" my Column E array. 
      Here is my code: 
      Local $nI  = 0                                                            ;Creates a name index of 0: nI = Name index Local $nII = 1                                                            ;Creates a name index of 1 for second loop: nII = Name Index 2 For    $iN = 0 To $IndexRows Step 1                                       ;Checks the roster for any names that appear twice      For $iN2 = 0 To $IndexRows Step 1          if $d_Names[$nI] == $d_Names[$nII] And $d_Names[$nII] <> "" Then              Local $timeSheetName = _ArraySearch($e_Names, $d_Names[$nI], 0, 0, 0, 0, 1)              ;MsgBox($MB_SYSTEMMODAL, "Found it", $d_Names[$nI] & " In column E on Row " & $timeSheetName)              Local $eI  = $timeSheetName + 1              ;ConsoleWrite($timeSheetName & @CRLF)              ;ConsoleWrite($eI & @CRLF)              ;ConsoleWrite(@CRLF)              _Excel_RangeInsert($OpenWorkbook.ActiveSheet, "E" & $eI & ":F" & $eI, $xlShiftDown)                                                                          ;Inserts a empty cell in columns E and F.              _Excel_RangeWrite($OpenWorkbook, $OpenWorkbook.ActiveSheet, $d_Names[$nII], "E" & $eI)                                                                         ;Fills the empty cell in columns E with the doubled name              $aArray_Index = 2                                           ;Array element counter              For $Index = 2 To $IndexRows Step 1                        ;Loops through every row in the Excel file unto no rows are found or a null row is found                  $Array_Value_E = _Excel_RangeRead($OpenWorkbook, Default, "E"&$Index)                  $e_names[$aArray_Index] = $Array_Value_E                ;While the code loops every value in column E is stored in the E array (updating the array)                  $aArray_Index += 1              Next              ExitLoop          EndIf      Next      $nI  += 1      $nII += 1 Next Basically, It checks a roster for people whose name appears twice then inserts a new "row" for that person because they work in two different departments.
      I have to find that name however in Column E if two appear in column D. My code works but I think it is not as efficient as it could be. 
      Any ideas on how to improve the "update" for my array?
      (once it finds the double names in Column D it then searches for that name by going name by name in the Column E array and once it finds it inserts a new row. However, the E array doesn't have that new row stored in it so I have to "update" the array to properly find the next name)
      Any and all tips would be greatly appreciated. 
       
      NOTE: Just assume I'm opening the excel file properly please do not add that code in, it only complicates your answer. 
    • Miliardsto
      By Miliardsto
      Hello Im wondering if using this https://ohtejera.github.io/ImperiusAutoIt/#started
      UDF can i make that I can control my windows application with phone?
      like for example click button Start on android phone and then something would be done in my windows app?
    • nooneclose
      By nooneclose
      How do I properly convert this to Autoit? This is a VBA macro that I recorded in Excel.
       ActiveSheet.Outline.ShowLevels RowLevels:=2 I need this to close my subtotal once it is finished. 
      any help will be greatly appreciated. 
    • iMacg3
      By iMacg3
      Hi,
      I was looking into a way to delete a registry key (not a specific value, an entire key) if it is present. I was considering using RegRead and RegDelete. However, RegRead appears to only read values, not just keys. Is there a way to delete an entire registry key if it is present? I have heard that the below function may help.
       
      #include-once ; #UDF# ======================================================================================================================= ; Title .........: Reads\Search the name of a Key\Subkey\Value ; AutoIt Version : 3.3.8.1 ; Language ......: English ; Description ...: Lists all Keys\Subkeys\Values in a specified registry key ; Author(s) .....: DXRW4E ; Notes .........: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;~ _RegEnumKeyEx ;~ _RegEnumValEx ; =============================================================================================================================== #Region ;**** Global constants and vars **** Global Const $sValueTypes[12] = ["REG_NONE","REG_SZ","REG_EXPAND_SZ","REG_BINARY","REG_DWORD","REG_DWORD_BIG_ENDIAN","REG_LINK","REG_MULTI_SZ","REG_RESOURCE_LIST","REG_FULL_RESOURCE_DESCRIPTOR","REG_RESOURCE_REQUIREMENTS_LIST","REG_QWORD"] #EndRegion ;**** Global constants and vars **** ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumKeyEx ; Description ...: Lists all subkeys in a specified registry key ; Syntax.........: _RegEnumKeyEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read. ; $iFlag - Optional specifies Recursion (add the flags together for multiple operations): ; |$iFlag = 0 (Default) All Key-SubKeys Recursive Mod ; |$iFlag = 1 All SubKeys Not Recursive Mod ; |$iFlag = 2 Include in ArrayList in the first element $KeyName ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 128 Enum value's name (_RegEnumKeyEx Return a 2D array, maximum Array Size limit is 3999744 Key\Value) ; |$iFlag = 256 Reads a value data, this flag will be ignored if the $iFlag = 128 is not set ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $vFilter - Optional the filter to use for ValueName, $vFilter will be ignored if the $iFlag = 128 is not set ; default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All), $iValueTypes will be ignored if the $iFlag = 128 is not set ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |1 = Invalid $sFilter ; |2 = No Key-SubKey(s) Found ; |3 = Invalid $vFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is one-dimensional and is made up as follows: ; $array[0] = Number of Key-SubKeys returned ; $array[1] = 1st Key\SubKeys ; $array[2] = 2nd Key\SubKeys ; $array[3] = 3rd Key\SubKeys ; $array[n] = nth Key\SubKeys ; ; If is set the $iFlag = 128 The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumValEx() ; Link ..........: ; Example .......: _RegEnumKeyEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumKeyEx($KeyName, $iFlag = 0, $sFilter = "*", $vFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, StringReplace("^\s*$|\v|\\|^\||\|\||\|$", Chr(BitAND($iFlag, 64) + 28) & "\|^\||\|\||\|$", "\\\\")) Then Return SetError(1, 0, "") Local $IndexSubKey[101] = [100], $SubKeyName, $BS = "\", $sKeyList, $I = 1, $sKeyFlag = BitAND($iFlag, 1), $sKeyFilter = StringReplace($sFilter, "*", "") If BitAND($iFlag, 2) Then $sKeyList = @LF & $KeyName If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" While $I $IndexSubKey[$I] += 1 $SubKeyName = RegEnumKey($KeyName, $IndexSubKey[$I]) If @error Then $IndexSubKey[$I] = 0 $I -= 1 $KeyName = StringLeft($KeyName, StringInStr($KeyName, "\", 1, -1) - 1) ContinueLoop EndIf If $sKeyFilter Then If StringRegExp($SubKeyName, $sFilter) Then $sKeyList &= @LF & $KeyName & $BS & $SubKeyName Else $sKeyList &= @LF & $KeyName & $BS & $SubKeyName EndIf If $sKeyFlag Then ContinueLoop $I += 1 If $I > $IndexSubKey[0] Then $IndexSubKey[0] += 100 ReDim $IndexSubKey[$IndexSubKey[0] + 1] EndIf $KeyName &= $BS & $SubKeyName WEnd If Not $sKeyList Then Return SetError(2, 0, "") If BitAND($iFlag, 128) <> 128 Then Return StringSplit(StringTrimLeft($sKeyList, 1), @LF, StringReplace(BitAND($iFlag, 32), "32", 2)) $sKeyList = _RegEnumValEx(StringSplit(StringTrimLeft($sKeyList, 1), @LF), $iFlag, $vFilter, $iValueTypes) Return SetError(@Error, 0, $sKeyList) EndFunc ; #FUNCTION# ======================================================================================================================== ; Name...........: _RegEnumValEx ; Description ...: Lists all values in a specified registry key ; Syntax.........: _RegEnumValEx($KeyName[, $iFlag = 0[, $sFilter = "*"]]) ; Parameters ....: $KeyName - The registry key to read Or one-dimensional array RegKeyList ; use _RegEnumKeyEx() to get $RegKeyList (example $RegKeyList = [3, 1st Key\SubKeys, 2st Key\SubKeys, nth Key\SubKeys]) ; |$iFlag = 16 $sFilter do Case-Sensitive matching (By Default $sFilter do Case-Insensitive matching) ; |$iFlag = 32 Disable the return the count in the first element - effectively makes the array 0-based (must use UBound() to get the size in this case). ; By Default the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) ; |$iFlag = 64 $sFilter is REGEXP Mod, See Pattern Parameters in StringRegExp ; |$iFlag = 256 Reads a value data ; $sFilter - Optional the filter to use, default is *. (Multiple filter groups such as "All "*.XXx|*.YYY|*.ZZZ") ; Search the Autoit3 helpfile for the word "WildCards" For details. ; $iValueTypes - Optional, set Value Types to search (Default $iValueTypes = 0 Read All) ; (add the flags together for multiple operations): ; 1 = REG_SZ ; 2 = REG_EXPAND_SZ ; 3 = REG_BINARY ; 4 = REG_DWORD ; 5 = REG_DWORD_BIG_ENDIAN ; 6 = REG_LINK ; 7 = REG_MULTI_SZ ; 8 = REG_RESOURCE_LIST ; 9 = REG_FULL_RESOURCE_DESCRIPTOR ; 10 = REG_RESOURCE_REQUIREMENTS_LIST ; 11 = REG_QWORD ; Return values .: Success - Return Array List (See Remarks) ; Failure - @Error ; |3 = Invalid $sFilter ; |4 = No Value-Name(s) Found ; Author ........: DXRW4E ; Modified.......: ; Remarks .......: The array returned is 2D array and is made up as follows: ; $array[0][0] = Number of Key-SubKeys returned ; $array[1][0] = 1st Key\SubKeys ; $array[1][1] = 1st Value name ; $array[1][2] = 1st Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[1][3] = 1st Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[2][0] = 2nd Key\SubKeys ; $array[2][1] = 2nd Value name ; $array[2][2] = 2nd Value Type (REG_NONE or REG_SZ or REG_EXPAND_SZ ect ect) ; $array[2][3] = 2nd Value Data (If is set $iFlag = 256 Else Value Data = "") ; $array[n][0] = nth Key\SubKeys ; Related .......: _RegEnumKeyEx() ; Link ..........: ; Example .......: _RegEnumValEx("HKEY_CURRENT_USER\Software\AutoIt v3") ; Note ..........: ; =================================================================================================================================== Func _RegEnumValEx($aKeyList, $iFlag = 0, $sFilter = "*", $iValueTypes = 0) If StringRegExp($sFilter, "\v") Then Return SetError(3, 0, "") If Not IsArray($aKeyList) Then $aKeyList = StringSplit($aKeyList, @LF) Local $aKeyValList[1954][4], $iKeyVal = Int(BitAND($iFlag, 32) = 0), $sKeyVal = 1953, $sRegEnumVal, $iRegEnumVal, $RegRead = BitAND($iFlag, 256), $vFilter = StringReplace($sFilter, "*", "") If Not BitAND($iFlag, 64) Then $sFilter = StringRegExpReplace(BitAND($iFlag, 16) & "(?i)(", "16\(\?\i\)|\d+", "") & StringRegExpReplace(StringRegExpReplace(StringRegExpReplace(StringRegExpReplace($sFilter, "[^*?|]+", "\\Q$0\\E"), "\\E(?=\||$)", "$0\$"), "(?<=^|\|)\\Q", "^$0"), "\*+", ".*") & ")" For $i = 1 To $aKeyList[0] $iRegEnumVal = 0 While 1 If $iKeyVal = $sKeyVal Then If $sKeyVal = 3999744 Then ExitLoop $sKeyVal *= 2 ReDim $aKeyValList[$sKeyVal + 1][4] EndIf $aKeyValList[$iKeyVal][0] = $aKeyList[$i] $iRegEnumVal += 1 $sRegEnumVal = RegEnumVal($aKeyList[$i], $iRegEnumVal) If @Error <> 0 Then If $iRegEnumVal = 1 And $vFilter = "" Then $iKeyVal += 1 ExitLoop EndIf $aKeyValList[$iKeyVal][2] = $sValueTypes[@Extended] If BitAND(@Extended, $iValueTypes) <> $iValueTypes Then ContinueLoop If $vFilter And Not StringRegExp($sRegEnumVal, $sFilter) Then ContinueLoop $aKeyValList[$iKeyVal][1] = $sRegEnumVal If $RegRead Then $aKeyValList[$iKeyVal][3] = RegRead($aKeyList[$i], $sRegEnumVal) $iKeyVal += 1 WEnd Next $sRegEnumVal = $iKeyVal - Int(BitAND($iFlag, 32) = 0) If Not $sRegEnumVal Or ($sRegEnumVal = 1 And $vFilter = "" And $aKeyValList[$iKeyVal - $sRegEnumVal][2] = "") Then Return SetError(4, 0, "") ReDim $aKeyValList[$iKeyVal][4] If Not BitAND($iFlag, 32) Then $aKeyValList[0][0] = $iKeyVal - 1 Return $aKeyValList EndFunc Thanks.
       
    • great77
      By great77
      ; put the root in a variable $sRoot = "C:\Project\PHexample\" Global $sCurrentTime = _NowCalc() ; We can use that variable here Global $aList = _FileListToArray($sRoot, Default, 2) If @error Then Exit ;;;;;;MsgBox(0, "Error", "_FileListToArray returned @error = " & @error) ;;;;;;;;;;;This is a loop that runs from 1 to the number of items listed in the first element of the returned  array For $i = 1 To UBound($aList) - 1     MsgBox(0, "Folder date", $sRoot & "" & $aList[$i] & @CRLF & @CRLF & FileGetTime($sRoot & "" & $aList[$i], 1, 1))     MsgBox(0, "Folder date", FileGetTime($sRoot & "" & $aList[$i], 1, 1))      $a_filenew = StringReplace(StringReplace(StringReplace(_NowCalc(), "/", ""), ":", ""), " ", "")       MsgBox(0, "Folder date", $a_filenew) $adex =  _DateDiff('D', FileGetTime($sRoot & "" & $aList[$i], 1, 1), $a_filenew)  MsgBox(0,"ade", $adex) Next I have a code as seen above, but the difference in time is returning zero. I understand that the date yyyymmddhhmmss but how can I find the difference.
      The purpose is to try find the difference in days. Any suggestion?  
×