Search code examples
c#vb.netexplorerfileinfohidden-files

File does not show on explorer, but VB.NET open it


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

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?