¡¡¤»¤Ã¤«¤¯¤Ë¤ã¤Î¤Çʸ»ú¥³¡¼¥ÉÊÑ´¹¤Î¤â¥á¥â¡£
@echo off
rem %0 euc2unicode in_file out_file
if "%~3"=="" @echo ERR %0 %*
if "%~3"=="" goto :EOF
setlocal
set res=0
if "%~1"=="euc2unicode" call :euc2unicode "%~2" "%~3" & set res=1
if "%~1"=="sjis2unicode" call :sjis2unicode "%~2" "%~3" & set res=1
if "%~1"=="utf82unicode" call :utf82unicode "%~2" "%~3" & set res=1
if "%~1"=="unicode2euc" call :unicode2euc "%~2" "%~3" & set res=1
if "%~1"=="unicode2sjis" call :unicode2sjis "%~2" "%~3" & set res=1
if "%~1"=="unicode2utf8" call :unicode2utf8 "%~2" "%~3" & set res=1
if "%res%"=="1" goto :EOF
@echo ERR %0 %*
endlocal
goto :EOF
:euc2unicode
start /min /wait cmd /c chcp.com 20932 ^& ^( set /p x="ÿþ"^<nul ^& cmd
/u /c type %1 ^) ^>%2
exit /b
:sjis2unicode
( set /p x="ÿþ"<nul & cmd /u /c type %1 ) >%2
exit /b
:utf82unicode
start /min /wait cmd /c chcp.com 65001 ^& ^( set /p x="ÿþ"^<nul ^& cmd
/u /c type %1 ^) ^>%2
exit /b
:unicode2euc
start /min /wait cmd /c chcp.com 20932 ^& cmd /c type %1 ^>%2
exit /b
:unicode2sjis
type %1 >%2
exit /b
:unicode2utf8
start /min /wait cmd /c chcp.com 65001 ^& cmd /c type %1 ^>%2
exit /b
¡¡¤¢¤¡¤¦¤ó¡¢¤â¤¦¤Á¤ç¤Ã¤È¥¹¥Þ¡¼¥È¤Ë¤ã¹½Â¤¤Ë½ÐÍè¤Þ¤¹¤Í¡¢µ¤¤Ë¤·¤Ë¤ã¤¤¡£
¡¡¤»¤Ã¤«¤¯¤Ë¤ã¤Î¤Çbat¤Ç½ñ¤¤¤Æ¤ß¤¿¥Ç¥â¡£
¡¡AD¤Î¥æ¡¼¥¶¤Î¥×¥í¥Ñ¥Æ¥£¤Ç¡¢¥À¥¤¥ä¥ë¥¤¥ó¤ÎÀÅŪIP¥¢¥É¥ì¥¹¤ò³ä¤êÅö¤Æ¤òÀßÄê
@echo off
rem (add) %0 "CN=user1,OU=ou1,OU=ou2,DC=dom,DC=local" 123.123.123.123
rem (mod) %0 "CN=user1,OU=ou1,OU=ou2,DC=dom,DC=local" 123.123.123.123
rem (del) %0 "CN=user1,OU=ou1,OU=ou2,DC=dom,DC=local"
set dn="%~1"
set ip=%~2
if %dn%=="" (@echo ERR1 : %0 %* & pause & exit)
call :chk_dn %dn%
@echo dn ok
if "%ip%"=="" call :mode_del
if not "%ip%"=="" call :mode_edit
goto :EOF
:mode_del
call :attr_del %dn% "msRADIUSFramedIPAddress"
call :attr_del %dn% "msRASSavedFramedIPAddress"
exit /b
:mode_edit
setlocal
call :ip2dec ip_dec %ip%
echo %ip% = %ip_dec%
call :attr_edit %dn% "msRADIUSFramedIPAddress" "%ip_dec%"
call :attr_edit %dn% "msRASSavedFramedIPAddress" "%ip_dec%"
endlocal
exit /b
:chk_dn
ldifde -u -d %1 -r "(objectClass=user)" -f out.tmp || goto :chk_err %*
ldifde -u -d %1 -r "(objectClass=user)" -f out.tmp | find "1¸Ä¤Î¥¨¥ó¥È¥ê¤¬¥¨¥¯¥¹¥Ý¡¼¥È¤µ¤ì¤Þ¤·¤¿" >NUL || goto :chk_err %*
type out.tmp | find %dn% >NUL || goto :chk_err %*
del out.tmp
exit /b
:chk_err
echo ERR2 %0 %*
pause
exit
:attr_edit
setlocal
set dn="%~1"
set attr="%~2"
set var="%~3"
call :is_exist_attr flag %dn% %attr%
if "%flag%"=="0" call :create_import_file_add %dn% %attr% %var% > tmp.txt
if "%flag%"=="1" call :create_import_file_modify %dn% %attr% %var% > tmp.txt
type tmp.txt || pause
call conv.cmd sjis2unicode tmp.txt tmp_u.txt
del tmp.txt
ldifde -u -i -f tmp_u.txt || (@echo ERR3 %0 %* & pause)
del tmp_u.txt
endlocal
exit /b
:attr_del
setlocal
set dn="%~1"
set attr="%~2"
call :is_exist_attr flag %dn% %attr%
if "%flag%"=="0" exit /b
if "%flag%"=="1" call :create_import_file_delete %dn% %attr% > tmp.txt
type tmp.txt || pause
call conv.cmd sjis2unicode tmp.txt tmp_u.txt
del tmp.txt
ldifde -u -i -f tmp_u.txt || (@echo ERR4 %0 %* & pause)
del tmp_u.txt
endlocal
exit /b
:create_import_file_add
@echo off
if "%~3"=="" (@echo ERR5 %0 %* & pause)
echo.|set /p x=dn: %~1
echo.
echo.|set /p x=changetype: modify
echo.
echo.|set /p x=add: %~2
echo.
echo.|set /p x=%~2: %~3
echo.
echo.|set /p x=-
echo.
exit /b
:create_import_file_modify
@echo off
if "%~3"=="" (@echo ERR6 %0 %* & pause)
echo.|set /p x=dn: %~1
echo.
echo.|set /p x=changetype: modify
echo.
echo.|set /p x=replace: %~2
echo.
echo.|set /p x=%~2: %~3
echo.
echo.|set /p x=-
echo.
exit /b
:create_import_file_delete
@echo off
if "%~2"=="" (@echo ERR7 %0 %* & pause)
echo.|set /p x=dn: %~1
echo.
echo.|set /p x=changetype: modify
echo.
echo.|set /p x=delete: %~2
echo.
echo.|set /p x=-
echo.
exit /b
:is_exist_attr
setlocal
set res=0
set dn=%2
set attr=%3
ldifde -u -d %dn% -l %attr% -f out.tmp >NUL
type out.tmp | find %attr% >NUL && set res=1
del out.tmp
endlocal & set %1=%res%
exit /b
:hex2dec
rem call :hex2dec var ffffffff
echo.|set /p x=Wscript.Echo ^^^&H%~2>tmp.vbs
echo.>>tmp.vbs
for /f "usebackq delims=" %%a in (`cscript //nologo tmp.vbs`) do set %1=%%a
del tmp.vbs
exit /b
:dec2hex
rem call :dec2hex var 123456
echo.|set /p x=Wscript.Echo Hex(%~2)>tmp.vbs
echo.>>tmp.vbs
for /f "usebackq delims=" %%a in (`cscript //nologo tmp.vbs`) do set %1=%%a
del tmp.vbs
exit /b
:format_dec
rem call :%0 var 4 99 -> var=0099
setlocal
set x=00000000000000000000000000000000000000000000000000%3
rem call echo %%x:~-^%2%%
call set ans=%%x:~-^%2%%
endlocal & set %1=%ans%
exit /b
:split_ip4
rem call %0 var1 var2 var3 var4 123.123.123.123
for /f "tokens=1,2,3,4 delims=." %%a in ("%~5") do set %1=%%a & set
%2=%%b & set %3=%%c & set %4=%%d
exit /b
:ip2dec
setlocal
rem call %0 var 10.1.0.255
set ip=%~2
call :split_ip4 var1 var2 var3 var4 %ip%
rem echo %var1% %var2% %var3% %var4%
call :dec2hex hvar1 %var1%
call :dec2hex hvar2 %var2%
call :dec2hex hvar3 %var3%
call :dec2hex hvar4 %var4%
rem echo %hvar1% %hvar2% %hvar3% %hvar4%
call :format_dec hvar1 2 %hvar1%
call :format_dec hvar2 2 %hvar2%
call :format_dec hvar3 2 %hvar3%
call :format_dec hvar4 2 %hvar4%
rem echo %hvar1% %hvar2% %hvar3% %hvar4%
call :hex2dec var %hvar1%%hvar2%%hvar3%%hvar4%
rem echo %var%
endlocal & set %1=%var%
exit /b
¡¡setlocalŪ¤Ë¤ãÉôʬ¤È¤«¥¨¥é¡¼¥Á¥§¥Ã¥¯¤Ï¤¤¤¤²Ã¸º¤Ë¤ã¤Î¤Ç¡¢½½Ê¬¥Æ¥¹¥È¤·¤Æ¤ª¤«¤Ë¤ã¤¤¤ÈAD¤Î¥Ç¡¼¥¿Á´ÌǤȤ«¤Ë¤ã¤êÆÀ¤ë½ê¤¬Éݤ¤¤Í
¡¡ip¤ò4¤Ä¶èÀÚ¤ê¤Ç»ØÄꤹ¤ë¤Èdword¤Ë¤ãint¤Ë¤·¤Æ½ñ¤¹þ¤ß¤ß¤¿¤¤¤Ë¤ã¤³¤È¤ò¤·¤Æ¤ë¤±¤É¡¢¤«¤Ë¤ã¤êȿ§µ¤Ì£¡£
¡¡¤¢¤Èº£²ó¤Ï´Ø·¸¤Ë¤ã¤¤¤ó¤À¤±¤ÉÆüËܸì´ØÏ¢¤Çunicode¤Ç½Ð¤·Æþ¤ì¤·¤¿¤Û¤¦¤¬¤¤¤¤¤Î¤Ç¡¢unicodeÊÑ´¹¤È¤«¸Æ¤ó¤Ç¤Þ¤¹¡£
¡¡
¡¡¤Ç¡¢¤³¤³¤Þ¤Ç¤·¤È¤¤¤Æ²¿¤À¤±¤É¡¢vbs¤ÇGetObject("LDAP://¡Á¡Á)¤·¤¿¤Û¤¦¤¬³Ú¤À¤Í¤³¤ì¤Ï(¾Ð)