0
votes

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.

4
what's the location of you new file? are you running the app as Administrator or as User? on WIndows Vista or recent you'll need to request for elevated permissions in order to create a file in locations as Program Files - Stefan P.
It's called UAC; see my answer here for more details. You shouldn't be writing to system folders in the first place. But if you absolutely have to, I just wrote up a detailed explanation of how to elevate your application's process in C# in answer to this question. - Cody Gray

4 Answers

0
votes

Can you you create that file manually? This is most probably a permission issue.

0
votes

This means that you don't have enough rights to read from this file. Check the file permissions.

0
votes

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.

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