C # Write IE configuration tool

Source: Internet
Author: User

Recently, when I was working on OA, I encountered many configuration items that need to be manually modified for IE, such as file download prompts, ActiveX prompts, and browser tag settings. I felt that if I had asked users to manually configure them, it is estimated that every user will be very annoying, especially users with low computer level. After a period of exploration, I found that all the iesettings are in the registry. Why not write a tool to modify the registry? My requirements are as follows:

1. You need to modify several IE configuration items and remove the security prompt when running the OA so that the user can use the system smoothly.

2. After logging on to the system, the full screen IE window is displayed. This window is used. open () does a good job, but if you open a new window in the new tab during ie settings, the effect will not be reached, and if you enable the interception window, window. open cannot pop up the window.

3. Generate a shortcut on the desktop and click the shortcut to go To the OA logon page.

First:

The following code is used:

Private void btnOK_Click (object sender, EventArgs e)
{
If (txtAddress. Text. Trim () = "")
{
MessageBox. Show ("Enter the OA address ");
Return;
}
Try
{
String ipAddress = txtAddress. Text. Replace ("http ://","");
// Modify the security settings of a trusted site
RegistryKey key = Registry. CurrentUser;
RegistryKey subkey = key. OpenSubKey ("Software \ Microsoft \ Windows \ CurrentVersion \ Internet Settings \ Zones \ 2", true );
Subkey. SetValue ("1001", 0 );
Subkey. SetValue ("1004", 0 );
Subkey. SetValue ("1200", 0 );
Subkey. SetValue ("1201", 0 );
Subkey. SetValue ("1208", 0 );
Subkey. SetValue ("1209", 0 );
Subkey. SetValue ("1405", 0 );
Subkey. SetValue ("1803", 0 );
Subkey. SetValue ("1806", 0 );
Subkey. SetValue ("1809", 1 );
Subkey. SetValue ("2000", 0 );
Subkey. SetValue ("2200", 0 );
Subkey. SetValue ("2201", 0 );
// Modify the tab Display Mode
RegistryKey tabKey = key. OpenSubKey ("Software \ Microsoft \ Internet Explorer \ TabbedBrowsing", true );
If (tabKey = null)
{
MessageBox. Show ("IE browser not initialized ");
Return;
}
TabKey. SetValue ("PopupsUseNewWindow", 0 );

If (radioButton1.Checked)
{
// Add an IP address to a trusted site
String ipStr = ipAddress. Split ('/') [0];
RegistryKey hkml = Registry. CurrentUser; // read HKEY_CURRENT_USER
String address = @ "SOFTWARE \ MICROSOFT \ WINDOWS \ CURRENTVERSION \ internet settings \ ZONEMAP \ RANGES ";
RegistryKey key1 = hkml. OpenSubKey (address, true );
RegistryKey Name1 = key1.CreateSubKey ("RANGES1"); // create an item
Name1.SetValue (": Range", ipStr, RegistryValueKind. String); // value assignment
Name1.SetValue ("http", 0x2, RegistryValueKind. DWord); // assign a value
}
Else
{
// Add a trusted site
String domainStr = ipAddress. Split ('/') [0];
String [] domainStrs = domainStr. Split ('.');
String domainName = "";
For (int I = 1; I <domainStrs. Length; I ++)
{
DomainName + = domainStrs [I] + ".";
}
DomainName = domainName. Trim ('.');
RegistryKey hkml = Registry. CurrentUser; // read HKEY_CURRENT_USER
String address = @ "SOFTWARE \ MICROSOFT \ WINDOWS \ CURRENTVERSION \ internet settings \ ZONEMAP \ Domains ";
RegistryKey key1 = hkml. OpenSubKey (address, true );
RegistryKey domain = key1.CreateSubKey (domainName); // create an item
RegistryKey ww = domain. CreateSubKey ("www"); // new sub-item www is replaced as needed
Ww. SetValue ("https", 0x2, RegistryValueKind. DWord); // assign a value
}
// Create a shortcut
WshShell shell = new WshShell ();
IWshShortcut shortcut = (IWshShortcut) shell. CreateShortcut (Environment. GetFolderPath (Environment. SpecialFolder. Desktop) + "//" + txtShortCut. Text. Trim () + ". lnk ");
Export cut. TargetPath = IEFilePath ();
Shortcut. Arguments = txtAddress. Text;
Export cut. WindowStyle = 3; // maximize the form
Export cut. Description = "ing OA Quick Start mode ";
Export cut. IconLocation = Application. StartupPath + "\ FrmIcon. ico"; // icon
Shortcut cut. Save ();
MessageBox. Show ("configured successfully ");
Application. Exit ();
}
Catch (Exception)
{
MessageBox. Show ("Make sure the OA address is correct ");
}
}

/// <Summary>
/// Obtain the path of IE
/// </Summary>
/// <Returns> </returns>
Public string IEFilePath ()
{
Return System. IO. Path. Combine (Environment. GetFolderPath (Environment. SpecialFolder. ProgramFiles), "Internet Explorer \ iw.e.exe ");
}

This is perfect.

Run and enter the corresponding items to generate a shortcut:

Click to enter:

The full screen window is displayed after Logon:

So far, the development of the Configuration tool has been completed. The image on the desktop does not match the whole system. Does anyone have a good image? It's a pain if you don't have an artist. If someone is interested in designing a desktop image for the system, please contact me to make some money...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.