|
Thank you my friend I was searching this solution from quote a while
|
|
|
|
|
Hello,
Thanks for the post.
I have added uninstall shortcut of my application as per this process. Setup is created successfully but when I run the setup of my application, in some machines application installed successfully and uninstall shortcut is also working but in some machines it’s failed in installation with below error.
"The Windows Installer service cannot update the system file C:\Windows\System32\msiexec.exe because the file is protected by Windows. You may need to update your operating system for this program to work correctly."
It seems the error is causing when installer tries to copy msiexec.exe in system32 folder but I have set the "NOT Installed" condition and other required properties. Then what can be the reson for this error?
Thanks in advance.
|
|
|
|
|
Msiexec.exe should not be listed in the setup project's properties. Double check your uninstall shortcut, it should point to your application's exe not msiexec. If it points to msiexec, then you haven't followed the instructions correctly.
|
|
|
|
|
If I go to the actual link I just made, is there any way to physically tell that this is an "uninstaller"?
In other words, I right-clicked the link and went to Properties and I was not able to see anything like "/u=" appended to the command line.
It appears to just launch the application again.
Did I do something wrong?
Update:
I have tried all of the techniques described below, but the Attributes field does not populate when the product is installed. It is blank.
Does everyone else's Setup Project (Visual Studio 2008 Professional w/SP1) replace "[ProductCode]" (without the quotes) with something like "{4FAE13C5-273B-40B4-BEC0-C3EAE5729304}?
Mine does not, and if someone could tell me where to look to fix this, I would greatly appreciate it.
|
|
|
|
|
[STAThread]
static void Main(string[] args)
{
foreach (string arg in args)
{
if (arg.Split('=')[0] == "/u")
{
Process.Start(new ProcessStartInfo(Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\msiexec.exe", "/x " + arg.Split('=')[1]));
return;
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new myForm());
}
Keep in mind you will need a reference to System.Diagnostics in your using section.
|
|
|
|
|
It works great thanks for the update.
Regards,
Satheesh.P,
Software Engineer,
TriozTech.
|
|
|
|
|
Thanks a lot
i converted it to C#
[STAThread]
static void Main()
{
string[] args = Environment.GetCommandLineArgs();
bool isRunnable = true;
foreach (string argument in args)
{
if (argument.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0].ToLower() == "/u")
{
string guid = argument.Split("=".ToCharArray(),StringSplitOptions.RemoveEmptyEntries)[1];
string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
ProcessStartInfo si=new ProcessStartInfo(path+"\\msiexec.exe","/x "+guid);
Process.Start(si);
Application.Exit();
isRunnable = false;
}
}
if (isRunnable)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new myForm());
}
}
=============
NITIN SAWANT
=============
http://nitin646.wordpress.com
|
|
|
|
|
Hello, where should I put below codes?
I have 2 projects now (Application and Setup).
But I don't know where should I put these codes.
I thought that I can't put these codes in startup form (in my application project) cause it will be executed later when I open application each time.
Dim arguments As String() = Environment.GetCommandLineArgs()
Dim argument As String
For Each argument In arguments
If argument.Split("=")(0).ToLower = "/u" Then
Dim guid As String = argument.Split("=")(1)
Dim path As String = _
Environment.GetFolderPath(Environment.SpecialFolder.System)
Dim si As New ProcessStartInfo(path & _
"\msiexec.exe", "/i " & guid)
Process.Start(si)
Close()
Application.Exit()
End
End If
Next
|
|
|
|
|
Step 4 refers to locations in your application program.
|
|
|
|
|
Hi,
This worked quite fine with me.Thanks.
One doubt is after pressing Uninstall from User's Programm menu,it will ask for confirmation for uninstalltion like "You want to uninstall this product?". I want show product name instead of 'this' in the message. How I can do this?
Thanks
|
|
|
|
|
I don't think it is possible to override this because it is built in to msiexec.
|
|
|
|
|
I solved it by using /qb switch for msiexec and adding custom MessageBox question:
string[] ss = arg.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (ss[0].ToLower() == "/u" && ss.Length == 2)
{
if (MessageBox.Show("Whatever question you want?", "Whatever caption you want", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
string guid = ss[1];
string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
ProcessStartInfo si = new ProcessStartInfo(path + "\\msiexec.exe", "/x " + guid + " /qb");
Process.Start(si);
}
Application.Exit();
return;
}
|
|
|
|
|
Excellent article, worked exactly the way I needed it. Kudos!!!
|
|
|
|
|
Hi,
If I remove original setup.exe and msi files; this uninstaller.exe will not work as "productCode" refers to that location. But still I am able to remove program from add/remove program.
I did some R&D and I found that add/remove program uses key located at "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" path.
The GUID is used over there is different then in "product code" of deployment project properties.
Is there any way to use same GUID(which is used by add/remove programs) for uninstaller.exe?
It is useful when you install program from CD and then later want to uninstall it.
Thanks
Sorry, my mistake!
Both GUID are same, but when I try to remove through uninstaller application(code provided by you), it always ask for msi file. but in case of add/remove programs, it does not ask. I tried with "/X" option but still result it same.
modified on Thursday, November 27, 2008 7:11 AM
|
|
|
|
|
When add/remove programs performs an uninstall of an msi based installer, it does exactly the same as the msiexec shell in the above code. That's what this code duplicates. It's not designed to work with setup.exe or other executable based installs. It might or might not work depending on how the setup.exe program sets the product code. I completely expect that with complicated setups which require a setup.exe isntall or which have multiple msi's supporting conditional installation of optional features that this project is far too simple for that kind of installation. I have used it ONLY with simple single msi-based installs which do not require a setup.exe or prerequisites.
Basically this sample code will work only if "msiexec /i {guid}" would work from the command line. If you have a complex installation and you can somehow find the proper guid that will work from the command line call to msiexec, then this code should work.
|
|
|
|
|
|
I've found even easier solution for uninstall menu item:
1. Create new shortcut in you system (NOT in VS Project, just in Windows).
2. In the location field type "msiexec".
3. Name the shortcut, for example, "Uninstall".
4. Now open its properties. Windows automatically used relative path to target: "%windir%\system32\msiexec.exe".
5. Add to the target "/x {ProductCode}". Here, you must specify the REAL ProductCode of you application (see it in your Deployment Project Properties -> ProductCode). The final target should look, for example, like this: "%windir%\system32\msiexec.exe /x {1CAD0188-B15F-4C31-8146-A267FDA507CB}".
6. Now you need to add this file to your Deployment Project. But here was the problem - u can't add shortcuts as files to your project. To bypass this restriction, you need just to rename your shortcut to have different extension. You can't do this in Windows Explorer, so use any file manager (Far, Total Commander, NDN, etc). Find and rename the shortcut we've created earlier from "Uninstall.lnk" to, for example, "Uninstall.lnk.foo".
7. Add this renamed shortcut to your Deployment Project (Add -> File...).
8. Open Properties of the added file and set TargetName back to initial name . (e.g. "Uninstall.lnk").
9. Move this file inside the Deployment Project to the folder your shortcuts would deploy.
That's all, now you will have the shortcut to uninstall your program without any additional files in your project (e.g. .bat files, etc)!
This could sound a bit complicated - but I've given so many steps only to explain the process very detailed. Actually, there is not so much to do. The only disadvantage of this method is, that you need to change ProductCode in the uninstall shortcut manually every time you change it in your deployment project.
This solution worked just well for me (i tested it on WinXP, but other versions could work as well, just maybe with some differences in the system pathes), so I think it could suit others as well .
|
|
|
|
|
You can't do this in Windows Explorer, so use any file manager (Far, Total Commander, NDN, etc). Find and rename the shortcut we've created earlier from "Uninstall.lnk" to, for example, "Uninstall.lnk.foo".
or
u can simply do this in command promt. juss naviage to that folder and use command:
ren uninstall.lnk uninstall.foo
and follow the remaining step
Thanx for this easier solution, it worked for me.
http://www.bilal.net.tc
|
|
|
|
|
You don't need to write code to parse the parameters and call msiexec...
1) n the Setup Project, View File System, and add a Special Folder - System Folder.
2) Into this folder Add a file. Browse for msiexec.exe from your local System32 folder and add it to the installation project. Override default properties of this file as follows... Condition:=Not Installed (make sure you put 'Not Installed' exactly like that, same case and everything), Permanent:=True, System:=True, Transitive:=True, Vital:=False.
3) Create a new Folder under the 'Users Program Menu' where you want the uninstall option to go.
4) Create a new shortcut in this new folder, and point it's at the msiexec.exe file in the System Folder as the target. Rename the shortcut to 'Uninstall MyApplication'.
Set the Arguments property to /x{space}[ProductCode].
5) Build the project, ignore warning about the fact that msiexec should be excluded, DONT exclude it or the setup project wont build.
The 'Not Installed' condition and Permananet:=True ensure that the msiexec.exe is only placed into the system folder as part of the install IF it doesn't aready exist, and it is not removed on an uninstall - therefore it;s pretty safe to ignore that warning and just go for it.
--------
SlapHead
|
|
|
|
|
The license for msiexec does not allow its distribution in this way. i.e. packaged in another installer. Msiexec should only be distributed as part of the Windows Installer 3.1 distribution. Whereas the method you have come up with should work, it is not legal. There is also the possibility that the user has a different version of msiexec already installed in their machine, and this might cause a version conflict.
|
|
|
|
|
You don't need to actually include msiexec, which is not legal as was pointed out.
You can just create a 0 byte file called msiexec.exe, include that, and then put it in the System Folder in the file system window.
This is the best and easiest way to create an Uninstall shortcut IMO.
|
|
|
|
|
Hi, i have problem with the solution given. i am a newbie in dot net. i have paste the coding given into my startup form (which is SplashScreen1.vb)
in SplashScreen1.Designer.vb, i add this code:
Sub New() 'i wrote this sub
Dim arguments As String() = Environment.GetCommandLineArgs()
Dim argument As String
For Each argument In arguments
If argument.Split("=")(0).ToLower = "/u" Then
Dim guid As String = argument.Split("=")(1)
Dim path As String = _
Environment.GetFolderPath(Environment.SpecialFolder.System)
Dim si As New ProcessStartInfo(path & _
" C:\Program Files\BSE 2008\Database\msiexec.exe", "/i " & guid)
Process.Start(si)
Close()
Application.Exit()
End
End If
Next
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<system.diagnostics.debuggerstepthrough()> _
Private Sub InitializeComponent()
......
End Sub
when i run the project, choose uninstall it gave me this error "(null) is not a valid win32 application"
what should i do? y is this happen?
tyia.
|
|
|
|
|
It appears that your code is trying to refer to a copy of msiexec which is in the program files folder. It should never be there. Msiexec is not licensed for separate distribution. But more importabtly you are concatenating path to the msiexec string. This is wrong. The code should be:
Dim si As New ProcessStartInfo(path & _
"\msiexec.exe", "/i " & guid)
This will concatenate the system path to the beginning of the msiexec path. Sinc you say you are a beginner you probably didn't realize that below is the same code:
Dim si As New ProcessStartInfo( _
path & "\msiexec.exe", "/i " & guid)
|
|
|
|
|
hi mjmeans,
i still cant running the uninstall part. i have changed the code as u mention before and it still produce me with the same result.
|
|
|
|
|
All I can think of is that maybe msiexec.exe is corrupt on your system, or you have some other msiexec.exe file that is not the real microsoft provided file somewhere in your system. Try downloading and installing an updated Windows Installer from Microsoft. When that is done, go to s command prompt and type "msiexec" and press enter. You should see a pop-up window with help parameters for msiexec. If you dont see this message, then your Windows system has problems that are preventing the code from working.
|
|
|
|