开发者

How do you ensure windows applications and windows services access the same ProgramData on Win2008 x64?

开发者 https://www.devze.com 2022-12-09 14:42 出处:网络
I have a windows forms application that reads and updates an XML file with information which a windows service must act on.

I have a windows forms application that reads and updates an XML file with information which a windows service must act on.

This has been working on Windows Server 2003, XP and Vista (x32) for some time.

Now, when installed on Windows Server 2008 x64, strange things have started happening, thanks I assume to the User "VirtualStore" folder redirecting security arrangement (which as you can tell I don't fully understand yet).

The Windows Forms app wants to create, read and update the files in c:\user\username\appdata\local\virtualstore\programdata\appname but the service seems happy reading the data from the file in c:\program files\appname...

The result is they are looking at different data.

Now, if I set both executables to "run as an administrator" via the properties/compatibility tab, this problem goes away and the file in c:\program files\appname is used as expected.

However, this feels less than ideal.

As you can probably tell, I am not really aware of most of the issues / factors at work here.

This question is possibly too broad to answer well on Stack Overflow but can someone point in the right direction or alert me to what I need to understand so that my applications can work properly in the Win2008 x64 environment, and continue to work as they do now, on XP, Vista x32 etc.

My user base is not at all technical so I don't want to force them to be making technical "behind the scenes" changes - if possible, I want the setup program to handle开发者_开发技巧 this for them.


From your question it seems you are storing data in c:\program files\appname

You shouldn't store any user or application modified data in c:\program files, it should only contain the static executable and support files written at installation. Simply store these things in ProgramData from the outset.

You should get the path to ProgramData from the environment variable ALLUSERSPROFILE (which also means it will work on XP, where it points to All Users). Alternatively if you want to have per user data use USERPROFILE instead.

This is all due to security changes, but the directory virtualisation that takes place can be extremely confusing. Especially for example if you install as admin (so all goes as expected) but then run as a normal user (where it starts pointing elsewhere).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号