By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,084 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,084 IT Pros & Developers. It's quick & easy.

How to uninstall a program?

P: n/a
I am needing to automate some installation tasks. I first need to determine
if there is already a version of a program installed. The program appears
in the Add/Remove Programs in control panel, and I know this is all stored
in the registry. But short of searching through the entire registry, I
cannot figure out how to locate the program.

I see that in the registry (for .msi) installs, stores something like:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Uninstall\{9783
3EC6-ACD7-4FD2-BFAF-B57438B55C1E}

In that key contains the Uninstall string I need. However, I do not really
want to have to search the entire registry for the product. What is that
long identifier in the name? How is it determined, etc? Or is it the same
on every machine and I can hardcode it in?

--
Adam Clauss
ca*****@tamu.edu
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Adam,

Please see replies to the "Uninstall application" thread in this newsgroup.
This should answer your question.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
I am needing to automate some installation tasks. I first need to determine if there is already a version of a program installed. The program appears
in the Add/Remove Programs in control panel, and I know this is all stored
in the registry. But short of searching through the entire registry, I
cannot figure out how to locate the program.

I see that in the registry (for .msi) installs, stores something like:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Uninstall\{9783 3EC6-ACD7-4FD2-BFAF-B57438B55C1E}

In that key contains the Uninstall string I need. However, I do not really want to have to search the entire registry for the product. What is that
long identifier in the name? How is it determined, etc? Or is it the same
on every machine and I can hardcode it in?

--
Adam Clauss
ca*****@tamu.edu


Nov 16 '05 #2

P: n/a
Unfortunately, that really isn't what I need.

I am not uninstalling a version of MY program, but another program. And I
am not writing an actual installer per-se, but one thing my program needs to
do to perform some tests is to remove any existing version of this other
program - so I use the suggestions mentioned in the other thread.

--
Adam Clauss
ca*****@tamu.edu
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi Adam,

Please see replies to the "Uninstall application" thread in this newsgroup. This should answer your question.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
I am needing to automate some installation tasks. I first need to

determine
if there is already a version of a program installed. The program appears in the Add/Remove Programs in control panel, and I know this is all stored in the registry. But short of searching through the entire registry, I
cannot figure out how to locate the program.

I see that in the registry (for .msi) installs, stores something like:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Uninstall\{9783
3EC6-ACD7-4FD2-BFAF-B57438B55C1E}

In that key contains the Uninstall string I need. However, I do not

really
want to have to search the entire registry for the product. What is that long identifier in the name? How is it determined, etc? Or is it the same on every machine and I can hardcode it in?

--
Adam Clauss
ca*****@tamu.edu

Nov 16 '05 #3

P: n/a
Well, in this case you should really scan the registry. I remember an
uninstall command is specified for each program listed in the registry so
you can use these.
Not sure though this is the case for MSI-based installs, but these use a
uniform uninstall method so you only need a product code.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Unfortunately, that really isn't what I need.

I am not uninstalling a version of MY program, but another program. And I
am not writing an actual installer per-se, but one thing my program needs to do to perform some tests is to remove any existing version of this other
program - so I use the suggestions mentioned in the other thread.

--
Adam Clauss
ca*****@tamu.edu
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi Adam,

Please see replies to the "Uninstall application" thread in this

newsgroup.
This should answer your question.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
I am needing to automate some installation tasks. I first need to

determine
if there is already a version of a program installed. The program appears in the Add/Remove Programs in control panel, and I know this is all stored in the registry. But short of searching through the entire registry, I cannot figure out how to locate the program.

I see that in the registry (for .msi) installs, stores something like:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Uninstall\{9783
3EC6-ACD7-4FD2-BFAF-B57438B55C1E}

In that key contains the Uninstall string I need. However, I do not

really
want to have to search the entire registry for the product. What is that long identifier in the name? How is it determined, etc? Or is it the same on every machine and I can hardcode it in?

--
Adam Clauss
ca*****@tamu.edu



Nov 16 '05 #4

P: n/a
> uniform uninstall method so you only need a product code.
Thats exactly my question :) Was wondering if there was a way to locate
this product code without scanning through the registry. A "fast" lookup
of sorts...
I've got it implemented right now as scanning, I just can't help but
thinking that it is inefficient. I figured somewhere it was stored by the
app name or something upon installation.

--
Adam Clauss
ca*****@tamu.edu
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:Ok**************@TK2MSFTNGP11.phx.gbl...
Well, in this case you should really scan the registry. I remember an
uninstall command is specified for each program listed in the registry so
you can use these.
Not sure though this is the case for MSI-based installs, but these use a
uniform uninstall method so you only need a product code.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Unfortunately, that really isn't what I need.

I am not uninstalling a version of MY program, but another program. And I
am not writing an actual installer per-se, but one thing my program needs
to
do to perform some tests is to remove any existing version of this other
program - so I use the suggestions mentioned in the other thread.

--
Adam Clauss
ca*****@tamu.edu
"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com>
wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl...
Hi Adam,

Please see replies to the "Uninstall application" thread in this

newsgroup.
This should answer your question.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
> I am needing to automate some installation tasks. I first need to
determine
> if there is already a version of a program installed. The program

appears
> in the Add/Remove Programs in control panel, and I know this is all

stored
> in the registry. But short of searching through the entire registry, I > cannot figure out how to locate the program.
>
> I see that in the registry (for .msi) installs, stores something
like: >

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Uninstall\{9783
> 3EC6-ACD7-4FD2-BFAF-B57438B55C1E}
>
> In that key contains the Uninstall string I need. However, I do not
really
> want to have to search the entire registry for the product. What is

that
> long identifier in the name? How is it determined, etc? Or is it
the same
> on every machine and I can hardcode it in?
>
> --
> Adam Clauss
> ca*****@tamu.edu
>
>


Nov 16 '05 #5

P: n/a
Hi Adam,

"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:uV**************@TK2MSFTNGP12.phx.gbl...
I am needing to automate some installation tasks. I first need to determine if there is already a version of a program installed.

<snip>

There are a lot of ways you can accomplish this, including using the
Microsoft Windows Installer Object Library (COM) or WMI. Since there are
already classes in .NET for WMI, I'll use that as an example. The
Win32_Product WMI class represents products installed on the machine. The
Win32_Product class has the product name, code, description, installed
location, etc., as well as methods to install, uninstall, advertise, etc the
product.

The first step is to determine the WMI "path" to the product you want to
uninstall. This routine will print out all the properties and the WMI path
for all installed products:

// need a "using System.Management;" somewhere
...
static void ListAllProducts()
{
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");
ManagementObjectSearcher allProducts =
new ManagementObjectSearcher(allProductsQuery);

foreach(ManagementObject product in allProducts.Get())
{
foreach(PropertyData property in product.Properties)
{
Console.WriteLine("{0} = {1}", property.Name,
property.Value);
}
Console.WriteLine("Path = {0}", product.Path);
Console.WriteLine();
}
}

Once you have the path for the product you wish to uninstall, you can
uninstall with a method that might look like this:

static void UninstallProduct(string path)
{
ManagementObject product = new ManagementObject(path);

if ((product != null) && (product.Path.ClassName ==
"Win32_Product"))
{
object result = product.InvokeMethod("Uninstall", null);
Console.WriteLine("The Uninstall method result is {0}",
result.ToString());
}

}

A call to the UninstallProduct method above might look like this:

UninstallProduct(
"Win32_Product" +
".IdentifyingNumber=\"{F934F310-BFEB-40CA-801B-CC7136CEE35F}\""
+
",Name=\"ObjectSpaces Mapper Utility\"" +
",Version=\"1.0.0\"");

I split the path over several lines for readability. FYI, the
IdentifyingNumber property is the "Product Code". Also, the part of the path
that precedes the class name (something like "\\MachineName\root\cimv2:") is
unnecessary for anything on the local machine, so I omitted it.

Hope that helps.

Regards,
Daniel

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.