using System;
using Microsoft.Win32;
class Class1 {
static void Main(string[] args) {
RegistryKey myRegKey = Registry.LocalMachine;
myRegKey = myRegKey.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionUninstall");
String[] subkeyNames = myRegKey.GetSubKeyNames();
foreach (String s in subkeyNames) {
RegistryKey UninstallKey = Registry.LocalMachine;
UninstallKey = UninstallKey.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionUninstall" + s);
try {
Object oValue = UninstallKey.GetValue("DisplayName");
Console.WriteLine(oValue.ToString());
} catch (NullReferenceException) {
}
}
}
}
Software Development
software development notes, main category for Cs, Java, and other programming experiences.
Write a Text and DWord Value to the Registry
using System;
using Microsoft.Win32;
class Class1 {
static void Main(string[] args) {
RegistryKey RegKeyWrite = Registry.CurrentUser;
RegKeyWrite = RegKeyWrite.CreateSubKey("SoftwareCSHARPWriteRegistryValue");
RegKeyWrite.SetValue("Success", "TRUE");
RegKeyWrite.SetValue("AttemptNumber", 1);
RegKeyWrite.Close();
RegistryKey RegKeyRead = Registry.CurrentUser;
RegKeyRead = RegKeyRead.OpenSubKey("SoftwareCSHARPWriteRegistryValue");
Object regSuccessful = RegKeyRead.GetValue("Success");
Object regAttemptNumber = RegKeyRead.GetValue("AttemptNumber");
RegKeyRead.Close();
Console.WriteLine(regSuccessful);
}
}
Registry.LocalMachine
using System;
using Microsoft.Win32;
using System.Security.Permissions;
[RegistryPermissionAttribute(SecurityAction.Demand)]
class Class1 {
static void Main(string[] args) {
RegistryKey myRegKey = Registry.LocalMachine;
myRegKey = myRegKey.OpenSubKey("SOFTWAREMicrosoftWindows NTCurrentVersion");
Object oValue = myRegKey.GetValue("RegisteredOwner");
Console.WriteLine("OS Registered Owner: {0}", oValue.ToString());
}
}
new RegexCompilationInfo(@”^d{4}$”,RegexOptions.Compiled, “PinRegex”, “”, true)
using System;
using System.Reflection;
using System.Text.RegularExpressions;
class MainClass
{
public static void Main()
{
RegexCompilationInfo[] regexInfo = new RegexCompilationInfo[2];
regexInfo[0] = new RegexCompilationInfo(@"^d{4}$",RegexOptions.Compiled, "PinRegex", "", true);
regexInfo[1] = new RegexCompilationInfo(@"^d{4}-?d{4}-?d{4}-?d{4}$",RegexOptions.Compiled, "CreditCardRegex", "", true);
AssemblyName assembly = new AssemblyName();
assembly.Name = "MyRegEx";
Regex.CompileToAssembly(regexInfo, assembly);
}
}
Regex.CompileToAssembly
using System;
using System.Reflection;
using System.Text.RegularExpressions;
class MainClass {
public static void Main() {
RegexCompilationInfo[] regexInfo = new RegexCompilationInfo[2];
regexInfo[0] = new RegexCompilationInfo(@"^d{4}$", RegexOptions.Compiled, "PinRegex", "", true);
regexInfo[1] = new RegexCompilationInfo(@"^d{4}-?d{4}-?d{4}-?d{4}$", RegexOptions.Compiled, "CreditCardRegex", "", true);
AssemblyName assembly = new AssemblyName();
assembly.Name = "MyRegEx";
Regex.CompileToAssembly(regexInfo, assembly);
}
}
Uses an object in another application domain
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example18_3.cs uses an object in another application domain
*/
using System;
using System.Runtime.Remoting;
using System.Reflection;
public class Example18_3
{
public static void Main()
{
// create a new appdomain
AppDomain d = AppDomain.CreateDomain("NewDomain");
// load an instance of the System.Rand object
ObjectHandle hobj = d.CreateInstance("Example18_2", "SimpleObject");
// use a local variable to access the object
SimpleObject so = (SimpleObject) hobj.Unwrap();
Console.WriteLine(so.ToUpper("make this uppercase"));
}
}
//=================================================
/*
Example18_2.cs defines a simple object to create
*/
using System;
[Serializable]
public class SimpleObject
{
public String ToUpper(String inString)
{
return(inString.ToUpper());
}
}
Illustrates unloading an application domain
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example18_4.cs illustrates unloading an application domain
*/
using System;
using System.Runtime.Remoting;
using System.Reflection;
public class Example18_4
{
public static void Main()
{
// create a new appdomain
AppDomain d = AppDomain.CreateDomain("NewDomain");
// load an instance of the SimpleObject class
ObjectHandle hobj = d.CreateInstance("Example18_2", "SimpleObject");
// use a local variable to access the object
SimpleObject so = (SimpleObject) hobj.Unwrap();
Console.WriteLine(so.ToUpper("make this uppercase"));
// unload the application domain
AppDomain.Unload(d);
Console.WriteLine(so.ToUpper("make this uppercase"));
}
}
//===================================================
/*
Example18_2.cs defines a simple object to create
*/
using System;
[Serializable]
public class SimpleObject
{
public String ToUpper(String inString)
{
return(inString.ToUpper());
}
}