使用“低完整性级别”时,Semaphore ctor在Windows 8 x64中失败

时间:2012-10-26 14:49:39

标签: c# .net .net-4.0 windows-8 .net-4.5

我正在尝试使用.Net 4.0 / 4.5在Windows 8 x64的桌面应用程序中创建/打开一个名为Semaphore的低完整性级别。

相同的代码适用于Windows 7 x64,但在带有System.IO.IOException的Windows 8 Entreprise x64上失败:“客户端不保留所需的权限”。

代码如下(控制台应用程序):

class Program
{
   static void Main(string[] args)
   {
      System.Security.AccessControl.SemaphoreSecurity sec = null;

      //[low integrity level[
      sec = new System.Security.AccessControl.SemaphoreSecurity();
      sec.SetSecurityDescriptorSddlForm("S:(ML;;NW;;;LW)");
      //]low integrity level]

      try
      {
         bool createdNew;
         var sem = new System.Threading.Semaphore(0, int.MaxValue, "MySemaphoreName", out createdNew, sec);
         if (createdNew) { Console.WriteLine("Semaphore created"); }
         else            { Console.WriteLine("Semaphore opened"); }
      }
      catch (Exception ex)
      {
         Console.WriteLine("Exception occured {0}", ex);
      }
      ConsoleKeyInfo cki = Console.ReadKey();
   }
}

在删除以下块时,它适用于两个系统:

sec = new System.Security.AccessControl.SemaphoreSecurity();
sec.SetSecurityDescriptorSddlForm("S:(ML;;NW;;;LW)");

欢迎任何帮助。

0 个答案:

没有答案