用批處理斷開網路連線
具體方法如下:
1、點選開始,點選執行,輸入notepad,點選確定;
2、複製以下內容到記事本:(此指令碼不受有線或無線連線的限制)
@echo off
rem 定義迴圈間隔時間:
set secs=30
echo。
echo ============================================
echo == 此指令碼用於計算機共享訪問達到上限後使用 ==
echo == 執行指令碼後會自動斷開一些訪問連線 ==
echo == 每%secs%秒種進行查詢,並執行清除命令 ==
echo ============================================
echo。
net session >nul || goto :error
:begin
set clear=0
echo。
for /f “tokens=1,2” %%i in (‘net session ^| find “/”’) do (
net session %%i /delete /y >nul 2>&1
set clear=1
echo %time:~0,8% 清除訪問來源: %%i [%%j]
)
echo。
if %clear%==0 (echo %time:~0,8% 現無人訪問此計算機, %secs%秒後繼續。。。
) else (echo %time:~0,8% 清除完畢, %secs%秒後繼續。。。)
ping 127。0。0。1 -n %secs% -w 0 >nul 2>&1
goto begin
:error
echo 許可權不足,無法執行,請與管理員聯絡。
echo。
pause >nul 2>&1 |echo 請按任意鍵關閉。。。
3、按ctrl+s,彈出儲存對話方塊,輸入1。bat,儲存型別選擇所有檔案,點選儲存;
4、雙擊執行該檔案即可。
輸入
rasphone /?
好像也沒看到具體的子命令的詳細說明。不知道怎麼搞。。。
vbs code:Const ssfCONTROLS = 3
sConnectionName = “本地連線” ‘可改成需要控制的連線名稱,如“無線網路連線”等
sEnableVerb = “啟用(&A)”
sDisableVerb = “停用(&B)” 非xp 系統可能 是禁用
set shellApp = createobject(“shell。application”)
set oControlPanel = shellApp。Namespace(ssfCONTROLS)
set oNetConnections = nothing
for each folderitem in oControlPanel。items
if folderitem。name = “網路連線” then
set oNetConnections = folderitem。getfolder: exit for
end if
next
if oNetConnections is nothing then
msgbox “未找到網路連線資料夾”
wscript。quit
end if
set oLanConnection = nothing
for each folderitem in oNetConnections。items
if lcase(folderitem。name) = lcase(sConnectionName) then
set oLanConnection = folderitem: exit for
end if
next
if oLanConnection is nothing then
msgbox “未找到 ’” & sConnectionName & “‘ item”
wscript。quit
end if
bEnabled = true
set oEnableVerb = nothing
set oDisableVerb = nothing
s = “Verbs: ” & vbcrlf
for each verb in oLanConnection。verbs
s = s & vbcrlf & verb。name
if verb。name = sEnableVerb then
set oEnableVerb = verb
bEnabled = false
end if
if verb。name = sDisableVerb then
set oDisableVerb = verb
end if
next
’debugging displays left just in case。。。
‘
’msgbox s ‘: wscript。quit
’msgbox “Enabled: ” & bEnabled ‘: wscript。quit
’not sure why, but invokeverb always seemed to work
‘for enable but not disable。
’
‘saving a reference to the appropriate verb object
’and calling the DoIt method always seems to work。
‘
if bEnabled then
’ oLanConnection。invokeverb sDisableVerb
oDisableVerb。DoIt
else
‘ oLanConnection。invokeverb sEnableVerb
oEnableVerb。DoIt
end if
’adjust the sleep duration below as needed。。。
‘
’if you let the oLanConnection go out of scope
‘and be destroyed too soon, the action of the verb
’may not take。。。
‘
wscript。sleep 400
樓上的那不算是用命令連線和斷開其實不用VB也能行得通斷開的命令是:Rasdial 寬頻連線 /disconnect(其中寬頻連線是連線時的名字,如果你的寬頻連線名是其他的,自己改)連線的命令是:Rasdial 寬頻連線 使用者名稱 密碼)(寬頻連線同上,使用者名稱和密碼就是你的ADSL撥號時的使用者名稱和密碼)字尾名改成。cmd或者是。BAT