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.