2016年6月13日 星期一

Connect NetDisk And Copy to NetDisk

描述:使用Windows排程複製資料到網路磁碟機。使用執行帳號登入home目錄。設定排程時就會要求輸入帳號密碼。


@echo off
call:getlocaltime LogFileTime
set "LogFileNameStd=D:\bklog\%LogFileTime%.stdout.log"
set "LogFileNameErr=D:\bklog\%LogFileTime%.err.log"
set "DriveName=R:"
set "REMOTEBCKPATH=\\nas\home"

rem net use %DriveName% /delete /y 1>> %LogFileNameStd% 2>> %LogFileNameErr%
echo "connect netdisk..." 1>> %LogFileNameStd% 2>>%LogFileNameErr

net use %DriveName% %REMOTEBCKPATH% /persistent:no 1>> %LogFileNameStd% 2>>%LogFileNameErr%
net use 1>> %LogFileNameStd% 2>>%LogFileNameErr%

dir %DriveName% 1>> %LogFileNameStd% 2>>%LogFileNameErr%
echo "copying data..." 1>> %LogFileNameStd% 2>>%LogFileNameErr%
copy logTEST.txt %DriveName% 1>> %LogFileNameStd% 2>>%LogFileNameErr%


goto:eof

::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:getlocaltime
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set "%~1=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%_%ldt:~8,2%%ldt:~10,2%%ldt:~12,6%"
goto:eof

沒有留言: