判断不同IP段,预先由服务器复制文件到用户PC VBS+BAT(Windwos升级映像部署1 )

背景:由于公司各城市之间带宽限制,无法进行同一站点的文件复制,会造成网络拥堵,因此通过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

 

 

上一篇:linux_19


下一篇:【工具干货】CentOS 8 镜像安装,设置Installation Source