【问题标题】:C#: Custom action at UninstallC#:卸载时的自定义操作
【发布时间】:2011-03-02 15:58:34
【问题描述】:

我试图在卸载过程中删除一个 ODBC 条目。做这个的最好方式是什么?我有一个标准的 VS 安装项目。

【问题讨论】:

标签: c# odbc uninstallation


【解决方案1】:

还有一个

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Runtime.InteropServices;

namespace MyInstallerClassDll
{
[RunInstaller(true)]
public partial class MyInstallerClass : Installer
{
    const int ODBC_REMOVE_DSN = 3;
    public MyInstallerClass()
    {
        InitializeComponent();
    }

    public override void Uninstall(System.Collections.IDictionary savedState)
    {
        RemoveSystemDSN();
        base.Uninstall(savedState);
    }

    [DllImport("ODBCCP32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, SetLastError = true)]
    private static extern int SQLConfigDataSource(int hwndParent, int fRequest, string lpszDriver, string lpszAttributes);
    private void RemoveSystemDSN()
    {
        string vAttributes = "DSN=DSN Name" + Strings.Chr(0);
        vAttributes += "Description=DSN Description" + Strings.Chr(0);
        vAttributes += "Trusted_Connection=Yes" + Strings.Chr(0);
        vAttributes += "Server=SQLINSTANCE" + Strings.Chr(0);
        vAttributes += "Database=databasename" + Strings.Chr(0);

        if (SQLConfigDataSource(0, ODBC_REMOVE_DSN, "SQL Server", vAttributes) == 0)
        {
            MessageBox.Show("Failed to remove ODBC data source!!");
        }
    }
}
} 

【讨论】:

  • 这个安装程序类在哪里?我在我的安装项目中没有看到任何 *.cs 文件。
猜你喜欢
  • 2011-08-10
  • 2017-11-29
  • 1970-01-01
  • 2012-07-22
  • 1970-01-01
  • 2011-11-21
  • 2013-02-14
  • 2013-03-08
  • 2012-03-21
相关资源
最近更新 更多