0

I intend to share a Visual C# application using a setup project in Visual Studio Community, however after several configuration fixes (application not finding a DLL, for instance), it has a strange behavior:

  • When opened using the generated shortcut or when it is located in Program Files (x86), it won't start, even though it is running in the task manager.
  • When opened using administrative rights, it opens flawlessly.
  • When copied in another folder than Program Files (x86), it opens flawlessly also.

I use the Visual Studio Installer to create the setup project. The problem is not that the application doesn't start, obviously, it is that it needs special manipulations after setup to be run by the user, which is of course something I try to avoid when sharing a program with a community.

So, is there some special configuration to use when creating a project so that an application can be run by any user without any "tuning" after the installation process?

Thank you for your answers! :)

~Stéphane

  • 1
    Are you (or better your application) trying to write in the Program Files folder? – Steve Jun 23 '16 at 14:52
  • Good point @Steve - if you're trying to write to the relative path of where the program is running from, it might be throwing exceptions (and not appearing) when writing to Program Files as it doesn't have necessary rights (ergo - it works fine when running as Admin) – Geoff James Jun 23 '16 at 14:54
  • I was under the impression that VS post-2010 no longer supported old-fashioned MSI-based Setup projects. Are you somehow using one of those, or do you mean you're publishing your project with ClickOnce? – adv12 Jun 23 '16 at 14:54
  • @adv12 - I'm sure you can still create a setup project > VS2010? – Geoff James Jun 23 '16 at 14:55
  • To force your app to run as admin (and show UAC prompt), see here: http://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator – Geoff James Jun 23 '16 at 14:58
  • 7
    Don't force it to run as admin, just fix the program so it doesn't try to write to its own directory. Data goes in the AppData folder. – Cody Gray - on strike Jun 23 '16 at 14:59
  • @CodyGray - Good point. I suppose it does depend what data is wanting to be written and why as to where it's written, though (that is, if this is causing the problem in the first place) – Geoff James Jun 23 '16 at 15:03
  • @Steve The application is not writing in the Program Files, or at least it is not supposed to: it simply reads images and an SQLite database... I'll double-check if there's an issue on this side. Thanks! –  Jun 23 '16 at 15:24

1 Answers1

0

Following @Steve indications, I investigated the way my program was working: it was trying to open its SQLite database in the same folder... with Read/Write access!! As it was not allowed to do so in Program Files (x86), it would freeze at initialization without any warning of any sort. When adding flags, it then ran with no issues:

SQLiteConnection db = new SQLiteConnection(Data.path, SQLiteOpenFlags.ReadOnly);

Hope this given solution will help others!

  • 3
    Hmm, you haven't done the other 90% of the project yet. Ensuring your program fails with a good diagnostic that helps the user figure out how to fix the problem. – Hans Passant Jun 23 '16 at 16:45
  • Understood. This is very good advice! I will read more documents to get my hands on C# development and publication! –  Jun 23 '16 at 17:08
  • It may not apply in your case, because I don't know the details of your code. But I have to wonder, why would you have a database that is read-only? Surely at some point the app is going to have to write data to the database in order to make it useful. If that's the case, this will only get you so far. The database should probably be stored in the user's AppData folder, rather than in the same folder as the EXE. Then you have read/write privileges. As for failing with a good diagnostic, that requires checking error codes/return values (when applicable), and handling *specific* exceptions. – Cody Gray - on strike Jun 24 '16 at 04:21
  • That's true, though, I only need it for read access, the application doesn't need more than displaying some information from this database. Maybe in the future, I'll see; but the purpose of the application would be severely different. As for diagnostics, I'm working on it. –  Jun 24 '16 at 19:09