windows bat系列10:批量設定&取消共享目錄
1. 背景
在使用Windows過程中,經常要設定共享目錄,用完之後,又要取消共享目錄,如果只設定一次還好(直接右鍵—共享),但若有多個固定的目錄需要設定再取消,單個單個的設定就會很low,因而思考更快捷的解決方案:使用DOS指令碼。
2. dos命令
windows下網路共享主要是用net命令實現,其有多個子命令,如:
Command |
Sub-command |
annotation |
菜鳥翻譯 |
例子 |
Net |
View |
NET VIEW displays a list of resources being shared on a computer. When used without options, it displays a list of computers in the current domain or network. |
|
Net view—檢視域中PC數量 |
Share |
NET SHARE makes a server's resources available to network users. |
目錄共享 |
D:\myself\windows_script>net share help="D:\myself\windows_script\help" /grant:everyone,full 共享我的help檔案,使用者為everyone,許可權為full(可讀/寫/修改),其中help為共享名 net share help delete --停止剛才的help共享 |
|
Stop |
NET STOP stops Windows services. |
停止windows服務 |
Net stop |
|
Start |
NET START lists running services. |
啟動或檢視已經啟動的windows服務 |
Net start |
|
… |
|
|
|
3. 指令碼化
@echo off
Rem close echo
Rem chane active page
chcp 437 >nul
Rem delay expansion
setlocal enabledelayedexpansion
Rem set parameters
set TESTLIST=D:\myself\windows_script\bat_out;D:\myself\windows_script\bat_test;D:\myself\windows_script\testnull;
set TMPLIST=%TESTLIST%
Rem print title
echo=
echo=
echo ---------------------------%date% %time:~0,8%---------------------------
set /a NUM = 1
:loop
for /f "tokens=1* delims=;" %%a in ("%TMPLIST%") do (
Rem set local parameters
echo #!NUM! is %%a
Rem share_the_dir
for %%h in ("%%a") do (
net share %%~nh="%%a" /GRANT:everyone,FULL
)
Rem recursion
set TMPLIST=%%b
)
if defined TMPLIST goto :loop
Rem
echo=
echo=
endlocal
pause
4. 指令碼分析
- 變數TESTLIST儲存著待共享的路徑(以分號分割,最後一個路徑也要加分號“;”),後續生產可以設定;
- 採用for迴圈遞迴分割TESTLIST,抽取各個路徑;
- 在各個路徑中取最後的目錄名(內部for語句)---這裡用到擴充套件變數;
- 根據抽取的目錄名和之前的路徑呼叫net share進行共享;
- OK---全部搞定
5. 測試結果
相關文章
- win10怎麼設定nfs共享目錄_win10啟動nfs共享目錄的操作步驟Win10NFS
- vmware安裝VMware Tools,並設定共享目錄
- linux掛載windows共享目錄LinuxWindows
- 【萬里征程——Windows App開發】設定共享(共享源和共享目標)WindowsAPP
- linux與linux之間共享目錄設定Linux
- Word 設定目錄
- Windows2000Server設定活動目錄域WindowsServer
- 在word中怎麼設定目錄 word設定目錄的方法
- windows透過samba訪問aix的共享目錄WindowsSambaAI
- Linux掛載Windows網路共享目錄(轉)LinuxWindows
- 通過cifs協議,linux mount windows共享目錄協議LinuxWindows
- Linux批量建立目錄Linux
- Windows ntp時間同步設定(bat指令碼)WindowsBAT指令碼
- 儲存目錄的SMB目錄共享問題
- windows10怎麼設定開機密碼 windows10如何取消鎖屏密碼Windows密碼
- oracle 10G設定歸檔目錄及命令Oracle 10g
- linux nfs 共享目錄LinuxNFS
- 4.2.10.2 設定和取消設定環境變數變數
- win10設定硬碟密碼怎麼取消 win10硬碟設定密碼如何取消Win10硬碟密碼
- 抖音批量取消喜歡,批量取消抖音喜歡
- 獲取和設定pdf目錄
- win10印表機共享設定方法 win10如何設定印表機共享Win10
- redis系列目錄Redis
- CSS系列目錄CSS
- WebApi系列~目錄WebAPI
- JavaScript系列目錄JavaScript
- Windows10 如何更改Docker映象目錄WindowsDocker
- 10g Supplemental Log 設定與取消
- bat一鍵設定開啟或關閉windows功能BATWindows
- Linux共享遠端目錄Linux
- 電腦共享檔案怎麼設定,Win10共享設定方法Win10
- win10系統怎麼設定自動關機和取消自動關機的bat命令Win10BAT
- Vue設定許可權列表目錄Vue
- secureCRT如何設定sz傳輸目錄Securecrt
- win10共享網路怎麼設定_w10區域網共享設定方法Win10
- CSS系列之目錄CSS
- SQL Server系列目錄SQLServer
- Windows 上 Emacs 啟動的預設目錄WindowsMac