C # written with CDs to make a start-up disc

xiaoxiao2021-03-06  42

C # prepared by the CD-ROM to do startup disk full description of: thinkersky (Email: yanghuangming@rongji.com) a: 1 programming ideas, create a boot disk boot disk, insert to create the program automatically detecting the drive to CD using WMI (Windows Management Architecture: Windows Management Instrumentation) Reads the serial number (with uniqueness) of the disc and write the serial number to the registry. 2 2: Related knowledge 1, what is WMI? WMI (Windows Management Architecture: Windows Management Instrument is the implementation of Microsoft Web-based Enterprise Management (WBEM) and Desktop Management Task Force (DMTF) industry standards. It is a standard-based development interface, which is used Control the management computer. It provides a simple way to manage and control system resources. If you want to know him, you can refer to Micorosft Platform SDK. In this case, we only achieve a simple feature, get our system CD Related information. [We need to implement classes provided under System.Management namespace.]. 2, how to operate the registry in the C # Operation of language operation registry in the registry, which is more simple and convenient to operate the registry in the C #.

The following example provides a method for operating the registry in the C #: use Microsoft.win32; useing system.diagnostry; private void access_registry () {// Create a new button under HKEY_LOCAL_MACHINE / SOFTWARE, Named CDDRIVESN RegistryKey Key = Registry.localmachine.opensubKey ("Software", true); // Add a sub-key registryKey newkey = key.createSubkey ("cddrivesn"); // Setting the value of this subkey newkey.setValue ("cddrivesn", "123456789" ); // Get data from the registry // to find your cpu registryKey pregkey = registry = pregalmachine; pregkey = pregKey.opkey ("hardware // description // system // centralprocessor // 0"); Object val = pRegKey.GetValue ( "VendorIdentifier"); Debug.WriteLine ( "The central processor of this machine is:" val); // delete the key RegistryKey delKey = Registry.LocalMachine.OpenSubKey ( "Software", true); Delkey.DeleteSubKey ("cddrivesn");} III, write code as follows 1, create a startup disk using system; useing system.drawing; useing system.collections; using system.componentmodel; using System.windows.Forms; use system.data; using system.diagnostics; using microsoft.win32; namespace at_regcdrom {/// //// Form1 summary description. /// public class form1: system.windows.Forms.form {///// The required designer variable. /// private System.ComponentModel.Container components = null; private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; private static string cdRomSn; public Form1 () {// // Windows Forms Designer supports // initializeComponent (); // // Todo: Add any constructor code //} //// / / / / / / / / / / / / / / / / / / / / / / / / / / / /.

/// Protected {if (disponents! = Null) {components.dispose ();}} Base.dispose ();} #Region Windows Form Designer Generated Code // /// Designer Supports the required method - Do not modify the // this method using the code editor. /// private void InitializeComponent () {System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (Form1)); this.label1 = new System.Windows.Forms.Label (); this.button1 = new System .Windows.Forms.Button (); this.suspendlayout (); /// Label1 // this.label1.location = new system.drawing.point (72, 16); this.label1.name = "label1"; This.label1.size = new system.drawing.size (144, 24); this.label1.tabindex = 0; this.label1.text = "Click Start CD Registration"; this.Label1.TextAlign = System.drawing. ContentAlignment.middleCenter; /// Button1 // this.button1.location = new system.drawing.point (104, 56); this.button1.name = "button1"; this.button1.size = new system.drawing. Size (72, 24); this.button1.tabindex = 1; this.button1.text = "Start registration"; this.button1.click = new system.eventhandler (this.button1_click); // // form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.s Ize (280, 101); this.controls.add (this.button1); this.controls.add (this.label1); this.icon = ((System.Drawing.icon) (Resources.GetObject ("$ this. Icon "))); this.maximizebox = false; this.name =" form1 "; this.text =" CD registration "; this.ResumeLayout (false);} #ENDREGION / / / // Application main entrance point.

/// [stathread] static void main () {Application.run (new form1 ());} // /// read the disc related information and registration. /// public void ReadCDRom () {// create a disc information of the object acquired ManagementClass driveClass = new ManagementClass ( "Win32_CDROMDrive"); // returns all instances of the class set ManagementObjectCollection drives = driveClass.GetInstances (); // set state Sign bit is initialized to false bool status = false; // Query all CD-ROM Foreach (ManagementObject DRVIVIVES) {Try {// Get the first serial number IF of the optical disk in the optical drive in the optical disc (DRV ["VoluMserialNumber"] .Tostring ()! = "" "" VolumeSerialnumber "]. TOSTRING (); status = true; // Query end break;}} catch {// Exception Status = false; Continue;}} IF (status) {// Start registration if (regcdromsn) {this.label1.text = "Successful registration!"; this.button1.text = "Close";} else {this.label1.text = "Registration failed ! ";" THIS.BUTTON1.TEXT = "Close";}} else {// Initializes the variables to pass to the messagebox.show method. String message = "Please insert the startup CD to register!"; String C aption = "CD Registration"; MessageBoxButtons buttons = MessageBoxButtons.OKCancel; DialogResult result; // Displays the MessageBox result = MessageBox.Show (this, message, caption, buttons, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);. if (result = = DialogResult.ok) {readcdrom ();} else {Application.exit ();}} DRIVECLASS.DISPOSE ();} /// /// The information is written to the registry.

转载请注明原文地址:https://www.9cbs.com/read-55079.html

New Post(0)