この質問は何度も聞かれたと思います。しかし、私は問題に直面しています。そこで、別のクラスを作成しました。具体的には、適切なユーザー レベルが存在することを確認します。
以下は、これらのアクセス許可レベルをテストするコードです。
class Elevated_Rights
{
// Token Bool:
private bool _level = false;
#region Constructor:
protected Elevated_Rights()
{
// Invoke Method On Creation:
Elevate();
}
#endregion
public void Elevate()
{
// Get Identity:
WindowsIdentity user = WindowsIdentity.GetCurrent();
// Set Principal
WindowsPrincipal role = new WindowsPrincipal(user);
#region Test Operating System for UAC:
if (Environment.OSVersion.Platform != PlatformID.Win32NT || Environment.OSVersion.Version.Major < 6)
{
// False:
_level = false;
// Todo: Exception/ Exception Log
}
#endregion
else
{
#region Test Identity Not Null:
if (user == null)
{
// False:
_level = false;
// Todo: "Exception Log / Exception"
}
#endregion
else
{
#region Ensure Security Role:
if (!(role.IsInRole(WindowsBuiltInRole.Administrator)))
{
// False:
_level = false;
// Todo: "Exception Log / Exception"
}
else
{
// True:
_level = true;
}
#endregion
} // Nested Else 'Close'
} // Initial Else 'Close'
} // End of Class.
}
その部分は意図したとおりに機能しています。ただし、このクラスを別のクラスに継承して保護されたコンストラクターを利用すると、問題が発生します。
class Default_Configuration : Elevated_Rights
{
#region Constructor:
public Default_Configuration() : base()
{
Elevate();
}
#endregion
}
しかし、その新しいクラスを呼び出すと; メソッドは次のように述べています:「コンストラクターのアクセス許可による無効なアクセス」。理論的には機能するはずです。私が欠けているものはありますか?どんな助けでも大歓迎です。