Implement mutual access between multiple servers and establish a connection to the server: Use the stored procedure: sp_add1_server; sp_add1_srvlogin
Beep:
[Dllimport ("kernel32.dll")]
Public static extern bool BEEP (INT frequency, int duration );
Public static void abeep (INT ifrequency, int iduration)
{
Beep (ifrequency, iduration );
}
//////////////////////////////
Draw an image on the screen
[Dllimport ("gdi32.dll")]
Static extern intptr createdc (string lpszdriver, string lpszdevice, string lpszoutput, intptr initdata );
Intptr screem = createdc ("display", null, null, intptr. Zero );
Graphics G = graphics. fromhdc (screem );
G. fillrectangle (brushes. Red, 0, 0, 1000,100 0 );
Refreshing desktop images disappears
//////////////////////////////
Read the serial number of the hard disk:
Private string [] getmoc ()
{
String [] STR = new string [2];
Managementclass mccpu = new managementclass ("win32_processor ");
Managementobjectcollection moccpu = mccpu. getinstances ();
Foreach (managementobject m in moccpu)
{
STR [0] = m ["processorid"]. tostring ();
}
Managementclass mchd = new managementclass ("win32_logicaldisk ");
Managementobjectcollection mochd = mchd. getinstances ();
Foreach (managementobject m in mochd)
{
If (M ["DeviceID"]. tostring () = "C :")
{
STR [1] = m ["volumeserialnumber"]. tostring ();
Break;
}
}
Return STR;
}
4. Read the hard disk ID
Dllimport ("kernel32.dll")]
Private Static extern int getvolumeinformation (
String lprootpathname,
String lpvolumenamebuffer,
Int nvolumenamesize,
Ref int lpvolumeserialnumber,
Int lpmaximumcomponentlength,
Int lpfilesystemflags,
String lpfilesystemnamebuffer,
Int nfilesystemnamesize
);
/////////////////////////////
(1) Draw control, which can be drawn outside the form
Controlpaint. drawreversibleframe (New rectangle (pbegin. X, pbegin. Y, pend. X-pbegin. X, pend. Y-pbegin. Y ),
Color. White, framestyle. Dashed );
/////////////////////////////
C # also supports editing the Registry. the. NET Framework provides two classes in the Microsoft. Win32 namespace to operate the Registry: Registry and registrykey. Both classes are sealed and cannot be inherited. Next we will introduce these two classes respectively.
The Registry class provides seven public static domains, which represent seven basic primary keys (two of which are not in the XP system and are not described here): Registry. classesroot, registry. currentuser, registry. localmachine, registry. users, registry. current Config. Which keys they correspond.
Registrykey class provides methods for registry operations. Note that the Registry must comply with system permissions; otherwise, an error will be thrown.
Below are some common methods to operate the registry.
The method prototype for creating a sub-key is:
Public registrykey createsubkey (string sunbkey );
The sunbkey parameter indicates the name or path name of the child key to be created. The created sub-key is returned. Otherwise, null is returned.
The prototype of the sub-key is as follows:
Public registrykey opensubkey (string name );
Public registrykey opensubkey (string name, bool writable );
The name parameter indicates the name or path name of the subkey to be opened. The writable parameter indicates whether the subkey to be opened can be modified. The subkey opened in the first method is read-only. The Microsoft. Win32 class also provides us with another method to open the registry on a remote computer. The prototype of the method is:
Public static registrykey openremotebasekey (registryhive hkey, string machinename );
The method prototype for deleting a sub-key is:
Public void deletekey (string subkey );
This method is used to delete a specified Primary Key. If the sub-key to be deleted also contains a primary key, the deletion fails and an exception is returned. If you want to completely delete the sub-key under the sub-key's extreme directory, you can use deletesubkeytree, the method is prototype as follows:
Public void deletekeytree (string subkey );
The following is a prototype of the key value reading method:
Public object getvalue (string name );
Public object getvalue (string name, object defaultvalue );
The parameter name indicates the key name. The return type is an object type. If the specified key does not exist, null is returned. If you do not want the returned value to be null, you can specify the defaultvalue parameter. If you specify a parameter, the value specified by this parameter is returned if the read fails.
the method prototype for setting the key value is as follows:
Public object setvalue (string name, object value);