@echo off title %~nx0 REM ##################################### REM ### MENU REM ##################################### :MENU set menu= cls echo: echo ============================================================== echo ********* 操作を選択シテクダサイ ********* echo ============================================================== echo: echo *** 1 : ログオンとネットワークドライブの割り当て *** echo: echo *** 2 : ネットワークドライブ or ログオン状態 の解除 *** echo: echo *** 3 : 現在のログオン状態を表示 *** echo: echo * 99 : 終了する echo ============================================================== echo: set /p menu= [1,2,3,99] : echo: if "%menu%"=="99" GOTO END if "%menu%"=="1" GOTO LOGON if "%menu%"=="2" GOTO LOGOFF if "%menu%"=="3" GOTO PRE_MENU GOTO MENU REM ##################################### REM ### 1. NET USE * ### REM ##################################### :PRE_MENU cls echo: echo ============================================================== echo *** net view echo ============================================================== for /f "tokens=1,1-3" %%x in ('net view ^| findstr /l \\') do echo * %%x -- %%y %%z REM net view | findstr /l \\ echo ============================================================== echo *** 現在のネットワークドライブとログオン状態 echo ============================================================== echo: set netuse= set netd= net use | findstr エントリが存在しません >nul && set netuse=none if "%netuse%"=="none" GOTO NO_LOGON if not "%netuse%"=="none" net use | findstr : >nul || set netd=none for /f "usebackq tokens=2,2-3 delims= " %%x in (`net use ^| findstr : ^| findstr OK`) do @echo * %%x %%y for /f "usebackq tokens=1,1-2 delims= " %%x in (`net use ^| findstr : ^| findstr /v "OK"`) do @echo * %%x %%y for /f "usebackq tokens=2 delims= " %%x in (`net use ^| findstr /l \\ ^| findstr /v ": 切断" ^| findstr OK`) do @echo * %%x for /f "usebackq tokens=1 delims= " %%x in (`net use ^| findstr /l \\ ^| findstr /v ": OK 切断"`) do @echo * %%x for /f "usebackq tokens=1,1-2 delims= " %%x in (`net use ^| findstr 切断`) do @echo * %%x %%y :NO_LOGON if "%netuse%"=="none" echo: if "%netuse%"=="none" echo * ありません... if "%netd%"=="none" echo: if "%netd%"=="none" echo * ネットワークドライブ割り当てはありません... echo: echo *** 何かキーを押すとメニューに戻ります *** pause >nul GOTO MENU REM ########################################################################## REM ### 2. LOGOFF * ### REM ########################################################################## :LOGOFF for /l %%x in (1,1,10) do if defined logon%%x set logon%%x= set cnt=0 for /f "usebackq tokens=2,2-3 delims= " %%x in (`net use ^| findstr : ^| findstr OK`) do set "ch_tmep=%%x %%y" && CALL :NET_USE for /f "usebackq tokens=1,1-2 delims= " %%x in (`net use ^| findstr : ^| findstr /v "OK"`) do set "ch_tmep=%%x %%y" && CALL :NET_USE for /f "usebackq tokens=2 delims= " %%x in (`net use ^| findstr /l \\ ^| findstr /v ": 切断" ^| findstr OK`) do set "ch_tmep=%%x" && CALL :NET_USE for /f "usebackq tokens=1 delims= " %%x in (`net use ^| findstr /l \\ ^| findstr /v ": OK 切断"`) do set "ch_tmep=%%x" && CALL :NET_USE for /f "usebackq tokens=2 delims= " %%x in (`net use ^| findstr 切断`) do set "ch_tmep=%%x" && CALL :NET_USE GOTO SHOW_LOG :NET_USE set /a cnt=cnt+1 set "logon%cnt%=%ch_tmep%" goto :EOF REM ##################################### REM ### エントリ解除 REM ##################################### :SHOW_LOG set netuse= set choice= set del_log= net use | findstr エントリが存在しません >nul && set netuse=none cls echo: echo ============================================================== echo *** 解除するエントリを選択シテクダサイ echo ============================================================== echo: if "%netuse%"=="none" echo * ありません... if defined logon1 echo *** 1 --- %logon1% if defined logon2 echo *** 2 --- %logon2% if defined logon3 echo *** 3 --- %logon3% if defined logon4 echo *** 4 --- %logon4% if defined logon5 echo *** 5 --- %logon5% if defined logon6 echo *** 6 --- %logon6% if defined logon7 echo *** 7 --- %logon7% if defined logon8 echo *** 8 --- %logon8% if defined logon9 echo *** 9 --- %logon9% if defined logon10 echo *** 10 --- %logon10% echo: echo * 99 : メニューに戻る echo ============================================================== echo: set /p choice= [番号] : echo: if "%choice%"=="99" GOTO MENU if "%choice%"=="1" set "del_log=%logon1%" if "%choice%"=="2" set "del_log=%logon2%" if "%choice%"=="3" set "del_log=%logon3%" if "%choice%"=="4" set "del_log=%logon4%" if "%choice%"=="5" set "del_log=%logon5%" if "%choice%"=="6" set "del_log=%logon6%" if "%choice%"=="7" set "del_log=%logon7%" if "%choice%"=="8" set "del_log=%logon8%" if "%choice%"=="9" set "del_log=%logon9%" if "%choice%"=="10" set "del_log=%logon10%" for /f "tokens=1" %%x in ("%del_log%") do set del_log=%%x if "%del_log%"=="" GOTO SHOW_LOG :ASK set ask= echo: echo ************************************************************** echo * %del_log% を解除(切断) します ! echo *** よろしいデスカ? *** echo: echo * そのままEnter : 解除(切断) echo * 99 : 戻る echo ************************************************************** echo: set /p ask= [Y , 99] : echo: if "%ask%"=="99" GOTO LOGOFF if /i "%ask%"=="y" GOTO DEL_LOG if /i "%ask%"=="" GOTO DEL_LOG GOTO ASK :DEL_LOG net use /delete %del_log% >nul if not ERRORLEVEL 1 echo * %del_log% を解除(切断)しました... echo: echo: echo *** 何かキーを押すと戻ります *** pause >nul GOTO LOGOFF REM ########################################################################## REM ### 3. LOGON * ### REM ########################################################################## :LOGON set count=0 for /f "usebackq tokens=1,1-1 delims= " %%x in (`net view ^| findstr \\`) do set "hname=%%x" && call :SET_HOST GOTO SEL_HOST :SET_HOST set /a count=count+1 set host%count%=%hname% GOTO :EOF :SEL_HOST set ho_name= cls echo: echo ============================================================== echo *** ホスト名を番号で選択してクダサイ echo ============================================================== echo *** if defined host1 echo *** 1 --- %host1% if defined host2 echo *** 2 --- %host2% if defined host3 echo *** 3 --- %host3% if defined host4 echo *** 4 --- %host4% if defined host5 echo *** 5 --- %host5% if defined host6 echo *** 6 --- %host6% if defined host7 echo *** 7 --- %host7% if defined host8 echo *** 8 --- %host8% if defined host9 echo *** 9 --- %host9% if defined host10 echo *** 10 --- %host10% echo: echo * 直接入力 : \\ホスト名 or \\IPアドレス echo: echo * 99 : メニューに戻る echo ============================================================== echo: set /p ho_name= [番号 , 99 ] : echo: if "%ho_name%"=="99" GOTO MENU if "%ho_name%"=="" GOTO SEL_HOST if "%ho_name%"=="1" set "ho_name=%host1%" if "%ho_name%"=="2" set "ho_name=%host2%" if "%ho_name%"=="3" set "ho_name=%host3%" if "%ho_name%"=="4" set "ho_name=%host4%" if "%ho_name%"=="5" set "ho_name=%host5%" if "%ho_name%"=="6" set "ho_name=%host6%" if "%ho_name%"=="7" set "ho_name=%host7%" if "%ho_name%"=="8" set "ho_name=%host8%" if "%ho_name%"=="9" set "ho_name=%host9%" if "%ho_name%"=="10" set "ho_name=%host10%" if "%ho_name%"=="\\%computername%" GOTO WAIT if not "%ho_name%"=="" GOTO SEL_USER GOTO SEL_HOST :WAIT echo: echo !!! 選択ホストは自分自身です... !!! echo: echo *** 戻るには何かキーを押シテクダサイ *** pause >nul GOTO SEL_HOST REM ##################################### REM ### ユーザ名 入力 REM ##################################### :SEL_USER set usr_name= cls echo: echo ============================================================== echo *** %ho_name% にログオンする 'ユーザ名' を入力してクダサイ echo ============================================================== echo *** echo *** 認証不要なら、そのまま Enter echo: echo * 99 : 戻る echo ============================================================== echo: set /p usr_name= [ユーザ名 , 99 ] : echo: if "%usr_name%"=="" set usr_name=guest if "%usr_name%"=="99" GOTO LOGON net use | findstr %ho_name%\ipc$ && net use /delete %ho_name%\ipc$ :PASSWD_1 echo ============================================================== echo *** パスワード入力 *** echo ============================================================== echo: net use "%ho_name%\ipc$" /user:%usr_name% * 2>nul echo: echo ============================================================== if ERRORLEVEL 1 GOTO WAIT2 GOTO OK_LOGON :WAIT2 echo: echo !!! エラー出ますた... !!! echo: echo *** 戻るには何かキーを押シテクダサイ *** pause >nul GOTO SEL_USER REM ##################################### REM ### ログオン確認 REM ##################################### :OK_LOGON set oklogon= cls echo: echo ============================================================== echo *** %ho_name%\ipc$ にログオンしました echo ============================================================== echo: echo * ネットワークドライブは割当しなくても、 echo * %ho_name% に echo * マイ ネットワークからアクセス可能になっています。 echo: echo * 引き続き、ネットワークドライブを割当しますか? echo: echo * Enter (Y) : ネットワークドライブを割当 echo * 99 : 戻る echo ============================================================== echo: set /p oklogon= [番号 , 99 ] : echo: if "%oklogon%"=="99" GOTO LOGON if "%oklogon%"=="" GOTO NET_VIEW if /i "%oklogon%"=="y" GOTO NET_VIEW GOTO OK_LOGON REM ##################################### REM ### 共有名 選択 REM ##################################### :NET_VIEW set count=0 for /f "usebackq tokens=1" %%x in (`net view %ho_name% ^| findstr Disk`) do set "sname=%%x" && call :SET_SHAR GOTO SEL_SHAR :SET_SHAR set /a count=count+1 set share%count%=%sname% GOTO :EOF :SEL_SHAR set sh_name= cls echo: echo ============================================================== echo *** 共有名を番号で選択してクダサイ echo ============================================================== echo *** if defined share1 echo *** 1 --- %share1% if defined share2 echo *** 2 --- %share2% if defined share3 echo *** 3 --- %share3% if defined share4 echo *** 4 --- %share4% if defined share5 echo *** 5 --- %share5% echo: echo * 直接入力 : 共有名 echo * 99 : 戻る echo ============================================================== echo: set /p sh_name= [番号 , 99 ] : echo: if "%sh_name%"=="99" GOTO LOGON if "%sh_name%"=="" GOTO SEL_SHAR if "%sh_name%"=="1" set "sh_name=%share1%" if "%sh_name%"=="2" set "sh_name=%share2%" if "%sh_name%"=="3" set "sh_name=%share3%" if "%sh_name%"=="4" set "sh_name=%share4%" if "%sh_name%"=="5" set "sh_name=%share5%" net use | findstr ^: | findstr /i /c:"%ho_name%\%sh_name%" if not ERRORLEVEL 1 GOTO WAIT3 if not "%sh_name%"=="" GOTO NET_MNT GOTO SEL_SHAR :WAIT3 echo: echo ! %ho_name%\%sh_name% は割当済みです ! echo: echo *** 戻るには何かキーを押シテクダサイ *** pause >nul GOTO SEL_SHAR REM ##################################### REM ### ネットワークドライブ割り当て REM ##################################### :NET_MNT REM ## 空きドライブ文字の検索 regedit /e /a "mount_reg.txt" "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices" for %%x in (O,P,Q,R,S,T,U,V,W,X,Y,Z) do findstr \\%%x: mount_reg.txt >nul || if not exist %%x:\ set netdrive=%%x: for %%x in (%netdrive%) do set netdrive=%%~dx :ASK2 set ask2= echo: echo ============================================================== echo *** %ho_name%\%sh_name% を %netdrive% に割当てます *** echo *** よろしいデスカ? *** echo: echo * そのままEnter : 実行 echo * N (n) : 選択しなおす echo * 99 : 戻る echo ============================================================== echo: set /p ask2= [Y , n ,99] : echo: if "%ask2%"=="99" GOTO LOGON if /i "%ask2%"=="n" GOTO SEL_SHAR if /i "%ask2%"=="y" GOTO PASSWD_2 if /i "%ask2%"=="" GOTO PASSWD_2 GOTO ASK2 :PASSWD_2 echo ============================================================== echo *** もう一度 パスワード入力 *** echo ============================================================== echo: net use %netdrive% %ho_name%\%sh_name% /user:%usr_name% * 2>nul echo: echo ============================================================== if ERRORLEVEL 1 GOTO WAIT4 net use /delete "%ho_name%\ipc$" GOTO MOUNT :WAIT4 echo: echo !!! エラー出ますた... !!! echo: echo *** 戻るには何かキーを押シテクダサイ *** pause >nul GOTO SEL_SHAR :MOUNT cls echo: echo ************************************************************** echo: echo * '%ho_name%\%sh_name%' を echo * %netdrive% ドライブに割り当てしました echo: for /f "tokens=3" %%x in ('dir %netdrive% ^| findstr 空き領域') do set aki=%%x echo * %netdrive% ドライブ の空き領域 : %aki% バイト echo: echo ************************************************************** echo: echo *** 何かキーを押すと戻ります *** pause >nul GOTO LOGON :ERROR echo: echo !!! エラー出ますた... !!! echo: GOTO END :CANCEL echo: echo キャンセルしますた... echo: GOTO END :END echo: echo *** 終了します... *** echo: echo *** 何かキーを押すと閉じます *** echo: pause >nul del mount_reg.txt 2>nul