Question

My program write some files at the windows system path (C:\windows\syswow64...).

One of this files, were deleted for test reason, we're changing something and we need to delete it. OK, there's no problem here, the file is gone(almost...). The problem is, my application still getting the file! It's fun, cause I really delete the file (shift+del)

I test if file exist with FileInfo class.

I'm going crazy with this. I can't see where is the mistake. And sure, in Folder Options is enable to see Hidden and System Files...

Thank you

My code is bellow:

Public Shared Function GetUserConfigFile() As String
    Dim UserConfigFile As String = Metodos.GetUserConfigPath("config.gf")
    'Above we have C:\Windows\SysWOW64\Microsoft\....\config.gf

    Dim ConfigFile As New IO.FileInfo(UserConfigFile)
    ConfigFile.Refresh()

    EventLog.RegisterDebugMessage("ConfigFile.Exists:{0};ConfigFile.Length:{1}", ConfigFile.Exists, ConfigFile.Length)
    If ((ConfigFile.Exists AndAlso ConfigFile.Length = 0) OrElse Not ConfigFile.Exists) Then
        Dim config As StreamWriter = IO.File.CreateText(UserConfigFile)
        config.WriteLine("<?xml version=""1.0""?><cnfg></cnfg> ")
        config.Close()
        config.Dispose()
    End If
    EventLog.RegisterDebugMessage("config.gf -> {0}", IO.File.ReadAllText(UserConfigFile))
    '''''''''''And here it's show me the content of the file... -.-''''''

    Return UserConfigFile
End Function
Was it helpful?

Solution

On a very similar note to what Mark Peters said, another thing that could be happening is UAC Data Redirection because you do not have write permissions to that folder so what you are really seeing is files located in %LOCALAPPDATA%\VirtualStore\Windows\System32. Does your application run with administrative privileges, if not, do the files go missing when it does?

I have a much longer post describing a similar issue over on Super User.

As an aside why do you "need" to have your program be accessing files in the windows directory? What are you doing that adds that requirement to your program?

OTHER TIPS

I would guess that you are being hit by the file system redirector (MSDN)

In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64. Access to %windir%\lastgood\system32 is redirected to %windir%\lastgood\SysWOW64. Access to %windir%\regedit.exe is redirected to %windir%\SysWOW64\regedit.exe.

There's some magic that happens with the System32 and SYSWOW64 folders. (Ironically,the 32-bit files are stored in WOW64 and the 64-bit files are stored in System32)

The MSDN page suggests a posible solution:

32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. This mechanism is flexible and easy to use, therefore, it is the recommended mechanism to bypass file system redirection. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top