
我有一個使用儲存在 C:\ProgramData\MyApp 中的 config.xml 檔案的應用程式
設定檔是使用 MyConfigApp.exe 建立和編輯的,然後由實際應用程式 MyApp.exe 讀取。
在安裝過程中,我以管理員身份登錄,一切都很完美!然後我們以普通用戶身份登錄,這裡也運行得很好。
然後我們需要更改配置。這是使用者應該能夠執行的操作,因此我們啟動 MyConfigApp.exe 並更改配置。
但更改從未讀入 MyApp.exe。
我打開了 c:\ProgramData\MyApp\config.xml 以及其中的舊值。
現在我們發現使用者對ProgramData目錄沒有任何寫入權限。因此Windows在VirtualStore中創建了一個新文件,MyApp.exe不使用該文件
我們在 ProgramData(和子目錄)中新增了寫入權限,並從 VirtualStore 中刪除了 config.xml 檔案。
但每次使用者執行 MyConfigApp.exe 時,它都會在 VirtualStore 中建立一個檔案!
如何讓 MyConfigApp.exe 讀取和寫入 ProgramData 中的檔案?
答案1
我透過建立一個.manifest
與 exe 一起放置的文件,用我的舊應用程式解決了這個問題。沒有真正的問題,只是一個名為 的文字文件MyConfigApp.exe.manifest
,其中包含類似於下面的 XML 程式碼的內容。
根據微軟的說法,(參見https://msdn.microsoft.com/en-us/library/bb756929.aspx)具有平行清單檔案(如下所示)的 EXE 將不會參與檔案系統虛擬化,因為需要特定的執行級別,因此不會將內容新增至使用者的 VirtualStore 中。
但請注意,系統將要如果已有文件,請使用 VirtualStore。這是清單代碼:
<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="**your version number, make sure the numbers match the EXE**"
processorArchitecture="X86"
name="MyConfigApp"
type="win32"
/>
<description>SOLIDCast</description>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
</application>
</compatibility>
<!-- Identify the application security requirements: Vista and above -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"
/>
</requestedPrivileges>
</security>
</trustInfo>