Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C# VB.NET
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
good
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[^]
  Permalink  
Comments
alcitect at 10-Jan-13 5:59am
   
thank you for answer, let me read your project
alcitect at 10-Jan-13 6:00am
   
thanks for your help but it not help me. thanks
Rate this: bad
good
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.
  Permalink  
Comments
alcitect at 10-Jan-13 6:03am
   
yes that may be work. but i want to run this application on many computers.
thanks for help.
tiggerc at 10-Jan-13 6:05am
   
you could set the run as administrator in the application shortcut.
alcitect at 10-Jan-13 6:17am
   
can you show this for me pleas?
thanks
tiggerc at 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 at 10-Jan-13 7:10am
   
did this work for you? if it did can you mark as solution.
alcitect at 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
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 345
2 CPallini 200
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,028
2 CPallini 4,700
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 10 Jan 2013
Copyright © CodeProject, 1999-2014
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