0

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
Flexo
  • 87,323
  • 22
  • 191
  • 272
user1858925
  • 59
  • 1
  • 10

1 Answers1

0

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.

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
  • Thanks a lot. Described me very well. Actually my application monitors the PC Activity every now and then. So are you saying that if the user doesnt log in, the start up application will save the xml in different path ? But once i logged in, the xml should be stored in the installed path. what should i do now – user1858925 Jan 20 '13 at 09:28
  • If i run my application as administrator, the xml is generated in installed path, and if i restart my PC, the application is not started up again. There is no process running. But If i run my application not as an administrator, the xml is generated in installed path, and if i restart my PC, the application is running in the background but generating the xml in different path ie sysWOW64 – user1858925 Jan 20 '13 at 09:30
  • Does "background process monitoring PC activity" describe your program? In that case, you have a prime example of a service. You can configure services to start on boot or allow users to start them. Even if a user starts it, the service does not necessarily run under that user's account and with that user's privileges. Things like changing directories are solved as a by-product of converting to a service. There is also a way to run a command-line program as service without coding the registration into the program itself. Summary: Look into writing a service, they exactly match your case! – Ulrich Eckhardt Jan 20 '13 at 11:31