Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralRe: Intersting question.... Pin
Mark Churchill22-Nov-07 1:05
Mark Churchill22-Nov-07 1:05 
Questiongridview row select [modified] Pin
Sunil Wise21-Nov-07 21:27
professionalSunil Wise21-Nov-07 21:27 
QuestionRe: gridview row select Pin
Sunil Wise22-Nov-07 3:11
professionalSunil Wise22-Nov-07 3:11 
QuestionC#.NET Push URL from textbox on a button click Pin
D i x y21-Nov-07 21:09
D i x y21-Nov-07 21:09 
AnswerRe: C#.NET Push URL from textbox on a button click Pin
Jonathan [Darka]21-Nov-07 22:12
professionalJonathan [Darka]21-Nov-07 22:12 
QuestionC#.NET Push URL from textbox on a button click Pin
D i x y21-Nov-07 21:08
D i x y21-Nov-07 21:08 
QuestionC#.NET Push URL from text box on button click Pin
D i x y21-Nov-07 21:06
D i x y21-Nov-07 21:06 
QuestionAdd/Remove program through code Pin
dan!sh 21-Nov-07 20:56
professional dan!sh 21-Nov-07 20:56 
Hi
I have written a code to uninstall any application. How can this be made better? I mean if a large amount of code can be replaced by smaller one or any other way to uninstall application. Apart from that I have some more questions which I have put in the code itself as comments. Please help on them as well.


Process oProcess = new Process();
oProcess.StartInfo.FileName = "cmd.exe";
oProcess.StartInfo.CreateNoWindow = true;
oProcess.StartInfo.UseShellExecute = false;
RegistryKey oRegKey  = null;// variable to get the registry key of the selected application
string sUninstallString = "";

// following code gets the registry key of the selected application
string[] asSubKeys = Registry.LocalMachine.OpenSubKey(
 @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\").GetSubKeyNames();
foreach (string sSubKey in asSubKeys) {
  oRegKey = Registry.LocalMachine.OpenSubKey(
   @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + sSubKey);

  if (oRegKey.GetValue("Displayname") != null && 
   oRegKey.GetValue("Displayname").ToString() == this.treePrograms.SelectedNode.Text) {
    sUninstallString = oRegKey.GetValue("Uninstallstring").ToString();
    break;
  }
}

// check if the uninstall.exe exists for the selected application
if (sUninstallString.LastIndexOf("exe") != (sUninstallString.Length - 3)) {
  // uninstall.exe does not exists for the selected application
  // so i get uninstall string as:
  // MsiExec.exe /I{920EB460-99D1-4CFB-A383-20DD293AA86D}
  // (for some application on my machine)
  // I am not sure why I am getting "/I" instead of "/X"
  // Manually edit the string to make it work
  sUninstallString = sUninstallString.Remove(0, 14);
  // uninstall the application
  oProcess.StartInfo.Arguments = "/k msiexec.exe /x" + sUninstallString;
}
else {
  // uninstall.exe exists for the selected application
  // so i get uninstall string as:
  // C:\Program Files\WinRAR\uninstall.exe (for winrar)
  // edit it to make it work in cmd.exe
  sUninstallString = sUninstallString.Replace("C:\\", "");
  string sExe = sUninstallString.Substring(sUninstallString.LastIndexOf('\\') + 1);
  sUninstallString = sUninstallString.Remove(sUninstallString.LastIndexOf('\\'));
  oProcess.StartInfo.Arguments = ("/k cd\\ & cd " + sUninstallString + " & " + sExe);
}
oProcess.StartInfo.RedirectStandardError = true;
oProcess.Start();
// how much miliseconds should be kept here so that code works fine for any application? 
oProcess.WaitForExit(); 
// Check for successfull uninstallation ????
// I guess StandardError may help. But how?
oProcess.Close();
oProcess.Dispose();



Also it would be nice if someone can suggest an approach for Add Programs. For me, the major issue would be how to find setups of applications in the system.

Chaos, panic and disorder - my work here is done.

NewsA Working Export from DB to CSV Pin
MumbleB21-Nov-07 20:34
MumbleB21-Nov-07 20:34 
QuestionSQL Image Data Type Pin
tr_thorn21-Nov-07 20:34
tr_thorn21-Nov-07 20:34 
AnswerRe: SQL Image Data Type Pin
Colin Angus Mackay21-Nov-07 21:30
Colin Angus Mackay21-Nov-07 21:30 
GeneralRe: SQL Image Data Type Pin
tr_thorn21-Nov-07 21:46
tr_thorn21-Nov-07 21:46 
AnswerRe: SQL Image Data Type Pin
Pankaj - Joshi21-Nov-07 22:00
Pankaj - Joshi21-Nov-07 22:00 
AnswerRe: SQL Image Data Type Pin
tr_thorn21-Nov-07 22:44
tr_thorn21-Nov-07 22:44 
GeneralRe: SQL Image Data Type Pin
Pankaj - Joshi21-Nov-07 23:11
Pankaj - Joshi21-Nov-07 23:11 
GeneralRe: SQL Image Data Type Pin
tr_thorn22-Nov-07 0:48
tr_thorn22-Nov-07 0:48 
GeneralRe: SQL Image Data Type Pin
Pankaj - Joshi22-Nov-07 16:10
Pankaj - Joshi22-Nov-07 16:10 
QuestionHow to add Combobox's item Pin
jason_mf21-Nov-07 20:25
jason_mf21-Nov-07 20:25 
AnswerRe: How to add Combobox's item Pin
Sun Rays21-Nov-07 21:00
Sun Rays21-Nov-07 21:00 
GeneralRe: How to add Combobox's item Pin
jason_mf21-Nov-07 21:29
jason_mf21-Nov-07 21:29 
QuestionBulk Export Task Pin
RAGHAVENDRAN200721-Nov-07 20:20
RAGHAVENDRAN200721-Nov-07 20:20 
QuestionVertical scrollbar in listview Pin
anu8121-Nov-07 19:50
anu8121-Nov-07 19:50 
QuestionEmail News Letters through C#,ASP.Net1.1 Pin
clife53721-Nov-07 19:25
clife53721-Nov-07 19:25 
AnswerRe: Email News Letters through C#,ASP.Net1.1 Pin
Christian Graus21-Nov-07 19:26
protectorChristian Graus21-Nov-07 19:26 
Questionbcc and cc in sending emails form C# Pin
new2pgrmg21-Nov-07 18:47
new2pgrmg21-Nov-07 18:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.