C#部署数据库及IIS站点

一、前言

最近忙里偷闲,做了一个部署数据库及IIS网站站点的WPF应用程序工具。

二、内容

此工具的目的是:

  • 根据.sql文件在本机上部署数据库
  • 在本机部署IIS站点,包括新建站点,新建应用程序池。只新建而不会对本机上原有的程序池或站点做修改操作

最终样式:(Check按钮的作用是防止与本机已有的站点或程序池有冲突)

View:

<Window x:Class="AutoWebTool.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:local="clr-namespace:AutoWebTool"
    Title="Web Site Automatic Deployment" Height="500" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="0.5*"/>
      <RowDefinition Height="0.5*"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <GroupBox Header="DataBase Configuration" FontSize="15" BorderThickness="3" Margin="5,10" Grid.Row="0">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition/>
          <RowDefinition/>
          <RowDefinition/>
          <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="65*"/>
          <ColumnDefinition Width="133*"/>
          <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0" Text="Server Address" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26" />
        <TextBlock Grid.Row="1" Grid.Column="0" Text="User" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26" />
        <TextBlock Grid.Row="2" Grid.Column="0" Text="Password" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26" />
        <TextBlock Grid.Row="3" Grid.Column="0" Text="Script Path" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26" />

        <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding ServerAddress, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32" />
        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding User, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32" />
        <PasswordBox Grid.Row="2" Grid.Column="1" PasswordChar="*" local:PasswordBoxHelper.Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32">
          <i:Interaction.Behaviors>
            <local:PasswordBoxBehavior />
          </i:Interaction.Behaviors>
        </PasswordBox>
        <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding SqlPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32" />

        <Button Grid.Row="4" Grid.Column="2" Width="70" Height="25" Margin="0,0,10,0"
            HorizontalAlignment="Left" VerticalAlignment="Center" Content="Browse" Click="FilePathBrowse_Click"/>
      </Grid>
    </GroupBox>
    <GroupBox Header="WebSite And Pool" FontSize="15" BorderThickness="3" Margin="5,10" Grid.Row="1">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition/>
          <RowDefinition/>
          <RowDefinition/>
          <RowDefinition/>
          <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="65*"/>
          <ColumnDefinition Width="133*"/>
          <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0" Text="WebSite Name" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26" />
        <TextBlock Grid.Row="1" Grid.Column="0" Text="WebSite ID" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26" />
        <TextBlock Grid.Row="2" Grid.Column="0" Text="WebSite PhysicalPath" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26" />
        <TextBlock Grid.Row="3" Grid.Column="0" Text="WebSite Port" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26" />
        <TextBlock Grid.Row="4" Grid.Column="0" Text="Application Pool Name" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="15" Height="26"/>

        <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding WebSiteName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32" />
        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding WebSiteID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32" />
        <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding PhysicalPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32" />
        <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding WebSitePort, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32" />
        <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding PoolName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
           HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="15" Width="450" Height="32" />

        <Button Grid.Row="0" Grid.Column="2" Width="70" Height="25" Margin="0,0,10,0"
            HorizontalAlignment="Left" VerticalAlignment="Center" Content="Check" Click="WebSiteNameCheck_Click"/>
        <Button Grid.Row="1" Grid.Column="2" Width="70" Height="25" Margin="0,0,10,0"
            HorizontalAlignment="Left" VerticalAlignment="Center" Content="Check" Click="WebSiteIDCheck_Click"/>
        <Button Grid.Row="2" Grid.Column="2" Width="70" Height="25" Margin="0,0,10,0"
            HorizontalAlignment="Left" VerticalAlignment="Center" Content="Browse" Click="PathBrowse_Click"/>
        <Button Grid.Row="3" Grid.Column="2" Width="70" Height="25" Margin="0,0,10,0"
            HorizontalAlignment="Left" VerticalAlignment="Center" Content="Check" Click="WebSitePortCheck_Click"/>
        <Button Grid.Row="4" Grid.Column="2" Width="70" Height="25" Margin="0,0,10,0"
            HorizontalAlignment="Left" VerticalAlignment="Center" Content="Check" Click="PoolNameCheck_Click"/>
      </Grid>
    </GroupBox>
    <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="10">
      <Button Width="70" Height="25" Content="OK" Click="Deploy_Click"/>
      <Button Width="70" Height="25" Content="Cancel" Margin="10,0,0,0" Click="Close_Click"/>
    </StackPanel>
  </Grid>
</Window>

View的后台文件:

using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace AutoWebTool
{
  /// <summary>
  /// MainWindow.xaml 的交互逻辑
  /// </summary>
  public partial class MainWindow : Window
  {
    private AutoGenerationVM _vm;

    public MainWindow()
    {
      InitializeComponent();
      DataContext = new AutoGenerationVM();
      _vm = DataContext as AutoGenerationVM;
    }

    private bool sqlPath;
    private void FilePathBrowse_Click(object sender, RoutedEventArgs e)
    {
      sqlPath = _vm.GetSqlFilePath();
    }

    private void WebSiteNameCheck_Click(object sender, RoutedEventArgs e)
    {
      var isInUse = _vm.CheckNameAndID();
      if (isInUse)
      {
        MessageBox.Show("1.This name is Empty \r\n2.This name is in use,please change name!");
      }
      else
      {
        MessageBox.Show("No Problem!");
      }
    }

    private void WebSiteIDCheck_Click(object sender, RoutedEventArgs e)
    {
      var isInUse = _vm.CheckNameAndID();
      if (isInUse)
      {
        MessageBox.Show("1.This ID is Empty \r\n2.This ID is in use,please change ID!");
      }
      else
      {
        MessageBox.Show("No Problem!");
      }
    }

    private bool physicalPath;
    private void PathBrowse_Click(object sender, RoutedEventArgs e)
    {
      physicalPath = _vm.GetFolderPath();
    }
    private void WebSitePortCheck_Click(object sender, RoutedEventArgs e)
    {
      var isInUse = _vm.CheckWebPort();
      if (isInUse)
      {
        MessageBox.Show("1.This port is Empty \r\n2.This port is in use,please change port!");
      }
      else
      {
        MessageBox.Show("No Problem!");
      }
    }
    private void PoolNameCheck_Click(object sender, RoutedEventArgs e)
    {
      var isInUse = _vm.CkeckPoolName();
      if (isInUse)
      {
        MessageBox.Show("1.This pool name is Empty \r\n2.This name is in use,please change name!");
      }
      else
      {
        MessageBox.Show("No Problem!");
      }
    }

    private void Deploy_Click(object sender, RoutedEventArgs e)
    {
      var dataBaseServerAddressChecked = string.IsNullOrEmpty(_vm.ServerAddress);
      var dataBaseUserChecked = string.IsNullOrEmpty(_vm.User);
      var dataBasePasswordChecked = string.IsNullOrEmpty(_vm.Password);
      var dataBaseScriptChecked = sqlPath;
      var dataBaseCondition = !dataBaseServerAddressChecked && !dataBaseUserChecked && !dataBasePasswordChecked && !dataBaseScriptChecked;

      var webSiteNameAndIDChecked = _vm.CheckNameAndID();
      var webSitePortChecked = _vm.CheckWebPort();
      var applicationPoolNameChecked = _vm.CkeckPoolName();
      var webSiteCondition = !webSiteNameAndIDChecked && !physicalPath && !webSitePortChecked && !applicationPoolNameChecked;

      if (dataBaseCondition&& webSiteCondition)
      {
        _vm.Execute();
      }
      else {
        MessageBox.Show("Please Check Your Input!");
      }
    }

    private void Close_Click(object sender, RoutedEventArgs e)
    {
      Close();
    }
  }

  public static class PasswordBoxHelper
  {
    public static readonly DependencyProperty PasswordProperty =
      DependencyProperty.RegisterAttached("Password",
      typeof(string), typeof(PasswordBoxHelper),
      new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged));

    private static void OnPasswordPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
      var passwordBox = sender as PasswordBox;

      string password = (string)e.NewValue;

      if (passwordBox != null && passwordBox.Password != password)
      {
        passwordBox.Password = password;
      }
    }

    public static string GetPassword(DependencyObject dp)
    {
      return (string)dp.GetValue(PasswordProperty);
    }

    public static void SetPassword(DependencyObject dp, string value)
    {
      dp.SetValue(PasswordProperty, value);
    }
  }

  public class PasswordBoxBehavior : Behavior<PasswordBox>
  {
    protected override void OnAttached()
    {
      base.OnAttached();

      AssociatedObject.PasswordChanged += OnPasswordChanged;
    }

    private static void OnPasswordChanged(object sender, RoutedEventArgs e)
    {
      var passwordBox = sender as PasswordBox;

      string password = PasswordBoxHelper.GetPassword(passwordBox);

      if (passwordBox != null && passwordBox.Password != password)
      {
        PasswordBoxHelper.SetPassword(passwordBox, passwordBox.Password);
      }
    }

    protected override void OnDetaching()
    {
      base.OnDetaching();

      AssociatedObject.PasswordChanged -= OnPasswordChanged;
    }
  }
}

ViewModel:

using System;
using System.DirectoryServices;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using Microsoft.Web.Administration;
using System.Windows.Forms;
using System.Diagnostics;
using System.Data.SqlClient;
using System.IO;

namespace AutoWebTool
{
  public class AutoGenerationVM : INotifyPropertyChanged
  {

    public AutoGenerationVM()
    {
      _physicalPath = AppDomain.CurrentDomain.BaseDirectory;
    }

    //DataBase ServerAddress
    private string _serverAddress = string.Empty;

    public string ServerAddress
    {
      get { return _serverAddress; }
      set
      {
        if (_serverAddress != value)
        {
          _serverAddress = value;
          NotifyPropertyChanged("ServerAddress");
        }
      }
    }

    //DataBase User
    private string _user = string.Empty;

    public string User
    {
      get { return _user; }
      set
      {
        if (_user != value)
        {
          _user = value;
          NotifyPropertyChanged("User");
        }
      }
    }

    //DataBase Password
    private string _password = string.Empty;

    public string Password
    {
      get { return _password; }
      set
      {
        if (_password != value)
        {
          _password = value;
          NotifyPropertyChanged("Password");
        }
      }
    }

    //DataBase SQLPath
    private string _sqlPath = string.Empty;

    public string SqlPath
    {
      get { return _sqlPath; }
      set
      {
        if (_sqlPath != value)
        {
          _sqlPath = value;
          NotifyPropertyChanged("SqlPath");
        }
      }
    }

    public bool GetSqlFilePath() {

      var openFileDialog = new OpenFileDialog();
      openFileDialog.Filter = "数据库脚本文件|*.sql";
      if (openFileDialog.ShowDialog() == DialogResult.OK)
      {
        SqlPath = openFileDialog.FileName;
      }
      return false;
    }

    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //WebSite Name
    private string _webSiteName = string.Empty;

    public string WebSiteName
    {
      get { return _webSiteName; }
      set
      {
        if (_webSiteName != value)
        {
          _webSiteName = value;
          NotifyPropertyChanged("WebSiteName");
        }
      }
    }

    //WebSite ID
    private string _webSiteID = string.Empty;

    public string WebSiteID
    {
      get { return _webSiteID; }
      set
      {
        if (_webSiteID != value)
        {
          _webSiteID = value;
          NotifyPropertyChanged("WebSiteID");
        }
      }
    }

    /// <summary>
    /// Check WebSite Name and ID
    /// </summary>
    /// <returns></returns>
    public bool CheckNameAndID()
    {
      if (string.IsNullOrEmpty(WebSiteName) || string.IsNullOrEmpty(WebSiteID)) return true;

      DirectoryEntry rootEntry = new DirectoryEntry("IIS://localhost/w3svc");
      foreach (DirectoryEntry entry in rootEntry.Children)
      {
        if (entry.SchemaClassName.Equals("IIsWebServer", StringComparison.OrdinalIgnoreCase))
        {
          if (WebSiteID == entry.Name) {
            return true;
          }
          if (entry.Properties["ServerComment"].Value.ToString() == WebSiteName)
          {
            return true;
          }
        }
      }
      return false;
    }

    //Physical Path
    private string _physicalPath = string.Empty;

    public string PhysicalPath
    {
      get { return _physicalPath; }
      set
      {
        if (_physicalPath != value)
        {
          _physicalPath = value;
          NotifyPropertyChanged("PhysicalPath");
        }
      }
    }

    /// <summary>
    /// Get Path for WebSite
    /// </summary>
    public bool GetFolderPath()
    {
      if (string.IsNullOrEmpty(PhysicalPath)) return true;
      var openFolderDialog = new FolderBrowserDialog();
      if (openFolderDialog.ShowDialog() == DialogResult.OK)
      {
        PhysicalPath = openFolderDialog.SelectedPath;
      }
      return false;
    }

    //WebSite Port
    private string _webSitePort = string.Empty;

    public string WebSitePort
    {
      get { return _webSitePort; }
      set
      {
        if (_webSitePort != value)
        {
          _webSitePort = value;
          NotifyPropertyChanged("WebSitePort");
        }
      }
    }

    /// <summary>
    /// Check WebSite Port
    /// </summary>
    /// <returns></returns>
    public bool CheckWebPort()
    {
      try
      {
        IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
        IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();

        foreach (IPEndPoint endPoint in ipEndPoints)
        {
          if (endPoint.Port == Convert.ToInt32(WebSitePort))
          {
            return true;
          }
        }
        return false;

      }
      catch {

        return true;
      }
    }

    //Pool Name
    private string _poolName = string.Empty;

    public string PoolName
    {
      get { return _poolName; }
      set
      {
        if (_poolName != value)
        {
          _poolName = value;
          NotifyPropertyChanged("PoolName");
        }
      }
    }

    /// <summary>
    /// Check Application Pool Name
    /// </summary>
    /// <returns></returns>
    public bool CkeckPoolName()
    {
      if (string.IsNullOrEmpty(PoolName)) return true;
      var manager = new ServerManager();
      var list = manager.ApplicationPools;
      var matchedItem = list.FirstOrDefault(x => x.Name == PoolName);
      if (matchedItem != null)
        return true;
      return false;
    }

    /// <summary>
    /// Execute Script
    /// </summary>
    public void Execute()
    {
      //Deploy DataBase
      var tmpConn = new SqlConnection();
      tmpConn.ConnectionString = "SERVER = " + ServerAddress +"; DATABASE = master; User ID = " + User+ "; Pwd = " + Password+ ";";
      var scriptFile = new FileInfo(SqlPath);
      var sqlCreateDBQuery = scriptFile.OpenText().ReadToEnd();
      SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
      try
      {
        tmpConn.Open();
        myCommand.ExecuteNonQuery();
        MessageBox.Show("Database has been created successfully!","Create Database", MessageBoxButtons.OK,MessageBoxIcon.Information);
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.ToString(), "Create Database", MessageBoxButtons.OK, MessageBoxIcon.Information);
        return;
      }
      finally
      {
        tmpConn.Close();

      }

      try
      {
        //Deploy WebSite and Application Pool
        var script = "net start w3svc " +
               "& cd c:/Windows/System32/inetsrv " +
               "& appcmd add site /name:" + WebSiteName + " /id:" + WebSiteID +
               " /physicalPath:" + PhysicalPath + " /bindings:http/*:" + WebSitePort + ":" + WebSiteName +
               " & appcmd add apppool /name:" + PoolName + " /managedRuntimeVersion:v4.0 /managedPipelineMode:Integrated" +
               " & appcmd set site /site.name:" + WebSiteName + " /[path='/'].applicationPool:" + PoolName;

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.WorkingDirectory = @"C:\Windows\System32";
        startInfo.FileName = @"C:\Windows\System32\cmd.exe";
        startInfo.RedirectStandardInput = true;
        startInfo.RedirectStandardOutput = true;
        startInfo.RedirectStandardError = true;
        startInfo.UseShellExecute = false;
        startInfo.Verb = "RunAs";

        Process process = new Process();
        process.StartInfo = startInfo;
        process.Start();
        process.StandardInput.WriteLine(script);
        process.StandardInput.WriteLine("&exit");
        process.StandardInput.Flush();
        process.StandardInput.Close();
        process.WaitForExit();

        MessageBox.Show("IIS WebSite and Application Pool Deployed Successfully!", "Create WebSite and Application Pool", MessageBoxButtons.OK, MessageBoxIcon.Information);
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Information);
      }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string name)
    {
      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • C#实现获取IIS站点及虚拟目录信息的方法

    本文实例讲述了C#实现获取IIS站点及虚拟目录信息的方法.分享给大家供大家参考.具体如下: using System; using System.DirectoryServices; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DirectoryEntry rootEntr

  • C#操作IIS程序池及站点的创建配置实现代码

    首先要对Microsoft.Web.Administration进行引用,它主要是用来操作IIS7: using System.DirectoryServices;using Microsoft.Web.Administration; 1:首先是对本版IIS的版本进行配置: 复制代码 代码如下: DirectoryEntry getEntity = new DirectoryEntry("IIS://localhost/W3SVC/INFO");            string V

  • C#操作IIS方法集合

    C# 操作IIS方法集合 如果在win8,win7情况下报错:未知错误(0x80005000) ----见http://www.jb51.net/article/72881.htm using System; using System.Collections; using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using System.Net; using System.Tex

  • C# WebService发布以及IIS发布

    首先我们要做的就是先把IIS(Internet信息服务)打开,我用的是win8 的系统,所以这里以win8系统的操作来讲 一.IIS的一些事先操作 1.打开控制面板,然后进入程序 2.进入程序以后我们找到 启用或关闭Windows功能 3.进入以后把  Internet信息服务  的都选上,单击"确定" 上述的步骤好了以后我们退回到控制面板  ,找到   系统和安全 里面的  管理工具     点击"管理工具"    ,第一个就是我们的IIS了,双击打开它 我们会弹

  • C#修改IIS站点framework版本号的方法

    本文实例讲述了C#修改IIS站点framework版本号的方法.分享给大家供大家参考.具体如下: 使用ASP.NET IIS 注册工具 (Aspnet_regiis.exe)可以方便地更新 ASP.NET 应用程序的脚本映射,使其指向与该工具关联的 ASP.NET ISAPI 版本. 关于ASP.NET IIS 注册工具的更详细的内容,请参考MSDN. 在控制台上我们使用下面的命令可以修改一个虚拟目录的Asp.Net版本: 复制代码 代码如下: Aspnet_iis.exe –s path 我们

  • c#操作iis根目录的方法

    本文实例讲述了c#操作iis根目录的方法.分享给大家供大家参考.具体实现方法如下: using System; using System.DirectoryServices; using System.Collections; namespace IISManagement { /// <summary> /// IISManager 的摘要说明. /// </summary> public class IISManager { //定义需要使用的 private string _

  • C#无法打开计算机“.”上的 IISADMIN 服务的解决方法

    在使用c#进行控制IIS服务启动停止的时候,提示:[无法打开计算机"."上的 IISADMIN 服务] 这种情况是发生在像vista.win7.win2008这类带UAC的系统,原因就是c#的程序没有权限去执行控制IIS服务. 调试出错提示: 执行程序出错提示: 对于没有权限这问题,通常使用右键以管理员的身份运行程序即可,或者把UAC关掉,不过对于写程序的我们来说,会认为这种体验是一个恶梦,必须找到方法获取权限. 方法是有的,在VS2008 c#可以用manifest使程序以管理员身份

  • c# 解决IIS写Excel的权限问题

    具体配置方法如下: 1:在服务器上安装office的Excel软件. 2:在"开始"->"运行"中输入dcomcnfg.exe启动"组件服务" 3:依次双击"组件服务"->"计算机"->"我的电脑"->"DCOM配置" 4:在"DCOM配置"中找到"Microsoft Excel 应用程序",在它上面点击

  • 用C#操纵IIS(代码)

    using System;  using System.DirectoryServices;  using System.Collections;  using System.Text.RegularExpressions;  using System.Text;  /**   * @author 吴海燕   * @email  wuhy80-usual@yahoo.com   * 2004-6-25 第一版   */   namespace Wuhy.ToolBox  {       /// 

  • C#创建IIS虚拟目录的方法

    本文实例讲述了C#创建IIS虚拟目录的方法.分享给大家供大家参考.具体分析如下: DirectoryEntry是.Net给我们的一大礼物,他的名字我们就知道他的功能--目录入口.使用过ADSI的人都知道操作IIS,WinNT这些时,我们还需要提供他们的Path,操作IIS时,这个Path的格式为: 复制代码 代码如下: IIS://ComputerName/Service/Website/Directory ComputerName:即操作的服务器的名字,可以是名字也可以是IP,经常用的就是lo

随机推荐