今天收到命令,要做定時(shí)的備份工作,備份的目的地要在遠(yuǎn)端的網(wǎng)路磁碟機(jī)上
掛載、卸載網(wǎng)路磁碟機(jī)
因此就去查詢(xún)?nèi)绾卧?Windows 上寫(xiě) script 掛載網(wǎng)路磁碟機(jī),以下找到一段語(yǔ)法:
WshNetwork.MapNetworkDrive接著是卸載網(wǎng)路磁碟機(jī)的語(yǔ)法:
maps a remote drive onto a local drive letter
Syntax:
WshNetwork.MapNetworkDrive (strLocalName, strRemoteName [,bUpdateProfile] [,strUser] [,strPassword])
strLocalName
Receives the drive letter to which to map the remtoe share point in strRemoteName.
strRemoteName
Receives the name ofd the remote share point that will be mapped to the drive letter in strLocalName.
bUpdateProfile
If this optional parameter is True, the mapping will be saved in the current user's profile.
strUser
When combined with strPassword, this parameter can be used to conenct to a remote drive using someone else's credentials.
strPassword
When combined with strUser, this parameter can be used to conenct to a remote drive using someone else's credentials.
WshNetwork.RemoveNetworkDrive
removes a previously mapped network drive
Syntax:
WshNetwork.RemoveNetworkDrive (strName, [,bForce] [,bUpdateProfile])
strName
Receives the name of a previously mapped share point to be removed.
bForce
If this optional parameter is set to True, then this method will remove the connection even if the resource is currently being used.
bUpdateProfile
If this optional parameter is set to True, the mapping will be removed from the current user's profile.
以下是他的 sample code:
Dim objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")
strLocalDrive = "H:"
strRemoteShare = "\\myserver\users"
objNetwork.MapNetworkDrive strLocalDrive, strRemoteShare, False '沒(méi)有第四、五個(gè)參數(shù),表示不需帳號(hào)密碼
objNetwork.RemoveNetworkDrive strLocalDrive '卸載網(wǎng)路磁碟機(jī)
資料複製
另外還要將本地資料複製到網(wǎng)路磁碟機(jī)上,可用以下一段簡(jiǎn)單的語(yǔ)法達(dá)成:(也是範(fàn)例語(yǔ)法)
set fs = CreateObject("Scripting.FileSystemObject")
'將 c:\win98 中所有的內(nèi)容複製到 z:\backup (不包含 c:\win98 資料夾)
fs.copyFolder "c:\win98","z:\win99"
'將 c:\win98 中所有的內(nèi)容複製到 z:\backup (包含 c:\win98 資料夾)
fs.copyFolder "c:\win98","z:\win99\"
參考資料
- WSH >> Objects >> wshnetwork
- WSH >> wshnetwork >> MapNetworkDrive
- WSH >> wshnetwork >> RemoveNetworkDrive
- WshNetwork.MapNetworkDrive
- 資安論壇 - 求助!有時(shí)需要reboot或re-log才看見(jiàn)net use的network drive
- Windows Script 介紹 - 檔案及資料夾的處理