Using System;
Using System. Collections. Generic;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using Microsoft. Win32;
Public partial class PrintSetDefault: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
If (ReadReg () = 1)
{
If (WriteReg () = 1)
{
ReadReg ();
Response. Write ("Game over! ");
}
}
}
/// <Summary>
/// Read the Registry
/// </Summary>
/// <Returns> </returns>
Protected int ReadReg ()
{
// Read the Registry
RegistryKey regRead;
// Read the subkey in the HKEY_CURRENT_USER primary key
RegRead = Registry. CurrentUser. OpenSubKey ("Software \ Microsoft \ Internet Explorer \ PageSetup", true );
If (regRead = null) // if the child key does not exist
{
Response. Write ("PageSetup: null </br> ");
Return 0;
}
Else
{
Response. Write ("PageSetup: OK </br> ");
Object obj = regRead. GetValue ("header") = null? "Null": regRead. GetValue ("header"); // read the value
Response. Write ("header:" + obj. ToString () + "</br> ");
Obj = regRead. GetValue ("footer") = null? "Null": regRead. GetValue ("footer"); // read the value
Response. Write ("footer:" + obj. ToString () + "</br> ");
Obj = regRead. GetValue ("margin_left") = null? "Null": regRead. GetValue ("margin_left"); // read the value
Response. Write ("margin_left:" + obj. ToString () + "</br> ");
Obj = regRead. GetValue ("margin_right") = null? "Null": regRead. GetValue ("margin_right"); // read the value
Response. Write ("margin_right:" + obj. ToString () + "</br> ");
Obj = regRead. GetValue ("margin_top") = null? "Null": regRead. GetValue ("margin_top"); // read the value
Response. Write ("margin_top:" + obj. ToString () + "</br> ");
Obj = regRead. GetValue ("margin_bottom") = null? "Null": regRead. GetValue ("margin_bottom"); // read the value
Response. Write ("margin_bottom:" + obj. ToString () + "</br> ");
Obj = regRead. GetValue ("Print_Background") = null? "Null": regRead. GetValue ("Print_Background"); // read the value
Response. Write ("Print_Background:" + obj. ToString () + "</br> ");
Response. Write ("</br> ");
}
RegRead. Close ();
Return 1;
}
/// <Summary>
/// Write the Registry
/// </Summary>
Protected int WriteReg ()
{
// Write the Registry
RegistryKey regWrite;
// Write the subkey to the primary key of HKEY_CURRENT_USER
// If the sub-key already exists, the system will automatically overwrite it
RegWrite = Registry. CurrentUser. CreateSubKey ("Software \ Microsoft \ Internet Explorer \ PageSetup ");
// Add data items to the Test subkey
RegWrite. SetValue ("header", "& w & bPage & p of & P ");
RegWrite. SetValue ("footer", "& u & B & d ");
RegWrite. SetValue ("margin_left", 0.750000 );
RegWrite. SetValue ("margin_right", 0.750000 );
RegWrite. SetValue ("margin_top", 0.750000 );
RegWrite. SetValue ("margin_bottom", 0.750000 );
RegWrite. SetValue ("Print_Background", "no ");
// Close this object
RegWrite. Close ();
Return 1;
}
}
The above result is restored to the default value. You can also change it to 0.
Eat to live, but do not live to eat.
From Zhang Yin's blog