【问题标题】:Access denied when Called CreateFile()调用 CreateFile() 时访问被拒绝
【发布时间】:2011-04-01 09:14:35
【问题描述】:

调用 CreateFile() 函数时,它返回错误代码 0x5,表示访问被拒绝。谁能帮忙解决这个问题?

注意:CreateFile() 读取快照的路径,文件路径为\?\globalroot\device\harddiskvolumeshadowcopy35\program files\common files\microsoft shared\web server extensions\12\admisapi。

非常感谢。

【问题讨论】:

  • 新文件的位置是什么?您是以管理员身份运行应用程序还是以用户身份运行应用程序?在 WIndows Vista 或最新版本上,您需要请求提升权限才能在位置创建文件作为程序文件
  • 它叫UAC;有关详细信息,请参阅my answer here。首先,您不应该写入系统文件夹。但如果你必须这样做,我只是在answer to this question 中写了一个关于如何在 C# 中提升应用程序进程的详细说明。

标签: c# createfile


【解决方案1】:

您可以手动创建该文件吗?这很可能是权限问题。

【讨论】:

    【解决方案2】:

    这意味着您没有足够的权限来读取此文件。检查文件权限。

    【讨论】:

      【解决方案3】:

      访问被拒绝,您的应用程序在哪里尝试创建文件?如果它在程序文件等中,可能是因为它的 Windows 7 和用户在不首先提升权限的情况下无法创建它。另外,请确保它在您认为的位置创建它。

      【讨论】:

      • 文件路径为\\?\globalroot\device\harddiskvolumeshadowcopy33\program files\common files\microsoft shared\web server extensions\12\admisapi
      • 和上面一样,例如,如果您尝试使用命令行将文件写入该文件。它有效吗?例如在结尾处回显“测试”或其他内容
      【解决方案4】:
      ConnectionOptions connection = new ConnectionOptions();
      
      //just username, without domain name, otherwise, a "RPC is Unavaliable." exception will be thrown.
      connection.Username = "testUser";
      
      connection.Password = "testPassword";
      
      //Allow privilege
      connection.EnablePrivileges = true;
      
      connection.Impersonation = ImpersonationLevel.Delegate;
      
      connection.Authentication = AuthenticationLevel.Call;
      
      //Neither ntdlmdomain or kerberoes, otherwise, a "Invalid Parameter." exception will be thrown.
      connection.Authority = "ntlmdomain:MYDOMAIN";
      
      //IP Address or host full name.
      ManagementScope scope = new ManagementScope("\\\\myIPAddress\\root\\CIMV2", connection);
      
      scope.Connect();
      
      ManagementClass classInstance = new ManagementClass(scope,new ManagementPath("Win32_Process"), null);
      
      ManagementBaseObject inParams = classInstance.GetMethodParameters("Create");
      
      //Change it to your own execute file path
      inParams["CommandLine"] = "myExecuteFilePath";
      
      ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-25
        • 1970-01-01
        相关资源
        最近更新 更多