Install your own webinstall installation package step by step

Source: Internet
Author: User

1. To better operate IIS, add a class library (InstallClassLibrary) to the project. Code attachment
Copy codeThe Code is as follows:
Using System;
Using System. Collections;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Configuration. Install;
Using System. DirectoryServices;
Using System. Diagnostics;
Using System. Windows. Forms;
Using System. Security. AccessControl;
Using System. IO;
Namespace InstallClassLibrary
{
[RunInstaller (true)]
Public partial class WebInstaller: Installer
{
Public WebInstaller ()
{
InitializeComponent ();
}
Public override void Install (IDictionary stateSaver)
{
Base. Install (stateSaver );
CreateVirtualDir (); // the following code changes the directory permission specified for a website
DirectoryInfo di = new DirectoryInfo ("d: \ yourpath \ xml ");
If (di. Attributes & FileAttributes. ReadOnly )! = 0)
Di. Attributes = FileAttributes. Normal;
DirectorySecurity ds = di. GetAccessControl ();
Ds. AddAccessRule (new FileSystemAccessRule ("network service", FileSystemRights. Modify, InheritanceFlags. ObjectInherit | InheritanceFlags. ContainerInherit,
PropagationFlags. None, AccessControlType. Allow ));
Di. SetAccessControl (ds );
//
}
Void CreateVirtualDir ()
{
Try
{
DirectoryEntry root = new DirectoryEntry ("IIS: // localhost/W3SVC/1/root ");
DirectoryEntry newRoot = root. Children. Add ("virtualName", root. SchemaClassName );
NewRoot. Properties ["Path"] [0] = "d: \ yourpath"; // this. Context. Parameters ["targetdir"];
NewRoot. Properties ["AppIsolated"] [0] = 2; // The value 0 indicates that the application runs in the process. The value 1 indicates that the application is out of the process, and the value 2 indicates the process pool.
NewRoot. Properties ["AccessScript"] [0] = true; // executable script
NewRoot. Invoke ("AppCreate", true );
NewRoot. Properties ["DefaultDoc"] [0] = "login. aspx"; // set the start page
NewRoot. Properties ["AppFriendlyName"] [0] = "applicationName"; // Application name
NewRoot. CommitChanges ();
Root. CommitChanges ();
}
Catch (Exception ee)
{
MessageBox. Show ("virtual directory creation failed! You can create it manually! "+ Ee. message + ";" + ee. source + ";" + ee. targetSite + ";" + ee. innerException + ";" + ee. stackTrace, "Error", MessageBoxButtons. abortRetryIgnore, MessageBoxIcon. error, MessageBoxDefaultButton. button1, 0 );
}
}
}
}

2. Add the installation project to the solution, add the project output in the Setup, and add the WEB content and the class library you just created to the directory.
3. left-click the installation project and change the manufacturer, installation program title, installation for all users, and product name in the Properties window.
Right-click-View-custom operation, right-click Install-add custom operation-application folder, and select "Install class library (InstallClassLibrary, in the file system, right-click the application folder and set the default installation directory.
If you want to define more user installation data, add a user interface.

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.