Nant - 如何检查用户是否具有对特定文件夹的写入权限。

时间:2009-07-28 15:21:21

标签: nant

我想测试我的脚本是否可以使用Nant访问特定的文件共享。所以我开始通过在该共享上执行简单的文件复制来检查这一点。这工作正常,但是当共享没有写入权限时,脚本崩溃,即使我有一个try-catch,但错误:

System.UnauthorizedAccessException: Access to the path '\\mypc\testsharefolder\systemaccesscheck.txt' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)*

请向我建议解决此问题的方法,或建议脚本检查访问权限。

`<target name="test.target">
 <echo>start of try catch block</echo>
<trycatch>
<try>
<copy file="c:\systemaccesscheck.txt" todir="\\mypc\testsharefolder" overwrite="true"/>
<echo>filecopy passed</echo>
</try>
<catch property="failure">
<echo>inside catch block because of failure</echo>
</catch>
</trycatch>
<echo>End of try catch block</echo>`

1 个答案:

答案 0 :(得分:0)

找出用于运行NAnt脚本的用户帐户,然后检查该用户帐户是否对您尝试复制到的目标文件夹具有权限。

您甚至可以尝试使用该帐户登录PC并手动尝试在目标文件夹中创建新的文本文件。

希望这有帮助。