[SOLVED] Problem with InStr(FileExist(path), "D")

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jNizM
Posts: 2422
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

[SOLVED] Problem with InStr(FileExist(path), "D")

03 Jul 2014, 08:05

I got a problem with if InStr(FileExist(path), "D") under Windows SBS 2008

Code: Select all

path := "C:\Windows\System32\winevt\Logs\"

if InStr(FileExist(path), "D")
    MsgBox % path "`nexists"
else
    MsgBox % path "`ndoes not exist"
Image


C:\Windows\System32\
- works with win 7
- works with sbs 2008

C:\Windows\System32\winevt\
- works with win 7
- dont work with sbs 2008

C:\Windows\System32\winevt\Logs\
- works with win 7
- dont work with sbs 2008
Last edited by jNizM on 04 Jul 2014, 02:07, edited 1 time in total.
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
joedf
Posts: 7075
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Problem with InStr(FileExist(path), "D")

03 Jul 2014, 08:28

Fileexist values? Errorlevel? A_lasterror?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 2133 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
jNizM
Posts: 2422
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Problem with InStr(FileExist(path), "D")

03 Jul 2014, 08:34

A_LastError = 0

Code: Select all

path := "C:\Windows\System32\winevt\Logs"
FileGetAttrib, OutputVar, % path
MsgBox % OutputVar "`n" A_LastError
- Win 7: MsgBox --> D (Error = 0)
- SBS: MsgBox --> empty (Error = 3)

edit
ERROR_PATH_NOT_FOUND
3 (0x3)
The system cannot find the path specified.

with powershell
Image
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
joedf
Posts: 7075
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Problem with InStr(FileExist(path), "D")

03 Jul 2014, 09:30

Hmm... By looking at autohotkey's source code, it seems that it uses FindFirstFile()... There seems to be a discussion about an inconsistency : http://msdn.microsoft.com/en-us/library ... 64418.aspx
FindFirstFile - Guidelines for Error-Handling
It is worth noting that it is important to check the return value of GetLastError(). All examples I found in a brief search on the Web simply check for FindFirstFile returning INVALID_HANDLE_VALUE and assume the file was not found. In this has happened, GetLastError() will return ERROR_FILE_NOT_FOUND. If any other return value occurs, it will indicate some other error - the file path passed in may be invalid for some reason, it may have been impossible to connect to a network drive, etc.
.... I might be wrong, but it seems that autohotkey only checks for INVALID_HANDLE_VALUE see: https://github.com/Lexikos/AutoHotkey_L ... autoit.cpp (search for "bool Line::Util_DoesFileExist(LPCTSTR szFilename)"

Another windows bug/quirk to work around?

Edit: I have submitted a bug report: http://ahkscript.org/boards/viewtopic.php?f=14&t=3864
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 2133 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
guest3456
Posts: 2541
Joined: 09 Oct 2013, 10:31

Re: Problem with InStr(FileExist(path), "D")

03 Jul 2014, 14:17

permissions maybe? is your user able to read that directory?

User avatar
jNizM
Posts: 2422
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Problem with InStr(FileExist(path), "D")

03 Jul 2014, 14:20

Sysadmin..
I can delete the logs in this folder manually
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Problem with InStr(FileExist(path), "D")

03 Jul 2014, 16:54

To call the function directly: (requires Struct.ahk)

Code: Select all

lpFileName := "C:\boot.ini"
_ := Struct("
(LTrim Join
  DWORD    dwFileAttributes;            
  DWORD    dwCreationTimeLowDateTime;   
  DWORD    dwCreationTimeHighDateTime;  
  DWORD    dwLastAccessTimeLowDateTime; 
  DWORD    dwLastAccessTimeHighDateTime;
  DWORD    dwLastWriteTimeLowDateTime;  
  DWORD    dwLastWriteTimeHighDateTime; 
  DWORD    nFileSizeHigh;               
  DWORD    nFileSizeLow;                
  DWORD    dwReserved0;                 
  DWORD    dwReserved1;                 
  TCHAR    cFileName[260];              
  TCHAR    cAlternateFileName[14];       
)")
ret := DllCall("FindFirstFile", "Str", lpFileName, "Ptr", _[] )
MsgBox, % ret "`n" ErrorLevel "`n" A_LastError
Gui, Add, ListView, R15, Field|Value
LV_Add("" , "dwFileAttributes"            , _.dwFileAttributes               )
LV_Add("" , "dwCreationTimeLowDateTime"   , _.dwCreationTimeLowDateTime      )
LV_Add("" , "dwCreationTimeHighDateTime"  , _.dwCreationTimeHighDateTime     )
LV_Add("" , "dwLastAccessTimeLowDateTime" , _.dwLastAccessTimeLowDateTime    )
LV_Add("" , "dwLastAccessTimeHighDateTime", _.dwLastAccessTimeHighDateTime   )
LV_Add("" , "dwLastWriteTimeLowDateTime"  , _.dwLastWriteTimeLowDateTime     )
LV_Add("" , "dwLastWriteTimeHighDateTime" , _.dwLastWriteTimeHighDateTime    )
LV_Add("" , "nFileSizeHigh"               , _.nFileSizeHigh                  )
LV_Add("" , "nFileSizeLow"                , _.nFileSizeLow                   )
LV_Add("" , "dwReserved0"                 , _.dwReserved0                    )
LV_Add("" , "dwReserved1"                 , _.dwReserved1                    )
LV_Add("" , "cFileName     "              , StrGet(_.cFileName[""])          )
LV_Add("" , "cAlternateFileName    "      , StrGet(_.cAlternateFileName[""]) )
LV_ModifyCol()
Gui, Show
return

GuiClose:
GuiEscape:
ExitApp
Note also that:
  • even though it is possible to access _files_ from a given directory, the NTFS permissions for the directory itself may prevent accessing the directory
  • even though the current user is the System Administrator, it is possible to restrict access to certain files and folders for that user through NTFS permissions
Perhaps comparing the NTFS permissions on both systems would help (or pasting them here).
lexikos
Posts: 6404
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Problem with InStr(FileExist(path), "D")

03 Jul 2014, 20:56

If you're running 32-bit AutoHotkey (or any 32-bit program) on a 64-bit OS, C:\Windows\System32 is redirected to C:\Windows\SysWow64. In that case, winevt most likely really doesn't exist at that path, as accessed from a 32-bit program.

For AutoHotkey 32-bit, use SysNative instead of System32.
joedf wrote:.... I might be wrong, but it seems that autohotkey only checks for INVALID_HANDLE_VALUE
That may be the case, but isn't relevant in this case since jNizM is getting ERROR_PATH_NOT_FOUND.
User avatar
jNizM
Posts: 2422
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Problem with InStr(FileExist(path), "D")

04 Jul 2014, 02:06

Thanks lexikos...
it works with %windir%\SysNative

reflinks
- File System Redirector
- The 'Sysnative' folder in 64-bit Windows explained
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
joedf
Posts: 7075
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: [SOLVED] Problem with InStr(FileExist(path), "D")

04 Jul 2014, 02:11

Ahh, I see :D
Note: at the time of my post I did not see the value of A_LastError.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 2133 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
just me
Posts: 6370
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [SOLVED] Problem with InStr(FileExist(path), "D")

04 Jul 2014, 02:23

Hi jNizM,

would you in future report the fact, that you are running different AHK versions under different OS'es in such cases, please?
User avatar
jNizM
Posts: 2422
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: [SOLVED] Problem with InStr(FileExist(path), "D")

04 Jul 2014, 02:35

sure
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
lexikos
Posts: 6404
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [SOLVED] Problem with InStr(FileExist(path), "D")

04 Jul 2014, 19:25

just me wrote:would you in future report the fact, that you are running different AHK versions under different OS'es in such cases, please?
I think in general, people don't report it because they get fixated on the OS, and don't consider that there are other differences between the two systems. Hence the first part of my answer to the FAQ:
Why does my script run fine in XP but not in Vista or Windows 7 or 8?
Since you've switched operating systems, it is likely that something else may have also changed which could be affecting your script. For instance, if you've got a new computer, it might differ in some way to the old computer. If you've also updated to a newer version of AutoHotkey, find out which version you had before and then check the changelog and compatibility notes.
...
Source: AutoHotkey FAQ
It doesn't hint at having different "flavours" of AutoHotkey, but I suppose that's only one of many things that could differ between two systems.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Odlanir, vsub and 243 guests