VS2005 で開発した ActiveX コントロールがあります。私はそれをVS2008に変換しました。私のコードには ComRegisterFunctionAttribute と ComUnregisterFunctionAttribute があり、作業中の XP システムでコンパイルおよびデバッグすると、すべてうまく機能します。自宅の Vista ラップトップで実行しようとすると、次のエラーが表示されます。
「アセンブリ "D:\My Documents\Visual Studio 2008 Projects\C#\BLINCodes\BLINCodes\bin\Debug\BLINCodes.dll" を登録できません - アクセスが拒否されました。管理者としてアプリケーションを実行していることを確認してください。レジストリ キー 'HKEY_CLASSES_ROOT\RTPS.BLINCodes' が拒否されました。"
新しい 64 ビット オペレーティング システムでは、DLL を登録するために管理者として実行する必要があることは理解していますが、私が行ってきた方法でプログラムでそれを行うことはできますか? コードは次のとおりです。
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\Programmable");
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\Control");
string path = System.Reflection.Assembly.GetAssembly(typeof(BLINCodes)).Location;
Microsoft.Win32.RegistryKey subkey;
subkey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\DefaultIcon");
subkey.SetValue("", path + ",102");
subkey = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\ToolBoxBitmap32");
subkey.SetValue("", path + ",102");
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\Programmable");
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\Control");
Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\ToolBoxBitmap32");
Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + t.GUID.ToString().ToUpper() + @"}\DefaultIcon");
}
すべての助けをありがとう。
んん