打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Windows Scripting - 簡易資料備份

September 17, 2007

Windows Scripting - 簡易資料備份


今天收到命令,要做定時的備份工作,備份的目的地要在遠端的網路磁碟機上

掛載、卸載網路磁碟機

因此就去查詢如何在 Windows 上寫 script 掛載網路磁碟機,以下找到一段語法:

WshNetwork.MapNetworkDrive
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 '沒有第四、五個參數,表示不需帳號密碼
objNetwork.RemoveNetworkDrive strLocalDrive '卸載網路磁碟機

資料複製

另外還要將本地資料複製到網路磁碟機上,可用以下一段簡單的語法達成:(也是範例語法)
set fs = CreateObject("Scripting.FileSystemObject")

'將 c:\win98 中所有的內容複製到 z:\backup (不包含 c:\win98 資料夾)
fs.copyFolder "c:\win98","z:\win99"

'將 c:\win98 中所有的內容複製到 z:\backup (包含 c:\win98 資料夾)
fs.copyFolder "c:\win98","z:\win99\"

參考資料

  1. WSH >> Objects >> wshnetwork
  2. WSH >> wshnetwork >> MapNetworkDrive
  3. WSH >> wshnetwork >> RemoveNetworkDrive
  4. WshNetwork.MapNetworkDrive
  5. 資安論壇 - 求助!有時需要reboot或re-log才看見net use的network drive
  6. Windows Script 介紹 - 檔案及資料夾的處理

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
方便用户共享资源,在域内通过脚本给域内计算机映射网络驱动器-微软技术-Cnfan.net中国网络
XP自身【可完整清除垃圾】的秘密武器
利用脚本添加网络打印机方法详解
【玩转电脑】隐藏在XP中的一个秘密武器!
三个位置放电脑,切忌!
磁碟音乐,乐在其中,令人陶醉
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服