0

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.

Daniel
  • 45
  • 2
  • 11
  • 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. Apr 01 '11 at 09:20
  • It's called UAC; see [my answer here](http://stackoverflow.com/questions/5210575/does-windows-7-have-the-same-problem-as-vista/5210642#5210642) 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](http://stackoverflow.com/questions/5507818/workaround-against-registry-manipulation-limitation-in-windows-7/5508000#5508000). – Cody Gray - on strike Apr 01 '11 at 09:22

4 Answers4

0

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

Shamit Verma
  • 3,839
  • 23
  • 22
0

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

maverik
  • 5,508
  • 3
  • 35
  • 55
0

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.

BugFinder
  • 17,474
  • 4
  • 36
  • 51
  • the file path is \\?\globalroot\device\harddiskvolumeshadowcopy33\program files\common files\microsoft shared\web server extensions\12\admisapi – Daniel Apr 05 '11 at 01:25
  • and as above, if you try write the file to that using the command line for example. Does it work? eg echo "test" to the end of it or something – BugFinder Apr 05 '11 at 06:58
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);
bstpierre
  • 30,042
  • 15
  • 70
  • 103
Daniel
  • 45
  • 2
  • 11