2011-04-01 85 views
0

当调用CreateFile()函数时,它返回错误代码0x5,这意味着访问被拒绝。任何人都可以解决这个问题吗?调用CreateFile()时访问被拒绝()

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

非常感谢。

+0

什么是你新文件的位置?你是以管理员还是以用户身份运行应用程序?在Windows Vista或最近您需要提升权限才能在位置创建文件,如Program Files – 2011-04-01 09:20:09

+0

它被称为UAC;看到[我的答案在这里](http://stackoverflow.com/questions/5210575/does-windows-7-have-the-same-problem-as-vista/5210642#5210642)了解更多详情。您不应该首先写入系统文件夹。但是,如果你绝对必须,我只是写了一个关于如何在C#中提升应用程序过程的详细解释[回复此问题](http://stackoverflow.com/questions/5507818/workaround-against-registry-manipulation -limitation式 - 窗口五百五十零万八千分之七#5508000)。 – 2011-04-01 09:22:52

回答

0
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); 
0

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

0

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

0

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

+0

文件路径是\\?\ globalroot \ device \ harddiskvolumeshadowcopy33 \ program files \ common files \ microsoft shared \ web server extensions \ 12 \ admisapi – Daniel 2011-04-05 01:25:43

+0

并且如上所述,如果您尝试使用命令行将文件写入该文件。它工作吗?例如回声“测试”到它的结尾或某事 – BugFinder 2011-04-05 06:58:06