I've encountered a problem with a single file where I cannot retrieve it's Date-time. So far my code has worked well for over 30 files, but this one is a mystery I cannot debug myself due to insufficient Au3 knowledge.
In line 11 "_Date_Time_FileTimeToArray" is called and for this particular file it sets the @error to 10. I don't know what that error code means, but it's not set by the _Date functions themselves I think.
Overall, it could be a problem caused by any of the functions below, how can I properly debug this? / Does anybody know a what's causing this?
_WinAPI_CreateFile() / _Date_Time_GetFileTime() / _Date_Time_FileTimeToArray()
Func _SetFileTimes($sFilePath) Local $monthNumber = ["", "January", "February", "March", "April", "May", "Juny", "July", "August", "September", "October", "November", "December"] Local $dayNumber = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] Local $fHandle = _WinAPI_CreateFile($sFilePath, 2, 2) ; read-only ; may NOT return a valid date for some reason! TODO Local $fTagFILETIME = _Date_Time_GetFileTime($fHandle) _WinAPI_CloseHandle($fHandle) ; This will return an empty array if theres no valid date $fModTime = _Date_Time_FileTimeToArray($fTagFILETIME) ; last Modified if @error <> 10 then Local $year = $fModTime Local $month = $fModTime Local $day = $fModTime Local $hour = $fModTime Local $min = $fModTime Local $sec = $fModTime Local $ms = $fModTime Local $weekday = $fModTime Global $prettyTimestamp = StringFormat("%s, %s %d, %04d %02d:%02d:%02d", $dayNumber[$weekday], $monthNumber[$month], $day, $year, $hour, $min, $sec) Global $uploadDate = StringFormat("%04d-%02d-%02d", $year, $month, $day) $fModTime = _Date_Time_FileTimeToArray(_Date_Time_FileTimeToLocalFileTime($fTagFILETIME)) ; last Modified Local $year = $fModTime Local $month = $fModTime Local $day = $fModTime Local $hour = $fModTime Local $min = $fModTime Local $sec = $fModTime Local $ms = $fModTime Local $weekday = $fModTime ; GetUnixTime accounts for Local time, hence feed it local time Global $unixTimestamp = _GetUnixTime($year &"/"& $month &"/"& $day &" "& $hour&":"& $min &":"& $sec) else Global $prettyTimestamp = "N/A" Global $uploadDate = "" Global $unixTimestamp = "N/A" endif endfunc
_GetUnixTime returned the year 1601 start date, showing that $fModTime is probably equal 0. (But Why?)
The file reports these dates in Explorer, it's on local NTFS drive:
Created: Wednesday, 31. Januar 2018, 18:55:02
Modified: Wednesday, 10. Januar 2018, 12:39:23
Accessed: Wednesday, 10. Januar 2018, 12:39:23
I have this piece code that works with Excel file and finds the column name where is a specific named range located.
Local $Column = Null $Column = _Excel_ColumnToLetter($oWorkbook.Sheets("MySheetName").Range("MyRangeName").Column) If @error Then $Column = Null SetError(0) Else ;Proceed... EndIf It works properly if the named range exists in the Excel file, I do get the column name and the "Proceed" part is correctly executed. If the named range is not present in the Excel file, I would expect the If @error part to set the variable to Null and then follow with the rest of the function after EndIf. Instead, the script stops and I get this error:
"C:\test\script_021.au3" (1184) : ==> The requested action with this object has failed.: $Column = _Excel_ColumnToLetter($oWorkbook.Sheets("MySheetName").Range("MyRangeName").Column) $Column = _Excel_ColumnToLetter($oWorkbook.Sheets("MySheetName")^ ERROR What am I doing wrong here? Is it possible that failure to set the variable doesn't set the @error? Push in the right direction would be much appreciated. Thanks!
Hi, I have a software which has a 'run file'-ie; when i double click on that file, the input file of the software is run by the software. I wish to double click/execute this run file using autoit. how do i achieve this. i opened the software and it shows the input file and run file in same folder, i will put my autoitscript file too in same location. how do i simulate double clicking the run file (using its file name, say - abc.run ). I entered the following lines to make software window active - it became active, dont know how to go forward
controlclick("program title","abc.run",1000,"primary",2) ; 1000 is ctrl id
following my previous question, I have moved all potentially instable object interactions into Executes. But it Looks like "="-assignments to object Attributes cannot be done with Execute, only method calls. Using an "$obj = 1" construct, it compares (Eval) instead of sets (Execute) the value.
I have tested multiple different combinations, using Execute and Assign, but it seems not to work with object Attributes. :-(
Gives following Output:
The assign Action using apply (a3) Fails, while assigning it directly, without Assign() works fine.
The execute versions compare and do not assign, in both cases. Though, the "Execute" topic in the help file says it executes, not evaluates.
I have found a similar, old thread, which explains this behavious but does not give a solution. https://www.autoitscript.com/forum/topic/110228-pass-object-property-as-a-variable/
Is there a way to assign to a com object's Attribute? Or is there anything new to this unexpected behaviour of Execute (at least compared to the help file description and Python's exec).
Any help is appreciated, and thank you for all the help so far.
Bit of a fun one with querying WMI objects and setting errors within a function. Below is example code that I've used from JSThePatriot previous UDFs but the example would apply to many other scenarios. Basically the SetError should be called if $colItems is not an object as a result of the WMI query. This is then used to create a corresponding error message.
I've tried disabling WMIC thus forcing it to not be an object, but rather than catching the error and telling me about it, the code simply fails therefore surely making the purpose of the logging useless?? I've experienced this before but in other languages such as java i would use a try catch etc and get around this....any suggestions for its use in AutoIT?
#region Header #comments-start Title: Computer Information Automation UDF Library for AutoIt3 - EXAMPLES Filename: CompInfoExamples.au3 Description: Examples using the UDF's from CompInfo.au3 Author: Jarvis J. Stubblefield (JSThePatriot) http://www.vortexrevolutions.com/ Version: 00.03.08 Last Update: 11.09.06 Requirements: AutoIt v3.2 +, Developed/Tested on WindowsXP Pro Service Pack 2 Notes: Errors associated with incorrect objects will be common user errors. AutoIt beta 22.214.171.124 has added an ObjName() function that will be used to trap and report most of these errors. Special thanks to Firestorm (Testing, Use), Koala (Testing, Bug Fix), and everyone else that has helped in the creation of this Example File. #comments-end #endregion Header #region Global Variables and Constants If Not(IsDeclared("$cI_CompName")) Then Global $cI_CompName = @ComputerName EndIf Global Const $cI_VersionInfo = "00.03.08" Global Const $cI_aName = 0, _ $cI_aDesc = 4 Global $wbemFlagReturnImmediately = 0x10, _ ;DO NOT CHANGE $wbemFlagForwardOnly = 0x20 ;DO NOT CHANGE Global $ERR_NO_INFO = "Array contains no information", _ $ERR_NOT_OBJ = "$colItems isnt an object" #endregion Global Variables and Constants #Region Boot Configuration Dim $BootConfig _ComputerGetBootConfig($BootConfig) If @error Then $error = @error $extended = @extended Switch $extended Case 1 _ErrorMsg($ERR_NO_INFO) Case 2 _ErrorMsg($ERR_NOT_OBJ) EndSwitch EndIf For $i = 1 To $BootConfig Step 1 MsgBox(0, "Test _ComputerGetBootConfig", "Name: " & $BootConfig[$i] & @CRLF & _ "Boot Directory: " & $BootConfig[$i] & @CRLF & _ "Configuration Path: " & $BootConfig[$i] & @CRLF & _ "Last Drive: " & $BootConfig[$i] & @CRLF & _ "Description: " & $BootConfig[$i] & @CRLF & _ "Scratch Directory: " & $BootConfig[$i] & @CRLF & _ "Setting ID: " & $BootConfig[$i] & @CRLF & _ "Temp Directory: " & $BootConfig[$i]) Next #endregion Boot Configuration #region ---- Internal Functions Func _ErrorMsg($message, $time = 0) MsgBox(48 + 262144, "Error!", $message, $time) ConsoleWrite("Error!" & $message & $time & @CRLF) EndFunc #endregion Internal Functions Func _ComputerGetBootConfig(ByRef $aBootConfigInfo) Local $colItems, $objWMIService, $objItem Dim $aBootConfigInfo, $i = 1 $objWMIService = ObjGet("winmgmts:\\" & $cI_Compname & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BootConfiguration", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems ReDim $aBootConfigInfo[UBound($aBootConfigInfo) + 1] $aBootConfigInfo[$i] = $objItem.Name $aBootConfigInfo[$i] = $objItem.BootDirectory $aBootConfigInfo[$i] = $objItem.ConfigurationPath $aBootConfigInfo[$i] = $objItem.LastDrive $aBootConfigInfo[$i] = $objItem.Description $aBootConfigInfo[$i] = $objItem.ScratchDirectory $aBootConfigInfo[$i] = $objItem.SettingID $aBootConfigInfo[$i] = $objItem.TempDirectory $i += 1 Next $aBootConfigInfo = UBound($aBootConfigInfo) - 1 If $aBootConfigInfo < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) EndIf EndFunc ;_ComputerGetBootConfig