Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET
Good morning everyone
 
I am attempting to copy a file from a network folder to the local pc's root directory using a Vb.net program.
 
Unfortunately the copy fails with :
 
System.UnauthorizedAccessException: Access to the path 'C:\Settings.dat' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
at System.IO.File.Copy(String sourceFileName, String destFileName)
at HVT_PC_Setup.frm_Setup.CopyFiles() in C:\Users\Darrell\Documents\Client Development\HVT\DB & Applications\VB2010\HVT_PC_Setup\HVT_PC_Setup\frm_Setup.vb:line 64
 
If I copy the file manually (Drag and Drop) get dialog boxes stating :
 
You'll need administraor permission to copy this folder
 
Click on 'Continue'
and then

User Account Control - Do you want the following program to make changes to this computer?
 
Click YES
 
File gets copied.
 

Does anyone know if I can (and how) invoke this 'Permission"? from within vb?
 

My code is as follows :
Imports System.IO.File
 

  Private Sub CopyFiles()
        Dim FileToCopy As String
        Dim NewCopy As String
 
        FileToCopy = "\\zeus\DB\Installation Files\Settings.dat"
        NewCopy = "C:\Settings.dat"
 
        If System.IO.File.Exists(FileToCopy) = True Then
            Try
                System.IO.File.Copy(FileToCopy, NewCopy)
                MsgBox("File Copied")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
 
    End Sub
 
 
Any assistance would as usual be much appreciated.
Posted 11-Mar-13 1:38am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To be honest, I wouldn't do that.
Write access to the root folder of any hard drive is restricted to Admin only, and write access to the root folder of the boot drive is seriously not recommended.
 
Create a folder somewhere else and store your settings there so that it doesn't require permissions.
There are quite a few good places to store this info: Where should I store my data?[^] explains some of them.
  Permalink  
Comments
Darrell de Wet at 11-Mar-13 6:57am
   
Of course - I read your article and it makes perfectly good sense.
Sometimes I cannot quite see further than my nose.
Thanks for the advice
OriginalGriff at 11-Mar-13 7:01am
   
You're welcome!

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

  Print Answers RSS
0 OriginalGriff 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 11 Mar 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