Ste*_*tew 75 windows unc batch-file
我试图从网络共享运行批处理文件,但我不断收到以下消息:"不支持UNC路径.默认为Windows目录." 批处理文件位于\\Server\Soft\WPX5\install.bat
.以管理员身份登录后,从我的Windows 7桌面导航到\\Server\Soft\WP15\
双击install.bat,即当我得到"不支持UNC路径"时.信息.我在网上发现了一些建议说映射驱动器不起作用,但使用符号链接将解决这个问题,但符号链接对我不起作用.以下是我的批处理文件内容,我将不胜感激,可以帮助我完成我想要做的任何帮助.基本上,我希望能够从中运行批处理文件\\Server\Soft\WP15\install.bat
.
批处理文件内容
mklink /d %userprofile%\Desktop\WP15 \\server\soft\WP15
\\server\soft\WP15\setup.exe
robocopy.exe "\\server\soft\WP15\Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s \\server\soft\WPX5\Custom\Migrate.reg
Run Code Online (Sandbox Code Playgroud)
另外,如何在安装完成后删除符号链接?
dbe*_*ham 128
PUSHD和POPD应该对您的情况有所帮助.
@echo off
:: Create a temporary drive letter mapped to your UNC root location
:: and effectively CD to that location
pushd \\server\soft
:: Do your work
WP15\setup.exe
robocopy.exe "WP15\Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s WPX5\Custom\Migrate.reg
:: Remove the temporary drive letter and return to your original location
popd
Run Code Online (Sandbox Code Playgroud)
PUSHD /?
从命令行键入以获取更多信息.
Vin*_*nzz 24
有一个注册表设置,以避免此安全检查(尽管使用它自己的风险):
在注册表路径下
HKEY_CURRENT_USER
\Software
\Microsoft
\Command Processor添加值DisableUNCCheck REG_DWORD并将值设置为0 x 1(十六进制).
注意: 在Windows 10版本1803上,该设置似乎位于HKLM下:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
Gra*_*len 21
我觉得这cls
是最好的答案.它在任何人都可以看到它之前隐藏了UNC消息.我将其与之后的@pushd %~dp0
权利相结合,以便打开脚本并在一步中映射该位置,从而防止进一步的UNC问题.
cls
@pushd %~dp0
:::::::::::::::::::
:: your script code here
:::::::::::::::::::
@popd
Run Code Online (Sandbox Code Playgroud)
笔记:
pushd
将您的工作目录更改为新映射驱动器中的脚本位置.
popd
最后,清理映射的驱动器.
我需要能够只通过Windows资源管理器浏览服务器共享,然后双击启动批处理文件.@dbenham让我为我的场景提供了一个更简单的解决方案(没有popd
后顾之忧):
:: Capture UNC or mapped-drive path script was launched from
set NetPath=%~dp0
:: Assumes that setup.exe is in the same UNC path
%NetPath%setup.exe
:: Note that NetPath has a trailing backslash ("\")
robocopy.exe "%NetPath%Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s %NetPath%..\WPX5\Custom\Migrate.reg
:: I am not sure if WPX5 was typo, so use ".." for parent directory
set NetPath=
pause
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
271167 次 |
最近记录: |