How to get installed applications install folder(path) and uninstaller - c#

Hello I need some way of finding all the insllaled applications on windows(I already found the names but i need the actual folder). Also I need the path to their uninstaller.
I'm trying to build an application that is similar with Advanced Uninstaller pro.
PS. I need to do this in C#.

I think you wont need the path to the installer, you have to get the UninstallString value for each installed application so you can excute it once wanted to be removed. All of them are available here : HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall (my case is 64bit system)
You can enumerate all apps from here by getting DisplayName value. Hope it helps

Related

Deploying C# Console App - How do I update ENV PATH via the "Publish Now" settings?

Here's the thing. I have built a console app in .NET (C#). It works good and all is well. It's an internal tool for folks on our network, but could be used anywhere in the world (larger company). I thought I'd be able to use the simple install /deploy Wizard that comes with MS VisualStudio 2013 to generate a nice little installer. I got it set up and it works nice.
HOWEVER, once the app is installed on a target machine I want it to be usable from anywhere on the command line. Either I need to update PATH variables or have the app installed in a PATH location. The latter seems dangerous to do (putting something in SYSTEM and such), so I am wondering:
How can I get the simple Microsoft deploy wizard to update the appropriate path on the target machine while the app is being installed? I don't want to have to write some installer. I was hoping there would be some basic deployment options that let me do some custom things like this without hassle...
what am I missing? help? thanks...
Just to follow up, to answer my question--- I had to create a custom install step that would update the PATH environment variable to make the computer see my new console app from any CMD window. This meant doing 2 steps:
Reading the current Path (without expanding the variables in each string) as follows:
string RegKeyName = #"SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
string pathvariable = (string)Microsoft.Win32.Registry.LocalMachine.OpenSubKey(RegKeyName).GetValue
("Path", "", Microsoft.Win32.RegistryValueOptions.DoNotExpandEnvironmentNames);
I then split the pathvariable by semicolons and loaded it into an allpaths array variable (ignoring empty entries). Then, I iterated through allpaths in a foreach loop and rebuilt the master path, plus set a boolean to tell me if the directory I wanted to add was already in the path . Then, once I was done that, I did the following:
if (NeedtoUpdate)
{
Environment.SetEnvironmentVariable("Path", MasterPath + MyNewPathEntry + ";", EnvironmentVariableTarget.Machine);
}
That was how the custom install step worked for me.

Trying to launch a Visual Studio C# program from inside another one

I am having great difficulty getting a Windows program, written in VS 2008 C#, to launch another type program. I've put a main program to offer you the ability to launch some other VS 2008 C# programs. When one of them is selected the following code is intended to do the launch:
System.Diagnostics.Process.Start(#"C:\Documents and Settings\rat\My Documents\Visual Studio 2008\Projects\PV_002_082708\PV_001\PV_001\bin\Debug\PV.exe");
It works, but each user will have a different path. The path shown is for my computer. The code would have to know where each persons program was installed! In the past, I could easily call a program that was in the C:\Program Files location because that's where the MS Package & Deployment program put the programs. VS 2008/2010 doesn't put them there!
I'm sure I am not knowledgeable about Visual Studio 2008/2010 to know if there is a way around this, so any help would be greatly appreciated.
System.Diagnostics.Process.Start(System.Io.Path.Combine(System.Windows.Forms.Application.StartupPath, "PV.exe"));
assuming that the program is in the launched application's path.
or...
System.Diagnostics.Process.Start(System.Io.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), #"Visual Studio 2008\Projects\PV_002_082708\PV_001\PV_001\bin\Debug\PV.exe"));
assuming you want to open the project from it's place.
Once you create the installation package you can set the install path to some fixed path that users will not be able to change and than use that from your code (not very user friendly but it would work) or insert the user chosen path value into the registry and get it from there instead.
May want to have a look at this thread. How-to as well as lots of pro's and cons.
Embedded a *.exe into a dll
If you see the first answer to his question, I think this would work for you.
Simply he is saying, you add a resource file to your project, then when the user runes your program, it extracts your exe file that you added as a resource file to somewhere you know on the end users maching.

How to find a Windows Forms Application's Product Code?

I need my application to uninstall itself.
Reason: It's come to my attention that my app is destroying its own files (my bad), but the user of my app doesn't understand why he needs to uninstall it and refuses to uninstall it. However, he still complains about the constant problems. And in the Terms Of Use, there is a line that says "...we reserve the right to remove the application from your computer and temporarily or permanently discontinue your use of the software."
So, I did some searching on how to uninstall a program, (which will be replaced by a new version), and came across Uninstall C# windows application from self and the accepted answer says you need a 'product code'. What exactly is that, and where can I find/get it from? I have searched for this but can't find anything.
Thank you
The productcode can be obtained from your MSI by opening with orca, the msi db editor and lookup the productcode in the Property table. Orca is part of the Windows SDK.
You can also run your msi
msi /i [your msi] -lvx* log.log
and harvest the productcode from the log.
The easiest way is by getting it from the author files of your setup as Ken White already pointed out.
You created the product code (if it exists) when you created your MSI to install your application. You need the same product code you used in the installation in order to uninstall it via Windows Installer.
I am not sure about VS 2010, but in VS2008 setup projects have a ".vdproj" project file, which can be opened with a simple text editor (like notepad). If you search for the word "ProductCode", you will find a line like
"ProductCode" = "8:{GUID}"
(the GUID is what you are looking for).

How to install to the Public directory in Windows 7 from the VS 2010 deployment Setup Project

I have some documents I want to install (using the Setup project) onto a Windows 7 system which is accessible by everyone. These documents should not be hidden. They should be visible for all users to double click on. I believe the best place for this is C:\Users\Public or C:\Users\Public\Documents.
Since there isn't a special folder for either of these folders in the Setup project, the only way I have found so far is to create a custom folder and set the DefaultLocation to [%public][Manufacturer][ProductName] etc.
(see http://community.flexerasoftware.com/archive/index.php?t-164246.html)
However, this seems very brittle; what if someone deletes the environment variable for public? Also, would this work on a different language version of Windows 7? Is there a better way to define the DefaultLocation to the Public folder for a Windows 7 install?
The public folder isn't stored in a standard environment variable (System -> Advanced -> Environment Variables) so I think it is very unlikely too many people are doing this, but I understand the need to create a robust installer.
This page has instructions on changing the location of the public folder. The accepted solution is quite involved and requires command line work. The suggestion by Luviana is much simpler. I would test them out and see if they break the %public% shortcut. My guess is that they will not. My best advice is to check it out for yourself and if it still works then you can count on the fact that %public% will be available.

Access error in Windows 7

I am working on a windows appliciation in which i create a folder at runtime and save some xml files in the folder....
Every thing works fine in Windows XP but when i run this in Widows 7 / Vista i get the error saying Access to the path is denied..
i am creating the folder in C:\Programfiles\MyApplication\
Please help me in resolving this
Windows 7 (and Vista) set access permissions on the Program Files directories and will not allow a normal user to write to those directories.
Either your program has to be run by an administrator, or you can change the permissions on your app's Program Files entry, or save the data somewhere else.
It might be an idea to use the special folders .NET provides for this type of data. This should work:
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + #"\AppName\test folder");
Then write your data to this folder.
Is your application running in the context of administrator?
Is visual studio running as administrator?
To do this right click VS and select run as administrator, to do it permanently, right click, propertys and select the run as admin check box.
When your debugging your app through VS, it will need the permissions, else the application its self will.
Its probably just a permissions based thing...
You can enable XP mode for an executable.
Please find the settings below
link text
Long time Windows XP developers should consider reading UAC,
http://en.wikipedia.org/wiki/User_Account_Control
It was first added in Windows Vista, and now becomes a central part of Windows family.
You SHOULDN'T write to Program Files. It's a bad habit and only installers should write there. What you "want" is bad for the whole ecosystem and just plain wrong. Don't do it.

Categories