C # prepared by the CD-ROM to do startup disk full description of: thinkersky (Email: yanghuangming@rongji.com)? A: programming ideas ?? 1, create a boot disk ?????? insert to create the startup disk, automatically detects The optical disk in the optical drive, reads the serial number (unique) of the disc with WMI (Windows Management Architecture: Windows Management Instrument), and write the serial number to the registry. 2. When the verification is executed, the disc is automatically detected in the optical drive, uses the WMI to obtain the serial number, then read the serial number previously written in the registry, the two compare, the same, the program starts success, otherwise the prompt is inserted into the boot disk . 2: Related knowledge ?? 1, what is WMI? WMI (Windows Management Architecture: Windows Management Instrument) is an implementation of Microsoft's Web-based Enterprise Management (WBEM) and Desktop Management Task Force (DMTF) industry standards. Just a standard system management development interface, this set of interfaces To 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 function, to get our system Related information about the disc. [We need to implement classes provided under System.Management namespace.]. 2, how to operate the registry in C # ????? Use the examples of language operation registry using VC, VB, in fact, in fact, the registry is more simple and convenient to operate in C #.
The following example provides the method of operating the registry in the C #: ??? using microsoft.win32; ??? using system.diagnostics; ??? private void access_registry () ??? {??????? ? // Create a new button under HKEY_LOCAL_MACHINE / SOFTWARE, named cddrivesn ??????????? registryKey key = registry ("software", true); ?????? ?? // Add a child ??????????? regiSTryKey newkey = key.createSubkey ("cddrivesn"); ???????? // Set the value of this subkey ??? ???????? Newkey.setValue ("cddrivesn", "123456789"); ???????? // Observe data from other places in the registry ???????? // Have your CPU ??????????? registryKey pregkey = registry.localmachine; ????????? pregkey = pregKey.opensubkey ("hardware // description // system /// centralprocessor // 0 "); ??????????? Object val = pregKey.getValue (" vendoridentifier "); ??????????? debug.writeline (" The Central Processor of this Machine IS : " VAL); ???????? // Delete key value ??????????? registryKey Delkey = registry.localMachine.Opensubkey (" Software ", true); ???? ??????? Delkey.deleteSubKey ("cddrivesn");} III: Writing code is as follows? 1, create a startup disk using system; use system.drawing; useing system.collections; using system.componentmodel; using s YSTEM.WINDOWS.FORMS; Using System.data; use system.Management; use 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 Form Designer Support
??? //
? ??? initializationComponent ();
??? // ??? // Todo: Add any constructor code after INITIALIZECOMPONENT calls ??? // ??}
?? ///
?? /// Clean all the resources being used. ?? ///
?? protected override void dispose (Bool Disposing)
?? {
??? i (disposing)
??? {
???? if (Components! = NULL)
???? {
????? components.dispose ();
????}
???}
? ?????????????????????????????????????????????????????????????????????????????
??}
? # Region Windows Form Designer Generated code ?? ///
?? /// Designer supports the required method - do not use the code editor to modify ?? // This method. ?? ///
?? 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.size (280, 101);
??? this.Controls.add (this.button1);
??? this.controls.add (this.label1);
??? this.icon = ((System.drawing.icon) ("$ this.icon")))))));
??? this.maximizebox = false;
??? this.name = "form1";
??? this.text = "CD registration";
??? this.ResumeLayout (false);
??} ?? # endregion ?? ///
??/// The main entry point for the application. ?? ///
?? [stathread]
?? static void main ()
?? {
??? Application.run (New Form1 ());
??}
?? ///
?? // read the disc related information and register. ?? ///
?? public void readcdrom ()
?? {
??? // Create an access object information
???????????????N "Win32_CDROMDRIVE");
/ / Return to all instances of this class ??? ManagementObjectCollection drives = driveclass.getinstances (); ??? // Setting status flag is initialized to false ??? Bool status = false; ??????? ???? ??? // Query all the optical drive ??? Foreach (ManagementObject DRVIVIN DRIVES ??? {????? Try ???? {????? // Prior to acquiring the first The serial number of the disc in the optical drive in the optical disk ????? IF (DRV ["VoluMserialNumber"]. ToString ()! = "") ????? {?????? CDROMSN = DRV ["VoluMserNumber "] .Tostring (); ?????? status = true; ?????? // end ?????? Break; ?????} ???????? } ???? carat ???? {????? // appeared abnormal
????? status = false; ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???} ???????????????? f (status) ??? {??????????????? // start registration??? ? if (regcdromsn) ???? {????? this.label1.text = "Register success!"; ????? this.button1.text = "Close"; ????} ???? Else ???? {????? this.label1.text = "Registration failed!"; ????? this.button1.text = "Close"; ????} ??? ?????? ???} ???????? {????? initializes the variables to pass to the messagebox.show method.
???? String message = "Please insert the startup CD to register!"
???? // displays the messagebox.
???? result = messagebox.show (this, message, caption, buttons, ????? MessageBoxicon.warning, messageboxdefaultbutton.button1); ???? if (result == DialogResult.ok) ???? { ????? readcdrom (); ????} ???? Else ???? {????? Application.exit (); ????} ??????}??? DRIVECLASS.DISPOSE (); ?? ????} ?? ///
?? /// written the information to the registry. ?? ///
?? public bool regcdromsn (String Sn) ?? {
??? Try
??? {
???? // established a new button under hkey_local_machine / software, named CDDRIVESN ??????
???? registryKey key = registry.localmachine.opensubKey ("Software", true);
???? // Add a child
???? registryKey newkey = key.createSubkey ("cddrivesn");
???? // Set the value of this subkey
??? NEWKEY.SETVALUE ("cddrivesn", SN);
??????????????? // successfully returned TRUE
???? Return True;
???} ??? catch ??? {???? // appear anomaly return false ????? Return false; ???}
??}
?? private void button1_click (object sender, system.eventargs e) ?? {??? if (this.button1.text == "Start registration") ??? {???? this.button1.text = "cancellation Register ";?? ??? {???????} ??? Else ??? {?????????????? Application.exit (); ?? ?
??}?}}
2, verifying [application]? The verification principle is the same as registration, so don't do more descriptions, friends who want to code, please send a message to my mailbox [yanghuaGming@rongji.com]. The above code runs through the Visual Studio .NET 2003 environment. This is some of the stuffs used in an application for an anti-CD piracy company. Here and everyone will discuss it. If there is any shortcomings, welcome advice, 3Q. ?????????????????????????????????????????? ?????????????????????