Hi Dw
I'm creating an application that will copy a file from one directory file to System32 file but I get an access denial error and I've decided to use vb.net to call cmd.exe and send keys to it that will instruct it to copy the file but the same error occurs but if I put or copy the file let say to 'C:\test\' it will copy it but it produce error if I try to copy it to System32 so I don't know if there is anyone know how I can grant this program a permission to access this file because I'm also an administrator on this computer, here is the code I've used below:

Dim Process As New Process
Process.StartInfor.FileName = "cmd.exe"

Dim SourceFile As String = "C:\Users\MyAccount\Desktop\Test\1254.txt"

SendKeys.Send("xcopy " + SourceFile + " " + "C:\Windows\System32\" & "{enter}")

Anyone who can help please

Thank you

Recommended Answers

All 3 Replies

The System32 folder is managed by the UAC.
So in order for you to copy a file to that folder you have to use an elevated process.

If you go with the CMD.exe thing, you can elevate the process to administrator. Maybe this will help.

Dim process As New Process()
process.StartInfo.FileName = "cmd.exe "
process.StartInfo.Verb = "runas"
process.StartInfo.UseShellExecute = True
process.Start()

Another method that might help is if you use VB.NET tools only to copy the file, and run the entire project in an elevated state.

Thanks but the reason why I used cmd.exe is that I failed to do it in vb.net so because I've see when let say I'm using a computer at school where I'm not an administrator I can't copy or move files to 'c:\' drive but if I open the cmd.exe and type 'xcopy path tothefile.smthing destination' it copy it doesn't require me to be an admin because I use the command so I thought even here will be the same but not it fails the computer where I'm running at now is the computer where I'm the admin on it, so can you please help me in doing that in vb then in command thank you

Like I said. The second solution would be to use the file manipulation tools in VB.NET code, but to run the program itself as an administrator (run as).
I haven't tried it, though.
I found this article explaining how to auto-elevate a program within the bounds of the UAC: http://archive.msdn.microsoft.com/KB981778

The tools available to you are in the IO namespace.
File.Copy(), File.Move() a.s.o.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.