获取每个用户的应用程序数据文件夹
在我的应用程序中,每个用户都有自己的设置,我将其保存到该用户的应用程序数据目录中的子目录中。在卸载过程中,我想删除计算机上每个用户的这些设置。我怎样才能在 Inno Setup 中做到这一点?
换句话说,我需要获取一个包含每个用户的应用程序数据目录(而不是共享的应用程序数据目录)的列表,以便我可以从那里删除 MyAwesomeApp
目录。有什么办法可以做到这一点吗?
In my application, every user has its own settings, that I save to a subdirectory in that user's Application Data directory. During uninstall, I want to delete those settings for every user on the computer. How can I do that in Inno Setup?
In other words, I need to get a list that contains Application Data directory for each user (not the shared Application Data directory), so that I can delete the MyAwesomeApp
directory from there. Is there some way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 Windows 的设计,您不能这样做。
同样的设计也阻止您访问配置文件文件夹。
除此之外,公认的最佳做法是保留用户的数据,以防他们想要重新安装、漫游配置文件等。
You can't, due to the design of Windows.
The same design stops you accessing the profile folders too.
On top of this, it's accepted best practice to leave the user's data behind in case they want to reinstall it, roaming profiles, etc.
假设您的卸载程序以管理员权限运行,您只需获取用户目录,然后枚举其中的所有用户目录。
您可以从 Inno Setup 运行用您想要的任何语言编写的可执行文件。在其中,您可以首先使用 SHGetSpecialFolderPath 函数。对于 Win7,它看起来像这样:
您可以使用 GetUserName 获取用户名(本例中为 MyUser),并找到父目录并将字符串拆分到父目录“C:\Users\”和“应用程序数据\漫游\”。然后,您可以使用 FindFirstFile/FindNextFile 枚举所有用户目录,只需将第二部分“AppData\Roaming\”附加到它们,并检查文件是否存在。通过分割从 SHGetSpecialFolderPath 获得的目录,您可以确保它在 XP(将返回类似 C:\Documents and Settings\MyUser\Application Data" 的内容)和 Win7 中都可以工作。基本上,您只需将 MyUser 替换为所有用户名即可在 SHGetSpecialFolderPath 返回的字符串中,
我不知道这是否会避免操作系统安全或是否适用于漫游用户。
Assuming that your uninstaller runs with administrator priviledges, you can just get the User directory and then enumerate all the user directories there.
You can run an executable from Inno Setup written in whatever language you want. In it you can first get the current user's Application Data directory, using the SHGetSpecialFolderPath function. It would look something like this for Win7:
You can use GetUserName to get the user's name (MyUser in this case), and find the parent directory and split the string to the parent directory "C:\Users\" and "AppData\Roaming\". You can then use FindFirstFile/FindNextFile to enumerate all users directories, and just append the second part "AppData\Roaming\" to them, and check if the file exists. By splitting the directory you get from SHGetSpecialFolderPath you ensure it would work both in XP (which would return something like C:\Documents and Settings\MyUser\Application Data") and in Win7. Basically you just replace MyUser with all the users' names in the string returned by SHGetSpecialFolderPath.
I have no idea if this avoids OS security or if it works with roaming users.