我得到一个意外的&#34;访问被拒绝&#34;错误通过NET SHARE <share> /DELETE
删除共享,但仅在将最后一个映射取消映射到共享后立即执行,并且仅在作为普通(非提升)用户运行时执行。
我很欣赏(非Powershell)解决方案的建议,或者对正在发生的事情或者至少是一些同情的暗示。我试图在单元测试的环境中完成这项工作,该测试将在其他人的持续集成环境中运行,不要对Windows平台做出太多假设。
使用以下命令行运行脚本(下面):
> testbat
观察失败:
+> if NOT . == . sleep
+> net share uncpushd_test_cwd /delete
System error 5 has occurred.
Access is denied.
+> net share uncpushd_test_cd1 /delete
System error 5 has occurred.
Access is denied.
以魔法延迟(根据经验确定为11但不是10秒)运行
> testbatch 11
观察它有效:
+> if NOT .11 == . sleep 11
+> net share uncpushd_test_cwd /delete
uncpushd_test_cwd was deleted successfully.
+> net share uncpushd_test_cd1 /delete
uncpushd_test_cd1 was deleted successfully.
还有一个测试,运行带有 no 延迟的脚本,但是从提升的命令提示符开始。观察它有效!每一次!
这是整个剧本:
net share uncpushd_test_cwd=%TEMP%\pytest-of-bobhy\pytest-0\uncpushd
net use y: \\localhost\uncpushd_test_cwd /persistent:no
net share uncpushd_test_cd1=%TEMP%\pytest-of-bobhy\pytest-0\uncpushd\cdtest1
net use w: \\localhost\uncpushd_test_cd1
dir /s y:
dir /s w:
net use y: /delete
net use w: /delete
if NOT .%1==. sleep %1
net share uncpushd_test_cwd /delete
net share uncpushd_test_cd1 /delete