系统IO文件复制权限 [英] System IO File Copy Permissions

查看:104
本文介绍了系统IO文件复制权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家早上好



我正在尝试使用Vb.net程序将文件从网络文件夹复制到本地PC的根目录。



不幸的是,副本失败了:



System.UnauthorizedAccessException:访问路径''C:\\ \\ _Settings.dat''被拒绝。

在System.IO .__ Error.WinIOError(Int32 errorCode,String maybeFullPath)

在System.IO.File.InternalCopy(String SystemFileName,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



如果手动复制文件(拖放),请输入以下对话框:



你需要管理员的许可来复制这个文件夹



点击''继续''

然后



用户帐户控制 - 您是否希望以下程序对此计算机进行更改?



点击是



文件被复制。





有没有人知道我是否可以(以及如何)从vb中调用这个权限?





我的代码如下:

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.

推荐答案

说实话,我不会这样做。

对任何硬盘驱动器的根文件夹的写访问权限仅限于管理员,并且写访问权限严重不推荐启动驱动器的根文件夹。



在其他地方创建一个文件夹并将设置存储在那里,这样就不需要权限了。 />
有很多好地方可以存储这些信息:我应该在哪里存储我的数据? [ ^ ]解释其中一些。
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.


这篇关于系统IO文件复制权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆