Jump to content

C Sharp - Question - Multiple Commands in one


Recommended Posts

Hi @ all,

im in a Projekt to help my co Workers with a little app to save time in uninstallig a special app - My Goal is to write this tool in Framework 2.0 (Windows Forms Projekt) and later after 6-8Months to Framework 3.5.

OK now to my question - I know it sounds N00b but need help on how to setoff multiple commands to scan registry on a button.

My Code Looks like so:



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Security.Principal;
using System.Diagnostics;
using Microsoft.Win32;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button5_Click(object sender, EventArgs e)
{
WindowsIdentity wi = WindowsIdentity.GetCurrent();
WindowsPrincipal wp = new WindowsPrincipal(wi);

if (wp.IsInRole(WindowsBuiltInRole.Administrator))


// Ok, user is administrator
MessageBox.Show("OK");

else

// Non privileged user, not ok to continue...

MessageBox.Show("Nooooooo");
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string mailtoString = @"mailto:xxx@xxx.xx";

Process.Start(mailtoString);
}

private void button3_Click(object sender, EventArgs e)
{
this.Close();
}

private void button2_Click(object sender, EventArgs e)
{
string MyKeyName = "HKEY_LOCAL_MACHINE\\Software\\Test\\Product\\PAA003XX\\Versions\\1.0";
string MyKeyName1 = "HKEY_LOCAL_MACHINE\\Software\\Test\\Packages\\PAA003YY\\Versions\\1.0";
string MyValueName = "CompVersion";
string MyValueName1 = "CompVersion";
string MyValue = "####";
string MyValue1 = "####";
object MyObject = null;
object MyObject1 = null;


//Registry.GetValue returns an object:

MyObject1 = Registry.GetValue(MyKeyName1, MyValueName1, null);
if (MyValue1 != "####")
{
//Get the string value of the object returned:
MyValue1 = MyObject1.ToString();

MessageBox.Show("Product Version = " + MyValue1);
}

else
{
MessageBox.Show("Product X not found");
}

MyObject = Registry.GetValue(MyKeyName, MyValueName, null);

if (MyValue != "####")
{
//Get the string value of the object returned:
MyValue = MyObject.ToString();

MessageBox.Show("Product Version = " + MyValue);
}

else
{
MessageBox.Show("Product Y not found");
}




}
}
}

Main Code of problem is the Event from private void button2_Click(object sender, EventArgs e) - Downwards the rest is kinda ok. :D

how do i get this to work im very new to C Sharp still need to learn allot. ;)

Many MAny thx in advance Val.

--------------------- UPDATE -------------------------

----------------------SOLVED------------------

Yes I did it --> So this is the Code I use now and it works! :D


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Security.Principal;
using System.Diagnostics;
using Microsoft.Win32;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button5_Click(object sender, EventArgs e)
{
WindowsIdentity wi = WindowsIdentity.GetCurrent();
WindowsPrincipal wp = new WindowsPrincipal(wi);

if (wp.IsInRole(WindowsBuiltInRole.Administrator))


// Ok, user is power user or administrator
MessageBox.Show("OK");

else

// Non privileged user, not ok to continue...

MessageBox.Show("Nooooooo");
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string mailtoString = @"mailto:xxxx@xxxxx.xx";

Process.Start(mailtoString);
}

private void button3_Click(object sender, EventArgs e)
{
this.Close();
}

private void button2_Click(object sender, EventArgs e)
{
string MyKeyName = "HKEY_LOCAL_MACHINE\\Software\\XXXXX\\Packages\\PYY003XX\\Versions\\1.0";
string MyKeyName1 = "HKEY_LOCAL_MACHINE\\Software\\YYYYY\\Packages\\PYY003YY\\Versions\\1.0";
string MyValueName = "CompVersion";
string MyValueName1 = "CompVersion";
string MyValue = "";
string MyValue1 = "";
object MyObject = null;
object MyObject1 = null;


//Registry.GetValue returns an object:

MyObject = Registry.GetValue(MyKeyName, MyValueName, null);
if (MyObject != null)
{
//Get the string value of the object returned:
MyValue = MyObject.ToString();

MessageBox.Show("Product X Version = " + MyValue);
}

else
{
MessageBox.Show("Product X not found!");
MyObject1 = Registry.GetValue(MyKeyName1, MyValueName1, null);

if (MyObject1 != null)
{
//Get the string value of the object returned:
MyValue1 = MyObject1.ToString();

MessageBox.Show("Product Y Version = " + MyValue1);
}

else
{
MessageBox.Show("Product Y not found!");
}
}






}
}
}

So what happened ive mixed the MyObject with the MyValue and recieved a String Error if nothing was found and if something got found nothing will happen becouse it got stuck. Now it searches for Product X and if thatone got found its done - But if Product X wasnt found it will search for Product Y and then its done ---- IF Found dialouge with Version of Product X/or/Y or a Message!!! :D

So many many Thanks @ all - Bestregards HAppy Holidays @ ll and BEst regards Val.

Edited by Valvaris
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...