简体   繁体   中英

Administrative rights: Winforms vs WPF

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)

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

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 to Environment.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM