Click here to Skip to main content
13,086,662 members (55,405 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi Guys
can any one help me to know how to Copy a file to Drive "C:\" if we know this drive contain the Operating system "Win7".

i Use this code:
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Integer) As Integer
copyfile(strSource, strDest,True)

It work if run the program as administrator. Is there another way to do that??
Posted 9-Jan-13 21:52pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

No there is not, this is a restriction of the operating system which will not allow you to copy files to sensitive areas on disk.

You can however run your code as an administrator when needed see here : RunAs Class[^]
alcitect 10-Jan-13 5:59am
thank you for answer, let me read your project
alcitect 10-Jan-13 6:00am
thanks for your help but it not help me. thanks
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You can get around this by setting your UAC to none,

Control Panel -> user Accounts -> UAC drag the slider to the bottom.
alcitect 10-Jan-13 6:03am
yes that may be work. but i want to run this application on many computers.
thanks for help.
tiggerc 10-Jan-13 6:05am
you could set the run as administrator in the application shortcut.
alcitect 10-Jan-13 6:17am
can you show this for me pleas?
tiggerc 10-Jan-13 6:20am
Create a shortcut to the application.
Right click on the shortcut, select properties
go to the compatability tab
select run this program as administrator.

if there is a button change settings for all users click that and check the box run as administrator.

click ok a couple of times, all should work.
tiggerc 10-Jan-13 7:10am
did this work for you? if it did can you mark as solution.
alcitect 13-Jan-13 0:17am
that will work but I want to do this using code.
thanks for your answer.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100