When called CreateFile() function it returns an error code 0x5, which means access denied. Can anyone help with this issue?
Note: CreateFile() reads the path of a snapshot, and the file开发者_开发知识库 path is \?\globalroot\device\harddiskvolumeshadowcopy35\program files\common files\microsoft shared\web server extensions\12\admisapi.
thanks very much.
Can you you create that file manually? This is most probably a permission issue.
This means that you don't have enough rights to read from this file. Check the file permissions.
Access denied, where is your application trying to create the file? If its in program files etc, it maybe because its windows 7 and the user cant create it without elevating the permissions first. Also, be sure its creating it where you think it is.
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);
精彩评论