-1

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.

zakparks31191
  • 919
  • 2
  • 21
  • 42
  • Please ask one question at a time, not two unrelated questions – David Heffernan Aug 15 '17 at 18:07
  • I'm not sure what you mean by "other apps which don't have this setback". Any installer that installs into Program Files generates a UAC prompt. That's the intended behaviour - if you're not an administrator, you don't get to install software in Program Files. – Harry Johnston Aug 15 '17 at 22:47
  • I removed the other question. By "other apps which don't have this setback" i suppose i meant "other apps that don't have external libraries/apps that don't prompt for admin rights" – zakparks31191 Aug 16 '17 at 13:41
  • But the external library shouldn't have anything to do with it - to install in Program Files, you MUST have admin rights. – Harry Johnston Aug 17 '17 at 02:11

1 Answers1

3

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?

PhilDW
  • 20,260
  • 1
  • 18
  • 28
  • This makes sense. I suppose for context, this is the first VS installer project I've ever made so I was unsure of some things. So would the UAC prompt only show up on the first launch? With the default VS 2010 installer project, there's no UAC prompt when launching the program, it just launches and hangs. – zakparks31191 Aug 16 '17 at 13:44