0

I have a problem when I install my Windows Forms App in a computer. The .exe file doesn't do anything when I click it. To start the aplication, I have to run the program as administrator. It is developed in C#, .Net Framework 4.7.2 and I install it in a computer with Windows 10. THanks!

  • are you writing to any file in the program directory? writing to this folder requires admin permission. Check the event-viewer to see if there is any errors. – JonasH Sep 15 '21 at 13:46
  • Could be an issue with windows defender. It usually does not like .exe files from untrusted sources (which includes unsigned .exe even from your own computer). – Marc Pfister Sep 15 '21 at 13:51
  • Yes, I save photos to a folder and when the program starts I create that folder in the program's directory. If I want to save a file in any place, must I require admin permission? @JonasH – Aarón De Bernardo Sep 15 '21 at 13:53
  • 2
    Do not save files in the program files folder. Use the one of the [special folders for application data](https://stackoverflow.com/questions/16276139/what-is-the-difference-between-programdata-and-appdata) – JonasH Sep 15 '21 at 13:55
  • Are you saying that your program works when you _Right-Click, Run as Admin_, but it seems to do nothing when you double-click it? In that case, you are doing something that requires admin rights (what, we can't tell from your description). Look at the event log, you may see the crash. Use SysInternals' Process Monitor to figure out what you're trying to do (if you can't tell). If you want admin access, add a _manifest_ to your app – Flydog57 Sep 15 '21 at 14:07
  • Another option is to launch your application from the command line, and see if some errors show up. – XouDo Sep 22 '21 at 06:23

1 Answers1

1

You should not save anything to the application folder i program files. You should use a separate folder for any data that might change. There are a few locations to chose from:

  • ProgramData contains application data that is not user specific.This data will be available to all users on the computer. Any global data should be put in here.
  • AppData folder contains configuration settings, downloaded information/files for a particular user. So, for example any user specific preferences and profile configurations can be stored in the AppData folder. The AppData folder is further divided into three subfolders
    • Roaming - This folder contains data that can move with your user profile from a computer to another.
    • Local - This folder contains data that will not move with your user profile.
    • LocalLow - You can put in lowlevel access information such as information related to web browser running in a protected mode in this folder.

source

The location for these folders can be accessed by using Special Folders

string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
JonasH
  • 28,608
  • 2
  • 10
  • 23