Search code examples
c++xmlvisual-c++windows-installertinyxml

Xml file are saved in two different path


I created application that store some data to XML file. The issues is with the path of the XML saving. Am using TinyXML to save the data in vc++.

When I deploy this application, it installs in "C:\Program files(x86)\applicationname " and when I run the application the XML file is saving in

"C:\Users\UserName\AppData\Local\VirtualStore\Program Files (x86)\ApplicationName ".

I have made this application to work on system startup. So when I restart this application, the xml file is stored in different path "C:\Users\UserName\AppData\Local\VirtualStore\windows\sysWOW64"

I want my XML to be stored in the path where I installed or should be stored in appdata, application name

What should I do to store XML file in one places where application is installed?

doc.SaveFile( "test.xml" ); // xml saving code in tinyxml library

Solution

  • Firstly, this has nothing to do with C++, as the C++ code is probably working. Same with XML and tinyxml and even visual-c++.

    It seems that windows redirects those write accesses to a user-specific "VirtualStore\Program Files", but I'll leave it to you to research the actual semantics of that. On startup, when there is no user, this path obviously differs, since the former user is not logged in.

    Now, in order to get a fixed path, you can use the function GetModuleFileName() to find out the location of your executable and use that path to locate Smartmeter.xml. However, the problem you are facing now is that programs installed under "Program Files" don't magically gain write access rights to their install directory. This is to protect one user from messing with data of another user.

    I think that what you are doing is writing a program that runs in the background, which would be called a "service" under MS Windows. What is still unclear is what you want to achieve with this file and also what you are planning to do overall, and these are things that decide the future steps. In any case, take a look at the possibilities that services provide, maybe there is something that fits your needs.