Use C # To design a driver backup program code. First, obtain the driver information from the registry:
In Windows, select Run, type "Regedit" in the command line, open the Registry Editor, and find the directory HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ class. There are multiple subdirectories under this level of directory, each of which is a driver. The driver name is described in driverdesc, and the driver publishing vendor information is described in providername, the information document name under the INF directory is described in infpath, which is an INI structure. The sourcedisksfiles section in the information file describes the driver. Program The files are saved in the Windows main directory in the System32 directory and in the corresponding drivers help spool \ drivers \ color INF nview subdirectory. After obtaining the information, you can back up the driver.
Therefore, if you use C #, you must first solve the problem of reading the INI file, although there is a ready-made API getprivateprofilestring writeprivateprofilestring;
The designed INI File Reading Class must implement the key value in the enumeration segment, because the INI content like this must be read as follows:
[Sourcedisksfiles]
Ialmnt5.sys = 1
Ialmsbw. sys = 1
Ialmkchw. sys = 1
Because the content of sourcedisksfiles is uncertain, the following method is implemented:
// From the INI file, add all ident in the specified section name to the list.
Public Void Readsection ( String Section, stringcollection idents) {
Byte [] Buffer = New Byte [ 16384 ];
// Idents. Clear ();
Int Buflen = Getprivateprofilestring (section, Null , Null , Buffer, buffer. getupperbound ( 0 ),
Filename );
// Parse Section
Getstringsfrombuffer (buffer, buflen, idents );
}
For the complete INIFILE class, read C # an INI operation class.
Step 2: Access the registry;
. NET provides the Registry class. The access key value method is very simple but inconvenient;
So add an extension class to implement path-based access, for example, access
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ class \
All the following key names can be written as follows:
/**/ /// <Summary>
///Primary Key name of the mounted System Device
/// </Summary>
/// <Returns>Array</Returns>
Public String [] Loadlocalmachinecontrolnames () {
ReturnRegistry. localmachine. opensubkey ("System"). Opensubkey ("CurrentControlSet"). Opensubkey ("Control"). Opensubkey ("Class"). Getsubkeynames ();
}
But is it a little too intuitive;
Add a method:
/**/ /// <Summary>
/// Nodes can be expanded by Hierarchy
/// For example, \ System \ CurrentControlSet \ Control \ class \
/// </Summary>
/// <Param name = "key"> Hierarchical text </Param>
/// <Returns> Last key </Returns>
Public Registrykey openregistrykey ( String Key) {
String [] Keys = Key. Split ( " \\ " . Tochararray ());
Registrykey rk = Registry. localmachine;
Try {
For ( Int I = 0 ; I < Keys. length; I ++ ) {
If(Keys [I]. Trim (). Length>0)
Rk=Rk. opensubkey (Keys [I]);
}
Return Rk;
} Catch {
Return Null;
}
}
Directly access the last key by passing a string. application instance:
StringDriverkey= @"\ System \ CurrentControlSet \ Control \ class \" +S [I];
Registrykey rk=RH. openregistrykey (driverkey );
With these foundations, you can write a program. For details, download the source code;
But first declare,CodeIt's so bad that you don't need to talk about anything else.
Here you can preview the program interface:
author: Xiao Han,