Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i use this code in my program to copy current program to other place
but it dont work

C#
CopyFile(argv[0],L"C:\\Users\\233Amin\\Desktop",1)


Last Error code is :
...............................................
ERROR_ACCESS_DENIED

5 (0x5)

Access is denied.
...............................................
Why i should do ??
Posted
Updated 19-May-14 1:20am
v2
Comments
Richard MacCutchan 19-May-14 7:36am    
Use elevated privileges to get UAC to allow you to write into that directory.
[no name] 19-May-14 7:49am    
how i should do this?

Richard MacCutchan 19-May-14 8:12am    
Add a manifest to your project, which requests Administrator privilege, or use "Run as Administrator" to run the program.
[no name] 19-May-14 8:35am    
no it dont works
i run it as Adminstrator
Richard MacCutchan 19-May-14 8:49am    

1 solution

"to copy current program" - no, that cannot work. Your program is running, that means the executable file is being executed, it is in use. Elevation won't help you here.
 
Share this answer
 
Comments
[no name] 19-May-14 8:32am    
it means it have no way to copy this program ??
Richard MacCutchan 19-May-14 9:00am    
Interesting: I assumed that CopyFile would still be able to read it, even though the program is running.
[no name] 21-May-14 11:09am    
No. An executable file can be copied while it is being executed. You're wrong. I tested it by creating a console application which copies itself while it is being executed. OP may have any other problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900