标签:BAT log %% VBS PC window ISO rem copy
背景:由于公司各城市之间带宽限制,无法进行同一站点的文件复制,会造成网络拥堵,因此通过IP判断指向各个站点文件服务器进行局域网复制
#如果生产环境允许通过修改DNS,将路径指向FileSever会更加方便,判断IP的方式将不再需要,因为PC会自动寻找最近的FileSever
前期部署准备:
为了尽可能对用户产生最小的影响,前期先将ISO文件复制到用户PC中
BAT复制文件过程中黑框仅可通过VBS调用BAT实现隐藏
VBS:
set ws=wscript.createobject("wscript.shell")
set fso = Wscript.CreateObject("Scripting.FileSystemObject")
if (not fso.FolderExists("Foldername")) then
fso.CreateFolder("Foldername")
end if
sourcefilepath="sourceFoldername\copy.bat"
desfilepath="Foldername\copy.bat"
fso.copyfile sourcefilepath,desfilepath
Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c CFoldername\test.bat",0
WS.RUN参数:https://www.vbsedit.com/html/6f28899c-d653-4555-8a59-49640b0e32ea.asp
0 | Hides the window and activates another window. |
1 | Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time. |
2 | Activates the window and displays it as a minimized window. |
3 | Activates the window and displays it as a maximized window. |
4 | Displays a window in its most recent size and position. The active window remains active. |
5 | Activates the window and displays it in its current size and position. |
6 | Minimizes the specified window and activates the next top-level window in the Z order. |
7 | Displays the window as a minimized window. The active window remains active. |
8 | Displays the window in its current state. The active window remains active. |
9 | Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window. |
10 | Sets the show-state based on the state of the program that started the application. |
BAT:
@echo off
setlocal enabledelayedexpansion
rem "check log(防止用户重复Copy文件占用带宽,中断无Log也会copy)"
if exist \\SERVER\log\success\"%computername%".txt (
exit
)
rem "check log(检测上次copy失败重新copy)"
if exist \\SERVER\log\failed\"%computername%".txt (
del \\SERVER\log\failed\"%computername%".txt
)
rem "check IP(截取IP前X位并判断)"
for /f "tokens=2 delims=:" %%i in ('ipconfig^|findstr "IPv4"') do (
set ip=%%i
if "!ip:~1,3!" equ "192" goto testip
)
:testip
if "%ip:~1,10%" equ "192.168.46" goto :testa
if "%ip:~1,10%" equ "192.169.47" goto :testb
rem "Else(其余检测范围外IP)"
xcopy \\SERVER1\ISO D:\ISO\ /E /Y
goto log
:testa
xcopy \\SERVER2\ISO D:\ISO\ /E /Y
goto log
:testb
xcopy \\SERVER3\ISO D:\ISO\ /E /Y
:log
rem "created log(获取计算机名,复制文件的哈希值并比对,原哈希值写在脚本中更快)"
for /F %%i in ('hostname') do ( set hostname=%%i)
for /f "skip=1 delims=" %%i in ('CertUtil -hashfile D:\ISO\TEST.iso') do (
set hash=%%i
goto recheck
)
rem "recheck(对比哈希值,copy预先放在文件夹内SCCM快捷方式复制到桌面,方便用户确认copy完成和点击)"
:recheck
if %hash% equ 28c1df6b026e52089ad5209988de2f3ccb73d8207 (
echo successful copyed > \\SERVER\log\success\"%hostname%".txt
cd /d D:\ISO
copy "*.lnk" "C:\Users\Public\Desktop\Software Center.lnk"
)
if not %hash% equ 28c1df6b026e52089ad5209988de2f3ccb73d8207 echo fail copyed > \\SERVER\log\failed\"%hostname%".txt
exit
标签:BAT,log,%%,VBS,PC,window,ISO,rem,copy 来源: https://blog.csdn.net/weixin_57323573/article/details/116299541
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。