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.