Click here to Skip to main content
15,902,189 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to turn a Windows Form application into a library Pin
biop.codeproject10-Nov-11 15:30
biop.codeproject10-Nov-11 15:30 
AnswerRe: How to turn a Windows Form application into a library Pin
Luc Pattyn10-Nov-11 16:08
sitebuilderLuc Pattyn10-Nov-11 16:08 
GeneralRe: How to turn a Windows Form application into a library Pin
biop.codeproject10-Nov-11 17:52
biop.codeproject10-Nov-11 17:52 
AnswerRe: How to turn a Windows Form application into a library Pin
Luc Pattyn10-Nov-11 18:26
sitebuilderLuc Pattyn10-Nov-11 18:26 
GeneralRe: How to turn a Windows Form application into a library Pin
BillWoodruff10-Nov-11 19:27
professionalBillWoodruff10-Nov-11 19:27 
AnswerRe: How to turn a Windows Form application into a library Pin
Ennis Ray Lynch, Jr.10-Nov-11 8:40
Ennis Ray Lynch, Jr.10-Nov-11 8:40 
GeneralRe: How to turn a Windows Form application into a library Pin
BobJanova10-Nov-11 23:23
BobJanova10-Nov-11 23:23 
QuestionUninstall a none Microsoft program on a remote machine via WMI Pin
AndieDu9-Nov-11 23:03
AndieDu9-Nov-11 23:03 
Dear All,

I am scratching my head about 4 hours to get this sorted, but without any luck.

what i would like to do is on my windows form, it connects to a remote machine and then display all the programs that installed on a windows server 2003 box on a ListBox, then user can select one of the program, and click the Uninstall button to uninstall the selected program.

I am able to load all the programs installed on the remote machines by this code:
C#
public static ArrayList GetAppLists(string p_machineName)
        {
            RegistryHive hive = RegistryHive.LocalMachine;
            RegistryKey subKey;
            string displayName, displayVersion, keyNameCurrentMachine32;
            ArrayList al = new ArrayList();
            //ArrayList uninstallStrings = new ArrayList();

            keyNameCurrentMachine32 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            using (RegistryKey regHive = RegistryKey.OpenRemoteBaseKey(hive, p_machineName))
            {
                using (RegistryKey regKey = regHive.OpenSubKey(keyNameCurrentMachine32))
                {
                    if (regKey != null)
                    {
                        foreach (string k in regKey.GetSubKeyNames())
                        {
                            using (subKey = regKey.OpenSubKey(k))
                            {
                                displayName = subKey.GetValue("DisplayName") as string;
                                displayVersion = subKey.GetValue("DisplayVersion") as string;
                                if (!string.IsNullOrEmpty(displayName))
                                {
                                    al.Add(displayName + " " + displayVersion);
                                }
                            }
                        }
                    }
                }
            }
            return al;
        }


but when i try to uninstall the particular progarm by this code:
C#
private void UninstallProgram()
        {
            ConnectionOptions connection = new ConnectionOptions();
            connection.Username = txtDomain.Text + "\\" + txtUserName.Text;
            connection.Password = txtPassword.Text;
            connection.Impersonation = ImpersonationLevel.Impersonate;
            connection.Authentication = AuthenticationLevel.Packet;
            connection.EnablePrivileges = true;

            ManagementScope scope = new ManagementScope(@"\\" + cbServerAddress.Text + "\\root\\cimv2", connection);
            ManagementObject app = new ManagementObject(scope,
                                       new ManagementPath("Win32_Product.DisplayName='WinRAR 4.01 (32-bit)', DisplayVersion='4.01.0'"),
                                       null);
            MessageBox.Show(app.ToString());
            if (app != null)
            {
                ManagementBaseObject outParams = app.InvokeMethod("Uninstall", null, null);
                MessageBox.Show("finished");
            }
            else
            {
                MessageBox.Show("cant find app.");
            }
        }


it always returns "Invalid parameter", and the place throws exception was here:
C#
ManagementObject app = new ManagementObject(scope,
	new ManagementPath("Win32_Product.DisplayName='WinRAR 4.01 (32-bit)', DisplayVersion='4.01.0'"),


can someone in here assist me or point me to the right direction will be greatly appreciated.

Many thanks.

Andie
AnswerRe: Uninstall a none Microsoft program on a remote machine via WMI Pin
AndieDu10-Nov-11 11:15
AndieDu10-Nov-11 11:15 
QuestionHow can I use Word in C3.Net Not COM Componet Pin
yousefshokati9-Nov-11 20:03
yousefshokati9-Nov-11 20:03 
AnswerRe: How can I use Word in C3.Net Not COM Componet Pin
Wayne Gaylard9-Nov-11 21:19
professionalWayne Gaylard9-Nov-11 21:19 
QuestionRestore database with stored procedure Pin
nhanlaptrinh9-Nov-11 12:17
nhanlaptrinh9-Nov-11 12:17 
AnswerRe: Restore database with stored procedure Pin
Abhinav S9-Nov-11 16:54
Abhinav S9-Nov-11 16:54 
GeneralRe: Restore database with stored procedure Pin
nhanlaptrinh16-Nov-11 14:02
nhanlaptrinh16-Nov-11 14:02 
QuestionExport to Excel and Navigating to other Page Pin
pravin_mun9-Nov-11 6:51
pravin_mun9-Nov-11 6:51 
AnswerRe: Export to Excel and Navigating to other Page Pin
Dave Kreskowiak9-Nov-11 13:33
mveDave Kreskowiak9-Nov-11 13:33 
SuggestionRe: Export to Excel and Navigating to other Page Pin
RaviRanjanKr13-Nov-11 4:39
professionalRaviRanjanKr13-Nov-11 4:39 
Questionwhere to save my error.log? Pin
Jassim Rahma9-Nov-11 5:34
Jassim Rahma9-Nov-11 5:34 
AnswerMessage Removed Pin
9-Nov-11 5:50
professionalBert Mitton9-Nov-11 5:50 
GeneralRe: where to save my error.log? Pin
Dave Kreskowiak9-Nov-11 13:22
mveDave Kreskowiak9-Nov-11 13:22 
GeneralRe: where to save my error.log? Pin
Firo Atrum Ventus10-Nov-11 16:58
Firo Atrum Ventus10-Nov-11 16:58 
GeneralRe: where to save my error.log? Pin
Dave Kreskowiak10-Nov-11 18:40
mveDave Kreskowiak10-Nov-11 18:40 
GeneralRe: where to save my error.log? Pin
Pete O'Hanlon10-Nov-11 23:09
mvePete O'Hanlon10-Nov-11 23:09 
GeneralRe: where to save my error.log? Pin
Dave Kreskowiak11-Nov-11 2:51
mveDave Kreskowiak11-Nov-11 2:51 
AnswerRe: where to save my error.log? Pin
Luc Pattyn9-Nov-11 5:52
sitebuilderLuc Pattyn9-Nov-11 5:52 

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.