简体   繁体   中英

How to use an unmanaged DLL in VS installer project, but without the user needing admin rights?

I'm creating an installer for a C# project. It requires an unmanaged 3rd party C++ dll to connect to a hardware device. When I run the project from the debugger, or when I right click -> Run as Administrator on the installed program, everything works normally. However if I don't run this as administrator in some fashion, it crashes. So how do I set up the installer to not need admin rights to run? I know I can set the requestedExecutionLevel in the app.manifest to requireAdministrator , but I don't want the UAC prompt every time, and I'm not sure the end user's machines will be able to run anything as admin.

My current workaround is to just install it directly to the C:/, but I'd like to install it to the same Program Files directory all the other apps are installed to which don't have this setback.

Limited users can't circumvent security restrictions just because they are running an install. Writing to the ProgramFiles folder requires elevation (as do perhaps some other things the install does) so there is no choice other than elevating the install - and it will show a UAC elevation prompt. You haven't said what tool you're using to build your MSI, but an MSI doesn't use a manifest and (to use WiX as an example) elevation uses the Package InstallPrivileges element.

The user doesn't NEED to be admin because the UAC prompt will allow an administrator to type their credentials "over the shoulder" for the install to work, if that turns out to be possible. There are also managed deployment options in corporate-type GPO install where the user doesn't need to be elevated.

Having the MSI call your code requires creating a custom action that the install will call - it has a required calling convention. Then you can call from that into your 3rd party C++ Dll. Without knowing more about the call you want to make it's difficult to add any more information. Is the call early in the install (from the UI maybe)? After the install? Is it a condition of the install? Could it be done as a configuration check in the app after the install?

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