管理权限:Winforms 与 WPF
我一直在将 Winforms 应用程序移植到 WPF,并注意到以下有关管理权限的内容。 应用程序使用“ProcessStartInfo”启动命令行外部应用程序作为其执行的一部分。 Winforms 应用程序没有应用程序清单,并且可以正确运行应用程序。 但是,除非我授予 WPF 应用程序管理权限,否则 WPF 版本将无法正确启动外部应用程序。 ()
我不想这样做,因为 UAC 确认对话框有些烦人。 我尝试添加 'ProcessStartInfo' Verb = "runas" 但这没有效果。
有谁知道为什么Winforms版本可以,但WPF版本需要管理员权限?供参考。外部应用程序处理文件并将输出文件写入programdata目录中的文件夹中)
I have been porting a Winforms app to WPF and have noticed the following regarding administrative rights.
The application launches a command line exeternal app as part of its execution using 'ProcessStartInfo'. The Winforms app has no application manifest and runs the app correctly.
However the WPF version won't launch the external app correctly UNLESS I give the WPF application administrative rights. ()
I'd prefer not to do this because of the somewhat annoying UAC confirmation dialog.
I've tried adding the 'ProcessStartInfo' Verb = "runas" but that has no effect.
Does anyone know why the Winforms version is OK but the WPF version requires admin rights? FYI. The external app process a file and writes the output file into a folder in the programdata directory)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎从 Wpf 应用程序启动的外部进程无权访问 ProgrammData 文件夹,尽管父应用程序可以访问。 (是的,我确实需要写入 PrgrammData 中的文件夹。我有需要使用数据的系统服务,而这些服务不了解用户...)
通过让外部应用程序写入 Environment.SpecialFolder.ApplicationData,然后让父应用程序将文件从Environment.SpecialFolder.ApplicationData移动到programdata...事情的工作方式与Winforms应用程序中一样
It seems that external process launched from Wpf apps don't have access to the ProgrammData folder, although the parent app does. (Yes I do actually need to write to folders within PrgrammData. I have system services that need to consume data and these services have no knowledge of users...)
By having the external app write to Environment.SpecialFolder.ApplicationData and then have the parent app move the files from Environment.SpecialFolder.ApplicationData to programdata... things work as in the Winforms apps
不建议写入程序文件。如果您可以控制这些系统服务,请修改它们以从
Environment.SpecialFolder.CommonApplicationData
文件夹中获取数据,该位置不是特定于用户的并且在整个系统中共享。然后,您的可执行文件会将其输出写入Environment.SpecialFolder.CommonApplicationData
。ProgramData 位于哪里?如果它位于 Program Files 下,那么您的 WinForms 和 WPF 应用程序都应该具有写入它的管理员权限。
Writing to Program Files is not advised. If you have control over those system services, modify them to take the data from
Environment.SpecialFolder.CommonApplicationData
folder, this location is not user-specific and shared across the system. Then your executable will write its output toEnvironment.SpecialFolder.CommonApplicationData
.Where ProgramData is located? If it's under Program Files, then both your WinForms and WPF applications should have administrator rights to write to it.