Winform application not running after installing into program files directory - c#

I had created a windows form application and used setup project to create installer. But after installing my application the application is not opening from the location it is installed("c:\Programs Files(86x)\"). But the application runs fine if i copy the entire installed files to another drive. Actually my application is creating some folder inside the installed directory when running. so i thought it is some problem related to windows permissions. I had set app privileges as "requireAdministrator" and still not working. Can anyone help me with a solution?

Actually my application is creating some folder inside the installed directory when running.
Don't do that!
The Program Files folder is read only to standard users, and has been since Windows 2000. And since Windows Vista even Administrator users will require elevation to get write access into this folder.
Use the All Users Application Data folder instead (Environment.SpecialFolder.CommonApplicationData).
The alternative is an advanced installer product (meaning purchasing the full version of InstallShield or similar rather than the version included with Visual Studio) which supports adding an action to your install process that both creates the folder and sets new permissions, and does this at install time. But that's really a cheat, anyway. Just use Application Data.

Related

C# Winform Application Only Working as Run as Administrator

I am working on a application which is Windows Form Application and performs the CRUD operations in Microsoft Access Database (.mdb).
Old application :
The application was developed in C# with Microsoft .Net Framework 4.0.
The previous developers used Visual Studio installer projects to create the setup file.
The default installation path is "C:\Program Files (x86)\MyProduct".
This folder will have the MyProduct.exe executable and dependent dlls and also and Microsoft Access database file (.mdb). The shortcut will be created on desktop. When you run the MyProduct.exe it can access the database without any errors and can perform the CRUD operations.
New Application:
Now I have upgraded the .Net framework to 4.5.2 and used Installshield to create the installer. Installation path will be same "C:\Program Files (x86)\MyProduct".
Now the problem is, when I execute the exe and do any insert/update/delete operation it throws the error that "operation must use an updateable query". This means the database is not accessible. I tried running the exe as an administrator user and then only it is working fine.
My operating system is Window 10.
Note : I modified the database.mdb properties and provided FullControl to all the users for both new and old versions. But new version is not working without the admin user.
For the newer version I changed the installation path to "C:\My Folder\MyProduct" and it is working without any error. Only C:\Program Files is giving the error. The strange thing is older version is also installed in Program Files but it does not throw any errors.
Other difference between old and new application is, Older version uses Microsoft JET engine driver to use Microsoft Access database, while newer version uses Microsoft ACE OLEDB driver to use Microsoft Access Database.
I am not sure why this is happening. Older version is working but newer is not.
Can any one help me with this?
I would move the install to %userappdata% or some folder that does not require elevated rights. While you can place the .exe in program files, ANY data file in those locations tends to have VERY limited rights these days (they continue to lock down windows more and more).
Also, be carefull. Even if you say installed to my docuemnts? If you REQUIRE elevated rights during that install, then of then often DURING the install then the files and folder you create ALSO will have elevated rights.
So, don't place ANY data files or files that your code has to read in program files. These days such system folders tend to be restriced and have locked down rights.
%appdata% is your best bet. That will in most cases translate to:
C:\Users\AlbertKallal\AppData\Roaming
This ALSO means that your code better not have hard coded path names either. (you get/grab your path from the executing assembly. If you have a lot of code, and paths are hard coded? Then you can bite the bullet and say install to c:\MyCoolApp or some folder you create in the c:\ drive. However, with so many people doing remote work, then even c:\SomeFolder can be a bad choice, since on terminal services, all users share the same c:\ drive.
So, move the install out of program files, or at the very least move out the data file parts to a known read/write folder that all users by default will have rights to, and not require elevated rights to use such folders. So, be very aware of any data file parts you have as part of your install. As noted %appdata% is a good choice, but then keep in mind that the path names to the executable and the data file location will be dynamic (the users name will be part of the path name). And if you don't think you ever support terminal services or remote desktop? Then you can use/risk a hard coded c:\MyApp folder approach here.
At the end of the day, you REALLY need to avoid elevated rights DURING the install, and this is especially the case if data files are part of the install - since those files will ALSO inherit the elevated rights during the install. And for sure using program file which was common 10 or 15 years ago for programs AND data? Well the program part is still ok, but any data files now can't for all practical purposes be placed in program files.

attempt to write a read-only database sqlite Wpf inno setup [duplicate]

I am developing desktop database application. Using rdlc report and reportviewer. Everything was fine in developing process, reportviewer was showing all data smoothly. I deploy app with Inno Setup. But when I install the app, the reportviewer is not showing data. While data is correctly inserted in the tables.
For applications that work incorrectly or fail completely, when installed by Inno Setup to Program Files folder, the first thing to test, is to try to deploy the application manually to the same folder.
If the application fails even after a manual deployment, the most usual problem is that the application requires a user to have write permissions to application folder. As on modern versions of Windows a user typically does not have write permissions to the Program Files folder, the application does not work. So the problem usually has nothing to do with Inno Setup, but it's a problem of the application itself.
To solve the problem:
The best solution is to redesign the application so that it does not require write permissions to its folder. Windows applications should not require write permissions to their folder. That's against Windows guidelines. The application should write data to a user profile folder (C:\Users\username\AppData) or to a common data folder (C:\ProgramData).
A dirty workaround is have the installer grant a user(s) write permissions to the installation folder. Do that only, if you cannot get the application fixed (e.g. it's 3rd party application).
See Inno Setup - How to set permissions of installation folder.
Even more gross workaround is to configure the application to be executed with elevated (Administrator) privileges.
See Inno Setup desktop shortcut (link) which has "Run as administrator" advanced property set
or How to set 'Run as administrator' on a file using Inno Setup.
Another solution is enabling legacy compatibility mode that makes Windows redirect all application write attempts to a virtual store. See also Application installed with Inno Setup writes files to unknown location instead of its installation folder.
There are numerous other possible reasons, why the application might be failing when installed, including:
You omitted some dependency:
DLL library
.NET assembly
.NET Framework
Java Runtime Environment
other runtime
COM/ActiveX object, etc.
The application requires some configuration:
a file
a registry key [including COM/ActiveX object registration]
an environment variable, etc.
The application is not designed to be executed from a folder that has a space in its name (Program Files).
The application gets confused by Windows File virtualization (though it's unlikely). See Application installed with Inno Setup writes files to unknown location instead of its installation folder.

How to Resolve this - Enter an alternate path to a folder containing the installation package

A long time back I developped a Windows service with c# 4.0 and also created a setup file with VS2010 for that app. I installed that app and it was running. someone removed that Windows service not properly like removing some entry from registry regarding that app and as a result that app name is not showing in ADD/Remove list and removed all files and folder from program files folder related to that Windows service.
So when I try to run the setup file for that win service to install it in my pc then I am getting the error message Enter an alternate path to a folder containing the installation package
so guide me how could I again install that Windows service in my pc from that setup. thanks
I've found the "Windows Installer cleanup uitlity" to be enormously helpful in situations like this. It's an abandoned project, but you can still get it by googling. You can use it to completely remove a program from your computer, after which it won't conflict with a new installation.
I found it here:
www.majorgeeks.com
Simply download the file needed and provide the [un]installer with the download folder. And press OK. You can do it without interrupting the process. Do not use the Windows Installer Cleanup Utility It is not supported and extremely dangerous!

Providing Directory's Full Control for Non-admin Users under Windows 7

I'm working on a software written in C# and for .NET Framework 3.5. The installer for the software is created by a "Setup and Deployment > Setup Project" from Visual Studio 2008. Originally the software was written for Windows XP. Now I need to modify it so that it also works under Windows 7.
In Windows 7, admin privilege is required for a software to be installed. So the admin becomes the owner of the installation directory created during the installation. The software will be used by non-admin users, who only have read and execute access of the installation directory by default. But the software is designed in such a way that it can write to the installation directory. There is a startup.ini configuration file resides in the installation directory which the non-admins should be able to modify to alter the behavior of the software.
If the software is run from non-admin account, it can't write to the installation directory. Also non-admins can't change the startup.ini file.
As a workaround, currently the admin installs it changes the permission of the installation directory so that non-admins can write and modify it.
I want it to be automatically done after installation. Somehow the installer should take care of the permission. How can I do that? Note that I can't change the software behavior so it no longer writes into the installation directory. The non-admins must be given necessary privilege so that they can have modify and write permission.
I'm using Windows XP SP3 for the development. All OSes involved (XP and 7) are 32 bit.
Thanks in advance.
you should change the application so that it stores its INI file at a location which normal users can write - see http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/77aaf6e1-8de5-4529-9b26-fa89b55fcc49
EDIT:
IF that is absolutley not possible then:
create a "custom action" in the setup project and change the permissions... a good starting point is
http://www.redmondpie.com/applying-permissions-on-any-windows-folder-using-c/
and
http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.filesystemsecurity.addaccessrule.aspx
For the record, your program is broken on Windows XP as well. XP also requires admin rights to install this way or write to Program Files folders. The difference is that so many people have admin by default in XP.
If you can't modify the program, you will have to write a custom installer action to grant write access to the ini file in question. There is no need to grant this access to the entire folder.

Creating a updater

VS 2008 SP1
I have created a application that I have installed on the user computer. However, I want the application to be self-updating. But I am not sure if this would really update the application.
The application will download all the files from the web server, and replace the files in the directory where the program as been installed to. The user will restart the application.
I am just want to be sure, because I can't replace the installed files with the updated ones. As the application will be running. So really the application cannot delete/replace itself.
So, I was thinking that I could download into another directory, if the program is installed in this directory 'program files/application/1.0.0' then I could download the files to 'program files/application/1.0.1'.
However, when the program restarts, how can it know that it has to execute from the 1.0.1 directory?
I can't use clickonce or the updater block for this.
Many thanks for any advice,
A good option is to make an independant Updater application.
The updater will download the newest version and kill/replace the old.
I think this is the best option, because you can execute the updater within the main appication (so you can say that it´s self-updating), or directly by the user with a shortcut.
The updater can check if the application is running and ask the user to exit the application or kill it by itself.
Forgive my english...
Good luck
All of that is already done for you if you use ClickOnce deployment (Project properties, Publish).
You can wrap the application with a small loader program which will do a version check. If it's out of date, download the newer binaries and overwrite the old ones. If you want to maintain all version you might end up with:
c:\program files\mycompany\myapp\loader (the newer version will point to the latest directory)
c:\program files\mycompany\myapp\v1.0
c:\program files\mycompany\myapp\v1.1
If it's on a LAN, you might be able afford the bandwidth of just re-downloading the binaries on start up instead.
Use Windows Installer for the installation and updating. If you sign your installation packages the user can update your application without needing any administrator privileges.
I've made a website and an application that demonstrates the functionality of what you want on my website.
Wix Clickthrough might meet your needs: http://wix.sourceforge.net/clickthrough.html
I would look into ClickOnce. It can be configured multiple ways, to check for updates before the application runs, to download from the server each time it's run, or check for updates after the application has started.
I have done ClickOnce Deployment and an independent updating application, they both work well. You obviously will have more flexibility over an updating application that you create yourself, however tho, ClickOnce can also be configured to install prerequisites such as the .NET Framework, Windows Installer, etc... for your application to run.

Categories