none
Reading file under Windows\System32 is getting an undesired redirection to Windows\WinSxS RRS feed

  • Question

  • Under VB in a Windows Form app, I am trying to read an XML file as follows:

            Dim recDoc As XmlDocument = New XmlDocument
            recDoc.Load("C:\Windows\System32\Recovery\ReAgent.xml")

    What I have discovered is that it is actually reading a file of the same name under C:\Windows\WinSxS\wow64_microsoft_windows...

    I tried using

               Dim xmlString = My.Computer.FileSystem.ReadAllText("C:\Windows\System32\Recovery\ReAgent.xml")

    but it too fails in the same way.

    No difference whether I'm running the app as administrator or not. Since the two versions of the file are very different, is there any way to actually force it to read from where I am asking it to read. I have no trouble at all in Windows Explorer in being able to access the correct file.

    Saturday, January 25, 2020 10:22 PM

Answers

  • Go to Project Properties, Compile tab, and try unselecting “Prefer 32-bit” option.

    Or go to menu, Build, Configuration Manager, and create and use a new platform: “x64”.

    • Marked as answer by AZBruno Sunday, January 26, 2020 5:19 PM
    Sunday, January 26, 2020 9:04 AM

All replies

  • Hi

    Here, those two code lines resulted in the correct file being loaded. Here is the result.

    .


    Regards Les, Livingston, Scotland

    Saturday, January 25, 2020 10:44 PM
  • Thanks for trying it, Les. I just looked at the recDoc.BaseRI and it shows exactly as yours. But the XML is not right.

    What I'd done is search the entire \Windows folder for a file of the same name and after finding the one mentioned in the original post, I saw the contents matched what I was seeing being read. When I manually copied the file outside of the Windows folder and tried to read it, all was fine.

    Sunday, January 26, 2020 1:09 AM
  • Hi

    OK, I get the file contents from the file as per your post, and the contents loaded by your code into  recDoc.InnerXml to be identical. I haven't tried to find any other file.

    A quick look with Google seems to suggest that that file is subject to being copied many times to other locations.


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, January 26, 2020 1:58 AM
    Sunday, January 26, 2020 1:55 AM
  • I did an experiment. I created a batch file called D:\CopyReagent.bat containing the command

    copy C:\Windows\System32\Recovery\ReAgent.xml  d:\NewReAgent.xml

    If I run this batch file from Windows Explorer, it works fine. If I run the code from VB in my app using Process.Start ("D:\CopyReagent.bat"), I get the wrong file copied.

    I've been searching for a way to guarantee it works. What I have not yet tried is the various cleanup methods for the WinSxS store. I'm hesitating to see if I can find a working solution. I'm concerned as the program I'm building will be run on many systems.

    Sunday, January 26, 2020 2:12 AM
  • Hi

    Of course, the system does not react kindly to being messed with 😊


    Regards Les, Livingston, Scotland

    Sunday, January 26, 2020 2:23 AM
  • Les, can you try the batch file approach and then compare the file modification date on the copied file with the correct file in Windows\System32\Recovery.

    On my system, when I copy the file using the batch file under Windows Explorer, the modified date matches at 08/07/2019. When copying from VB and it copies the wrong file, the date modified is 03/18/2018.

    I'm wondering if 1) you do not have a WinSxS version elsewhere, or 2) you do and it just looks like the correct one. BTW, I tried a non-debug build and that made no difference,

    Sunday, January 26, 2020 3:26 AM
  • Go to Project Properties, Compile tab, and try unselecting “Prefer 32-bit” option.

    Or go to menu, Build, Configuration Manager, and create and use a new platform: “x64”.

    • Marked as answer by AZBruno Sunday, January 26, 2020 5:19 PM
    Sunday, January 26, 2020 9:04 AM
  • Go to Project Properties, Compile tab, and try unselecting “Prefer 32-bit” option.

    Or go to menu, Build, Configuration Manager, and create and use a new platform: “x64”.

    I took the first option and now it works. Thanks so much.

    Can you explain why, or direct me to some documentation that will explain this?

    Sunday, January 26, 2020 5:20 PM
  • On 64-bit windows you can run 32-bit programs too, but sometimes 32-bit programs need separate resources (e.g. system files) that cannot be shared with 64-bit programs. “The system isolates 32-bit applications from 64-bit applications, which includes preventing file and registry collisions” [https://docs.microsoft.com/en-us/windows/win32/winprog64/running-32-bit-applications].

    Windows includes a series of “redirectors” that forward 32-bit callers to special items.

    In order to access the right files and registry of 64-bit Operating System, the program should run in 64-bit mode. (Or else some special methods can be used).

    Sunday, January 26, 2020 5:56 PM
  • Now I understand what happened. I was wrong in thinking the redirection was to Windows\WinSxS. It was actually to Windows\SysWOW64. I'd missed finding the file there.

    The link really cleared it up.

    Monday, January 27, 2020 5:28 AM