دوستان این مشکل را هم حل کردم دنو تا تابع می زارم اولیش میبینه که application مورد نظر شما install شده یا نه و دومیش اونو uninstall می کنه
// this function return true if "Company Wizard" was installed in user's computer or false if it wasn't;
public static bool GetInstalledApps(string ProgramName)
{
// create a list to add all of installed application
List<string> appList = new List<string>();
// set the registry key that has been set for this application on uninstallKey string
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninst all";
// create a registry key to open uninstallKey and set it to rk
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
// give name of all of elemnet in rk and set it to skName
foreach (string skName in rk.GetSubKeyNames())
{
// create a registry key to open skName and set it to sk
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
// add application name to list
appList.Add((sk.GetValue("DisplayName")).ToString( ));
}
catch (Exception ex)
{ }
}
}
}
// if aour purpose appliaction was in list
if (appList.Contains(ProgramName))
{
return true;
}
// if it wasn't
else
{
return false;
}
}
// this function unindtall "Company Wizard" form user computer and act when user during installation "welcome... " cancel installation
private bool UninstallProgram(string ProgramName)
{
try
{
// find all of installed application
ManagementObjectSearcher mos = new ManagementObjectSearcher(
"SELECT * FROM Win32_Product WHERE Name = '" + ProgramName + "'");
// for all of them if it's name was equal to our application name Uninstall it
foreach (ManagementObject mo in mos.Get())
{
try
{
if (mo["Name"].ToString() == ProgramName)
{
object hr = mo.InvokeMethod("Uninstall", null);
return (bool)hr;
}
}
catch (Exception ex)
{
//this program may not have a name property, so an exception will be thrown
}
}
//was not found...
return false;
}
catch (Exception ex)
{
return false;
}
}
اگه بدردتون خورد تشکر شما باعث دلگرمی منه