ยินดีต้อนรับ สู่ Thailand Generating Batch Scripts

Blogger นี้จัดทำขึ้นมาเพื่อแบ่งปัน Batch Scripts ที่ผู้เขียนได้จัดทำขึ้นเพื่อใช้ในงานต่างๆ ทั้งการจัดการให้ระบบ Computer สามารถทำงานได้ด้วยความถูกต้อง

พร้อมทั้งเพิ่มความสะดวก สำหรับการจัดการดูแลรวมถึงการประยุกต์ใช้งานต่างๆได้ หวังเพียงให้โลกของเรามีการแบ่งปันเอื้อเฟื้อซึ่งกันและกัน ขอให้ประโยชน์สุขก์จงเกิดแก่มนุษย์โลกทุกท่าน

(เพื่อต่อยอดให้เกิดการแบ่งปันแก่มนุษย์โลกสืบต่อไป)

วันจันทร์ที่ 15 กันยายน พ.ศ. 2557

Count Character in line

@echo off &setLocal EnableDelayedExpansion
set _cha=\
set _input=net use L: "\\abcde\fxtest$\test-dasfadsfiii"
set _str1=%_input: =%
set _str2=%_str1:"=%
call :cntchar %_str2%
echo Number of all Charactor = %n%
echo Number of "!_cha!" = %x%
set _str=_%_str2%
for /l %%a in (1,1,%n%) do (
call set _chx=%%_str:~%%a,1%%
call echo %%a !_chx!
)
endlocal
exit /b

:cntchar
set _strx=%1
set i=-1
set n=0
set x=0
:nextChar
    set /a i+=1
    set c=!_strx:~%i%,1!
    if "!c!"=="" goto endLine
    if "!c!"=="!_cha!" set /a x+=1
    set /a n+=1
    goto nextChar
:endLine
goto:eof

Get Date Time With Leapyear

:gdatetime
if exist "%Temp%.\getdate.vbs" del /q /f "%Temp%.\getdate.vbs"
> "%Temp%.\getdate.vbs" echo Dim dt
>>"%Temp%.\getdate.vbs" echo dt=now
>>"%Temp%.\getdate.vbs" echo 'output format: yyyymmddHHnnss
>>"%Temp%.\getdate.vbs" echo Wscript.echo  ((((Year(dt)*100 + Month(dt))*100 + Day(dt))*100 + Hour(dt))*100 + Minute(dt))*100 + Second(dt)
For /f %%g in ('cscript /nologo "%Temp%.\getdate.vbs"') do set _dtm=%%g
set _yyyy=%_dtm:~0,4%
set _mm=%_dtm:~4,2%
set _dd=%_dtm:~6,2%
set _hh=%_dtm:~8,2%
set _nn=%_dtm:~10,2%
set _ss=%_dtm:~12,2%
set /a leapyear=((!(%_yyyy%%%400))^|!(!(%_yyyy%%%100)))^&!(%_yyyy%%%4)
set _mx=31
for %%i in (04,06,09,11) do if %_mm%==%%i set _mx=30
if %_mm%==02 set _mx=28
if %_mm%==02 if %leapyear%==1 set _mx=29
del /q /f "%Temp%.\getdate.vbs"
goto:eof

วันอาทิตย์ที่ 14 กันยายน พ.ศ. 2557

MAPDrives SCripts With Show Drive Letters First and Rename Drive Label with ShareName

:: START SCRIPTS ::
@echo off&setLocal EnableDelayedExpansion
:: All Drive L,M,N,O,P,Q,R,S,T,U,V,W,X,Y
:: Set your Drive Need to Map Drive
set _drivemap=n,s,t,u,w,x,y
call :sharepth1
set _maplist=%Temp%\sharepath1.txt
:stmap
:: Remove All Map drives
net use * /delete /y >nul
:: Show Drive Letters First
set _hkcuexp=HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer
call :shwdir1
:: Map Drive and Rename Drive Label
for /f "tokens=1,2 delims=:" %%a in (!_maplist!) do (
set _uncpth=%%b
set _str=!_uncpth: =!
set _regpth=!_uncpth:\=#!
set _labelpth="%_hkcuexp%\MountPoints2\!_regpth!"
call :cntchar !_str!
for %%i in (!_drivemap!) do (
if /i %%a==%%i net use %%a: "!_uncpth!">nul
if /i %%a==%%i call set _sname=%%_str:~!_lch!%%
if /i %%a==%%i reg add !_labelpth! /v _LabelFromReg /t REG_SZ /d "!_sname!" /f>nul
)
)
del /q /f !_maplist!
exit /b

:shwdir1
set _dchk=0
for /f "Tokens=*" %%i in ('reg query %_hkcuexp% ^|FIND /I /C "ShowDriveLettersFirst"') do set _dchk=%%i
if %_dchk%==0 reg add %_hkcuexp% /v ShowDriveLettersFirst /t REG_DWORD /d 00000004>nul
goto:eof

:cntchar
set _strx=%1
set _cha=\
set i=-1
set n=0
:nextchar
    set /a i+=1
    set c=!_strx:~%i%,1!
    if "!c!"=="" goto endline
        set /a n+=1
    if "!c!"=="!_cha!" set _lch=!n!
    goto nextchar
:endline
goto:eof

:: END SCRIPTS ::

:sharepth1
>"%temp%\sharepath1.txt" echo L:\\<SHARE_SERVER1>\<SHARE_PATH1>
>>"%temp%\sharepath1.txt" echo M:\\<SHARE_SERVER1>\<SHARE_PATH2>
>>"%temp%\sharepath1.txt" echo N:\\<SHARE_SERVER1>\<SHARE_PATH3>
>>"%temp%\sharepath1.txt" echo O:\\<SHARE_SERVER1>\<SHARE_PATH4>
>>"%temp%\sharepath1.txt" echo P:\\<SHARE_SERVER1>\<SHARE_PATH5>
>>"%temp%\sharepath1.txt" echo Q:\\<SHARE_SERVER1>\<SHARE_PATH6>
>>"%temp%\sharepath1.txt" echo R:\\<SHARE_SERVER2>\<SHARE_PATH7>
>>"%temp%\sharepath1.txt" echo S:\\<SHARE_SERVER2>\<SHARE_PATH8>
>>"%temp%\sharepath1.txt" echo T:\\<SHARE_SERVER2>\<SHARE_PATH9>
>>"%temp%\sharepath1.txt" echo U:\\<SHARE_SERVER2>\<SHARE_PATH10>
>>"%temp%\sharepath1.txt" echo V:\\<SHARE_SERVER2>\<SHARE_PATH11>
>>"%temp%\sharepath1.txt" echo W:\\<SHARE_SERVER3>\<SHARE_PATH12>
>>"%temp%\sharepath1.txt" echo X:\\<SHARE_SERVER3>\<SHARE_PATH13>
>>"%temp%\sharepath1.txt" echo Y:\\<SHARE_SERVER3>\<SHARE_PATH14>
goto:eof

ผู้ติดตาม