Jump to content
VADemon

File not returning a valid time/date

Recommended Posts

VADemon

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[13] = ["", "January", "February", "March", "April", "May", "Juny", "July", "August", "September", "October", "November", "December"]
    Local $dayNumber[7] = ["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[2]) ; last Modified
    if @error <> 10 then
        Local $year = $fModTime[2]
        Local $month = $fModTime[0]
        Local $day = $fModTime[1]
        Local $hour = $fModTime[3]
        Local $min = $fModTime[4]
        Local $sec = $fModTime[5]
        Local $ms = $fModTime[6]
        Local $weekday = $fModTime[7]
        
        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[2])) ; last Modified
        Local $year = $fModTime[2]
        Local $month = $fModTime[0]
        Local $day = $fModTime[1]
        Local $hour = $fModTime[3]
        Local $min = $fModTime[4]
        Local $sec = $fModTime[5]
        Local $ms = $fModTime[6]
        Local $weekday = $fModTime[7]
        
        ; 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

Share this post


Link to post
Share on other sites
careca

Try FileGetTime.

Other than that, the file is in use by some program that locks it or something, or is in read mode.

Dont see other options. Maybe a bug.


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
VIP

I don't know it help help for you or not:

#include <WinAPIFiles.au3>
#include <WinAPIHObj.au3>
#include <Date.au3>
#include <FileConstants.au3>

Global $iFileToWork = @ScriptFullPath

FileSetTime($iFileToWork, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC, $FT_CREATED)
FileSetTime($iFileToWork, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC, $FT_MODIFIED)
FileSetTime($iFileToWork, @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC, $FT_ACCESSED)

_FileGetTime($iFileToWork)


Func _FileGetTime($sFilePath)

    Local $Created_ArrayFileTime = FileGetTime($sFilePath, $FT_CREATED) ;  $FT_CREATED (1) = Created
    Local $Created_iYear = $Created_ArrayFileTime[0] ; = year (four digits)
    Local $Created_iMonth = $Created_ArrayFileTime[1] ; = month (range 01 - 12)
    Local $Created_iDay = $Created_ArrayFileTime[2] ; = day (range 01 - 31)
    Local $Created_iHour = $Created_ArrayFileTime[3] ; = hour (range 00 - 23)
    Local $Created_iMin = $Created_ArrayFileTime[4] ; = min (range 00 - 59)
    Local $Created_iSec = $Created_ArrayFileTime[5] ; = sec (range 00 - 59)
    Local $Created_iDayOfWeek = _DateToDayOfWeek($Created_iYear, $Created_iMonth, $Created_iDay)
    Local $Created_iDayName = _DateDayOfWeek($Created_iDayOfWeek)
    Local $Created_iMonthName = _DateToMonth($Created_iMonth)
    Local $Created_iShortTime = $Created_iYear & $Created_iMonth & $Created_iDay & $Created_iHour & $Created_iMin & $Created_iSec
    Local $Created_iLongTime = $Created_iYear & "/" & $Created_iMonth & "/" & $Created_iDay & " - " & $Created_iHour & ":" & $Created_iMin & ":" & $Created_iSec
    Local $Created_iLongTimeName = $Created_iDayName & "," & $Created_iMonthName & " " & $Created_iDay & "," & $Created_iYear
    ConsoleWrite("! File   : " & $sFilePath & @CRLF)
    ConsoleWrite("-DATE Created  : " & $Created_iLongTimeName & @CRLF)
    ConsoleWrite(">DATE Created S: " & $Created_iLongTime & @CRLF)
    ConsoleWrite("+DATE Created L: " & $Created_iShortTime & @CRLF)
    ConsoleWrite("-Year     : " & $Created_iYear & @CRLF)
    ConsoleWrite("-Mont     : " & $Created_iMonth & @CRLF)
    ConsoleWrite("-Day      : " & $Created_iDay & @CRLF)
    ConsoleWrite("-Hour     : " & $Created_iHour & @CRLF)
    ConsoleWrite("-Min      : " & $Created_iMin & @CRLF)
    ConsoleWrite("-Sec      : " & $Created_iSec & @CRLF)
    ConsoleWrite("-DayOfWeek: " & $Created_iDayOfWeek & @CRLF)
    ConsoleWrite("-DayName  : " & $Created_iDayName & @CRLF)
    ConsoleWrite("-MonthName: " & $Created_iMonthName & @CRLF)

    Local $Modified_ArrayFileTime = FileGetTime($sFilePath, $FT_MODIFIED) ;$FT_MODIFIED (0) = Last modified
    Local $Modified_iYear = $Modified_ArrayFileTime[0] ; = year (four digits)
    Local $Modified_iMonth = $Modified_ArrayFileTime[1] ; = month (range 01 - 12)
    Local $Modified_iDay = $Modified_ArrayFileTime[2] ; = day (range 01 - 31)
    Local $Modified_iHour = $Modified_ArrayFileTime[3] ; = hour (range 00 - 23)
    Local $Modified_iMin = $Modified_ArrayFileTime[4] ; = min (range 00 - 59)
    Local $Modified_iSec = $Modified_ArrayFileTime[5] ; = sec (range 00 - 59)
    Local $Modified_iDayOfWeek = _DateToDayOfWeek($Modified_iYear, $Modified_iMonth, $Modified_iDay)
    Local $Modified_iDayName = _DateDayOfWeek($Modified_iDayOfWeek)
    Local $Modified_iMonthName = _DateToMonth($Modified_iMonth)
    Local $Modified_iShortTime = $Modified_iYear & $Modified_iMonth & $Modified_iDay & $Modified_iHour & $Modified_iMin & $Modified_iSec
    Local $Modified_iLongTime = $Modified_iYear & "/" & $Modified_iMonth & "/" & $Modified_iDay & " - " & $Modified_iHour & ":" & $Modified_iMin & ":" & $Modified_iSec
    Local $Modified_iLongTimeName = $Modified_iDayName & "," & $Modified_iMonthName & " " & $Modified_iDay & "," & $Modified_iYear
    ConsoleWrite("! File   : " & $sFilePath & @CRLF)
    ConsoleWrite("-DATE Modified  : " & $Modified_iLongTimeName & @CRLF)
    ConsoleWrite(">DATE Modified S: " & $Modified_iLongTime & @CRLF)
    ConsoleWrite("+DATE Modified L: " & $Modified_iShortTime & @CRLF)
    ConsoleWrite("-Year     : " & $Modified_iYear & @CRLF)
    ConsoleWrite("-Mont     : " & $Modified_iMonth & @CRLF)
    ConsoleWrite("-Day      : " & $Modified_iDay & @CRLF)
    ConsoleWrite("-Hour     : " & $Modified_iHour & @CRLF)
    ConsoleWrite("-Min      : " & $Modified_iMin & @CRLF)
    ConsoleWrite("-Sec      : " & $Modified_iSec & @CRLF)
    ConsoleWrite("-DayOfWeek: " & $Modified_iDayOfWeek & @CRLF)
    ConsoleWrite("-DayName  : " & $Modified_iDayName & @CRLF)
    ConsoleWrite("-MonthName: " & $Modified_iMonthName & @CRLF)

    Local $Accessed_ArrayFileTime = FileGetTime($sFilePath, $FT_ACCESSED) ; $FT_ACCESSED (2) = Last accessed
    Local $Accessed_iYear = $Accessed_ArrayFileTime[0] ; = year (four digits)
    Local $Accessed_iMonth = $Accessed_ArrayFileTime[1] ; = month (range 01 - 12)
    Local $Accessed_iDay = $Accessed_ArrayFileTime[2] ; = day (range 01 - 31)
    Local $Accessed_iHour = $Accessed_ArrayFileTime[3] ; = hour (range 00 - 23)
    Local $Accessed_iMin = $Accessed_ArrayFileTime[4] ; = min (range 00 - 59)
    Local $Accessed_iSec = $Accessed_ArrayFileTime[5] ; = sec (range 00 - 59)
    Local $Accessed_iDayOfWeek = _DateToDayOfWeek($Accessed_iYear, $Accessed_iMonth, $Accessed_iDay)
    Local $Accessed_iDayName = _DateDayOfWeek($Accessed_iDayOfWeek)
    Local $Accessed_iMonthName = _DateToMonth($Accessed_iMonth)
    Local $Accessed_iShortTime = $Accessed_iYear & $Accessed_iMonth & $Accessed_iDay & $Accessed_iHour & $Accessed_iMin & $Accessed_iSec
    Local $Accessed_iLongTime = $Accessed_iYear & "/" & $Accessed_iMonth & "/" & $Accessed_iDay & " - " & $Accessed_iHour & ":" & $Accessed_iMin & ":" & $Accessed_iSec
    Local $Accessed_iLongTimeName = $Accessed_iDayName & "," & $Accessed_iMonthName & " " & $Accessed_iDay & "," & $Accessed_iYear
    ConsoleWrite("! File   : " & $sFilePath & @CRLF)
    ConsoleWrite("-DATE Accessed  : " & $Accessed_iLongTimeName & @CRLF)
    ConsoleWrite(">DATE Accessed S: " & $Accessed_iLongTime & @CRLF)
    ConsoleWrite("+DATE Accessed L: " & $Accessed_iShortTime & @CRLF)
    ConsoleWrite("-Year     : " & $Accessed_iYear & @CRLF)
    ConsoleWrite("-Mont     : " & $Accessed_iMonth & @CRLF)
    ConsoleWrite("-Day      : " & $Accessed_iDay & @CRLF)
    ConsoleWrite("-Hour     : " & $Accessed_iHour & @CRLF)
    ConsoleWrite("-Min      : " & $Accessed_iMin & @CRLF)
    ConsoleWrite("-Sec      : " & $Accessed_iSec & @CRLF)
    ConsoleWrite("-DayOfWeek: " & $Accessed_iDayOfWeek & @CRLF)
    ConsoleWrite("-DayName  : " & $Accessed_iDayName & @CRLF)
    ConsoleWrite("-MonthName: " & $Accessed_iMonthName & @CRLF)

    
EndFunc   ;==>_FileGetTime

 


Regards,
 

Share this post


Link to post
Share on other sites
VADemon

Thanks guys for the answers, took me too long to notice because I was supposed to be notified by email.

I was going to test VIP's code to debug, but the problem has somehow resolved itself. The exact same code of mine now returns the correct date and parses it without problems... A very strange edge-case. I don't think it was a lock problem like careca said, because these files shouldn't have been accessed by any programs and my tool opened them in read-mode anyway (to fetch the date).

In any way, I developed the code above in one go without reboots, maybe that fixed it. Windows 7 SP1 64-bit, NTFS. /thread

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

    • Jeep
      By Jeep
      Here is an other UDF for string handling :
      Date handling
      _StringDateConvert:  convert a date from one format ("YMD", "MDY" or "DMY") to another.
      _StringIsDate:  checks if a date with a given format is valid
      String management
      _StringCount: count of occurrences that appear in a string
      _StringFormatBytesSize: formatting a dimension expressed in bytes (bytes) in MB, TB, ...)
      _StringIsEndingWith: check if a string end with some characters
      _StringIsStartingWith: check if a string start with some characters
      _StringJoinArray:  concatenate elements of an array to rebuild a string
      _StringPadLeft: filling a string with characters on the left
      _StringPadRight: fill a string with characters on the right
      _StringRemoveFrenchAccent: remove french accent
      _StringRemoveChars: deleting characters from a string
      _StringStrip: eliminate characters at the begin and/or at the  end of a string
      _StringTitleCaseFrench: capitalize the first letter of each word with elimination of french accents
      _StringWSClean: simple replacement of "White Spaces",  remove beginning and trailing spaces and multiple spaces removal
      Any comments, suggestions for improvement or constructive criticism are welcome.
      Below you will find the UDF and a demo program. 
       
       
      JPD_String.zip
    • Skeletor
      By Skeletor
      Hey All,
      I'm trying to set the date using a variable.
      Basically, I set the date into the input box, then I change the input box, say, I change the year.
      Then I set what I typed into the input box into the Date Picker.

      This is a demo code.
      #include <ButtonConstants.au3> ;Start GUI includes #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <GuiDateTimePicker.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 438, 192, 124) $Date1 = GUICtrlCreateDate("2019/02/02 23:16:26", 80, 64, 186, 21, $DTS_SHORTDATEFORMAT) $Input1 = GUICtrlCreateInput("Input1", 80, 152, 185, 21) $Button1 = GUICtrlCreateButton("Set data", 176, 96, 75, 25) $Button2 = GUICtrlCreateButton("Read from input", 176, 200, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $Read = GUICtrlRead($Date1) GUICtrlSetData($Input1, $Read) MsgBox(-1, "", $Read) Case $Button2 $Read = GUICtrlRead($Input1) $New_date = StringReplace($Read, "/", "") $DAY = StringLeft($New_date, 2) $MON = StringMid($New_date, 4, 3) $YEAR = StringRight($New_date, 4) MsgBox(-1, "", $DAY & $MON & $YEAR) ;_GUICtrlDTP_SetFormat($hWndDate, "yyyy/MM/dd") $DateFormate = ($DAY & " " & $MON & " " & $YEAR) $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW GUICtrlSendMsg($Date1, $DateFormate, 0, "MM/dd/yyyy") EndSwitch WEnd  
    • TheDcoder
      By TheDcoder
      Hi, I thought I would never post a C/WinAPI related question in this forum ever, but here we are after a few years and me having learnt enough of C to write a basic console program
      My issue is that I am trying to read my child process's stdout output but ReadFile never returns if the child exits or if it is killed... very strange , I have been trying to work my way around this. The options I can think of are:
      Create a new thread and check for existance of the process constantly while reading Somehow make the pipe asynchronous (overlapped) so that I can read it in a non-blocking manner Fix ReadFile to return when the process ends Obviously I would prefer No. 3, I just want to make my program work. Here is my code if you guys want to take a look:
      // No text highlighting for C/C++ but we have it for C#? Blasphemy! bool allium_start(struct TorInstance *instance, char *config, allium_pipe *output_pipes) { char *cmd; // Figure out the command string for execution if (config) { char *parameters = " -f -"; cmd = malloc(strlen(instance->tor_path) + strlen(parameters) + 1); if (!cmd) return false; strcpy(cmd, instance->tor_path); strcat(cmd, parameters); } else cmd = instance->tor_path; // Prepare startup info with appropriate information SecureZeroMemory(&instance->startup_info, sizeof instance->startup_info); instance->startup_info.dwFlags = STARTF_USESTDHANDLES; SECURITY_ATTRIBUTES pipe_secu_attribs = {sizeof(SECURITY_ATTRIBUTES), NULL, true}; HANDLE pipes[2]; if (output_pipes == NULL) { CreatePipe(&pipes[0], &pipes[1], &pipe_secu_attribs, 0); output_pipes = pipes; } instance->startup_info.hStdOutput = output_pipes[1]; instance->startup_info.hStdError = output_pipes[1]; instance->stdout_pipe = output_pipes[0]; // Stored for internal reference if (config) { // Reuse the pipes array to store standard input pipes CreatePipe(&pipes[0], &pipes[1], &pipe_secu_attribs, 0); instance->startup_info.hStdInput = pipes[0]; } // Create the process bool success = CreateProcessA( NULL, cmd, NULL, NULL, config ? true : false, 0, NULL, NULL, &instance->startup_info, SecureZeroMemory(&instance->process, sizeof instance->process) ); // Free command string if needed if (config) free(cmd); // Write config to Tor's standard input unsigned long bytes_written; if (success) { WriteFile(pipes[1], config, strlen(config), &bytes_written, NULL); // Work around for simulating Ctrl + Z which sends the substitution character (ASCII 26), // this is needed in order for Tor to detect EOT/EOF while reading the config WriteFile(pipes[1], &(char){26}, 1, &bytes_written, NULL); } CloseHandle(pipes[1]); // Return on failure if (!success) return false; } char *allium_read_stdout_line(struct TorInstance *instance) { char *buffer = instance->buffer.data; // Check for valid buffer and allocate if needed if (instance->buffer.size == 0 || !buffer) { buffer = instance->buffer.data = malloc(instance->buffer.size = 80 + 1); if (!buffer) return NULL; } // Process the input unsigned int read_len = 0; while (true) { // Read data unsigned long bytes_read; if (ReadFile(instance->stdout_pipe, buffer, 1, &bytes_read, NULL) == false || bytes_read == 0) return NULL; // Check if we have reached end of line if (buffer[0] == '\n') break; // Proceed to the next character ++buffer; ++read_len; // Resize buffer if it is full if (read_len == instance->buffer.size) { char *new_buffer = malloc(instance->buffer.size += 50); if (new_buffer) memcpy(new_buffer, instance->buffer.data, read_len); free(instance->buffer.data); if (!new_buffer) return NULL; instance->buffer.data = new_buffer; buffer = instance->buffer.data + read_len; } } // Terminate the new line with null character and return // Special handling for Windows, terminate at CR if present buffer[read_len >= 2 && buffer[-1] == '\r' ? -1 : 0] = '\0'; } The allium_start function creates the redirection pipes and the child process, the other allium_read_stdout_line function reads from the stdout pipe created by the first function, ReadFile in this function does not return when the child ends or gets killed.

      I appriciate the help of the WinAPI gurus here, thanks in advance!
    • Jemboy
      By Jemboy
      Hi,
      Ones(some times twice) a month I get an e-mail with zip file, which has price updates from a supplier.
      I have to upload the file to an FTP to get it processed.
      When uploading the file, it will get "timestamped" with the time and date at which time the file was uploaded.
      Normally this is fine, because I mostly upload the file the same day.
      Sometimes it may take 1 or 2 days before I can upload the file.
      For historical purpose, I would like to have the file timestamped with the original date.
      I have tried using:  _FTP_Command ( $hFTPSession, "MFCT YYYYMMDDHHMMSS path") 
      however this command does not work or change the timestamp as I expected.
      Does anyone now a way how I can change the timestamp of a FTP-file?
    • astrionn
      By astrionn
      Hi Guys,
       
      I`m trying to record with my webcam in 5s intervalls and do some stuff between starting to record and stoping.
      I took code from here: https://www.autoitscript.com/forum/topic/27925-webcam-example/
      and took what looked relevant to me.
      I use 3 different files:
       Is called WMS.au3 and contains all the constants for the dll calls is called rec.au3 and does all necessary dll calls to start a webcam recording to a file Is called stopcam.exe and does the dll calls to stop recording into a file WMS.au3  :
      $WM_CAP_START = 0x400 $WM_CAP_UNICODE_START = $WM_CAP_START +100 $WM_CAP_PAL_SAVEA = $WM_CAP_START + 81 $WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81 $WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW $WM_CAP_ABORT = $WM_CAP_START + 69 $WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46 $WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43 $WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41 $WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42 $WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10 $WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11 $WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14 $WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12 $WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12 $WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13 $WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13 $WM_CAP_EDIT_COPY = $WM_CAP_START + 30 $WM_CAP_END = $WM_CAP_UNICODE_END $WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22 $WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21 $WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21 $WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23 $WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23 $WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25 $WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25 $WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20 $WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20 $WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24 $WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36 $WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1 $WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67 $WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67 $WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65 $WM_CAP_GET_STATUS = $WM_CAP_START + 54 $WM_CAP_GET_USER_DATA = $WM_CAP_START + 8 $WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44 $WM_CAP_GRAB_FRAME = $WM_CAP_START + 60 $WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61 $WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83 $WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84 $WM_CAP_PAL_OPENA = $WM_CAP_START + 80 $WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80 $WM_CAP_PAL_PASTE = $WM_CAP_START + 82 $WM_CAP_SEQUENCE = $WM_CAP_START + 62 $WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63 $WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35 $WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85 $WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2 $WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2 $WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5 $WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3 $WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3 $WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6 $WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7 $WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4 $WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66 $WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66 $WM_CAP_SET_OVERLAY = $WM_CAP_START + 51 $WM_CAP_SET_PREVIEW = $WM_CAP_START + 50 $WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52 $WM_CAP_SET_SCALE = $WM_CAP_START + 53 $WM_CAP_SET_SCROLL = $WM_CAP_START + 55 $WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64 $WM_CAP_SET_USER_DATA = $WM_CAP_START + 9 $WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45 $WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72 $WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71 $WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70 $WM_CAP_STOP = $WM_CAP_START + 68 rec.au3  :
       
      #include <WMS.au3> #include <GUIConstants.au3> if not FileExists(@ScriptDir&"\vid\"&string(@MON)&"\"&string(@mday)) Then DirCreate(@ScriptDir&"\vid\"&"\"&string(@MON)&"\"&string(@mday)) EndIf $moviefile = @ScriptDir&"\vid"&"\"&string(@MON)&"\"&string(@mday)&"\test.avi" $avi = DllOpen("avicap32.dll") $user = DllOpen("user32.dll") FileWrite(@scriptdir&"\clop.clop",$user) $Main = GUICreate("Camera",350,270) $moviefile=@ScriptDir&"\test.avi" $cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", 15, "int", 15, "int", 320, "int", 240, "hwnd", $Main, "int", 1) FileWrite(@scriptdir&"\clip.clip",$cap[0]) run(@scriptdir&"\stopcam.exe") DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", 0, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_FILE_SET_CAPTURE_FILEA, "int", 0, "str", $moviefile) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SEQUENCE, "int", 0, "int", 0) Stopcam.exe is the compiled version of this:
      #include "WMS.au3" #include <GUIConstants.au3> $cap = Int(FileRead(@scriptdir&"\clip.clip")) $user = int(fileread(@scriptdir&"\clop.clop")) Sleep(10000) DllCall($user, "int", "SendMessage", "hWnd", $cap, "int", $WM_CAP_STOP, "int", 0, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap, "int", $WM_CAP_END, "int", 0, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap, "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0) DllClose($user) FileDelete(@scriptdir&"\clip.clip") FileDelete(@scriptdir&"\clop.clop")  
      Unfortunately this is not working as I thought it would be working.
      Does someone see what I´m doing wrong?
      It should record the webcam for about 10 seconds ( a little less) and save that to an .avi file.
      It does not stop the recording , I have to stop the process manually...
      Secondly, which confuses me more is that it creates the test.avi not in the location is specified in the script... its stored in the ScriptDir for whatever reason haha
      I hope you can help me
       
      ~HappyCoding
×