我試圖在卸載期間刪除ODBC條目。做這個的最好方式是什麼?我有一個標準的VS安裝項目。C#:卸載時的自定義操作
3
A
回答
2
一個更
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!!");
}
}
}
}
相關問題
- 1. 卸載自定義操作
- 2. 安裝自定義操作上卸載
- 3. 僅在卸載時使用Wix自定義操作
- 4. 自定義操作失敗時取消卸載wix
- 5. 僅在卸載時觸發自定義操作
- 6. 僅在安裝或卸載時執行自定義操作
- 7. 在卸載修補程序時運行自定義操作
- 8. 無法在卸載時運行託管自定義操作
- 9. 自定義操作在卸載期間不起作用
- 10. 觸發通過InstallScript卸載的自定義操作的區域
- 11. 微星卸載Wix之前的自定義操作
- 12. Wix - 從控制面板卸載的自定義操作
- 13. 在卸載過程中未執行的自定義操作
- 14. 錯誤在卸載中的自定義操作
- 15. 卸載期間WIX中的自定義操作
- 16. 上卸載自定義操作(的ClickOnce) - 使用ClickOnce安裝.NET
- 17. 的InstallShield執行卸載自定義操作
- 18. 如何回滾自定義操作中的卸載?
- 19. 自定義卸載行動c#
- 20. c#自定義卸載程序
- 21. InstallShield - 軟件卸載例程中缺少自定義操作
- 22. 防止修補程序卸載自定義操作
- 23. 使用自定義操作卸載多個產品
- 24. 卸載不會始終調用自定義操作
- 25. 如何刪除卸載時的自定義操作二進制文件?
- 26. 卸載時自定義windows窗體
- 27. WIX C++自定義操作
- 28. InstallShield LE:自定義卸載
- 29. 如何僅在安裝時執行自定義操作(而不是卸載)
- 30. 來自C#自定義操作的MsiSetProperty
看看http://stackoverflow.com/questions/334939/how-do-i-create-an-odbc-dsn-entry-using-c – volody 2010-06-11 13:14:20