請教各位前輩:
小弟因對程式不是很懂,但因公司有網路磁碟連接後的更名需求,因此在網路上搜尋了一個VBS程式後,透過撰寫改版,而產生了一個VBS檔,目前使用者套用該VBS檔案後,會產生網路磁碟機(已更名),但如果重覆執行時,便會出現錯誤訊息,不知應如何才能重覆建立,可以類似net use z: /delete的方式重覆執行,卻不會有錯誤訊息產生。
以下是我寫的指令,還請各位前輩指導應如何修改至可重覆執行,謝謝
' NameDrive.vbs
' VBScript to map a network drive.
' Authors Guy Thomas and Barry Maybury
' Version 1.4 - April 2010
' ----------------------------------------'
'
Option Explicit
Dim objNetwork0, strDrive0, objShell0, objUNC0
Dim objNetwork1, strDrive1, objShell1, objUNC1
strDriveLetter0 = "H:"
strRemotePath0 = "\\192.168.123.123\123"
strNewName0 = "123"
' Section to map the network drive
Set objNetwork0 = CreateObject("WScript.Network")
objNetwork0.MapNetworkDrive strDriveLetter0, strRemotePath0
' Section which actually (re)names the Mapped Drive
Set objShell0 = CreateObject("Shell.Application")
objShell0.NameSpace(strDriveLetter0).Self.Name = strNewName0
'
strDriveLetter1 = "J:"
strRemotePath1 = "\\192.168.123.123\456"
strNewName1 = "456"
' Section to map the network drive
Set objNetwork1 = CreateObject("WScript.Network")
objNetwork1.MapNetworkDrive strDriveLetter1, strRemotePath1
' Section which actually (re)names the Mapped Drive
Set objShell1 = CreateObject("Shell.Application")
objShell1.NameSpace(strDriveLetter1).Self.Name = strNewName1
' End of Example VBScript.
'
小弟因對程式不是很懂,但因公司有網路磁碟連接後的更名需求,因此在網路上搜尋了一個VBS程式後,透過撰寫改版,而產生了一個VBS檔,目前使用者套用該VBS檔案後,會產生網路磁碟機(已更名),但如果重覆執行時,便會出現錯誤訊息,不知應如何才能重覆建立,可以類似net use z: /delete的方式重覆執行,卻不會有錯誤訊息產生。
以下是我寫的指令,還請各位前輩指導應如何修改至可重覆執行,謝謝
' NameDrive.vbs
' VBScript to map a network drive.
' Authors Guy Thomas and Barry Maybury
' Version 1.4 - April 2010
' ----------------------------------------'
'
Option Explicit
Dim objNetwork0, strDrive0, objShell0, objUNC0
Dim objNetwork1, strDrive1, objShell1, objUNC1
strDriveLetter0 = "H:"
strRemotePath0 = "\\192.168.123.123\123"
strNewName0 = "123"
' Section to map the network drive
Set objNetwork0 = CreateObject("WScript.Network")
objNetwork0.MapNetworkDrive strDriveLetter0, strRemotePath0
' Section which actually (re)names the Mapped Drive
Set objShell0 = CreateObject("Shell.Application")
objShell0.NameSpace(strDriveLetter0).Self.Name = strNewName0
'
strDriveLetter1 = "J:"
strRemotePath1 = "\\192.168.123.123\456"
strNewName1 = "456"
' Section to map the network drive
Set objNetwork1 = CreateObject("WScript.Network")
objNetwork1.MapNetworkDrive strDriveLetter1, strRemotePath1
' Section which actually (re)names the Mapped Drive
Set objShell1 = CreateObject("Shell.Application")
objShell1.NameSpace(strDriveLetter1).Self.Name = strNewName1
' End of Example VBScript.
'