中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-05 17:57
48,039 topics / 350,124 posts / today 2 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » (Closed) Seeking VBS to automatically map a network drive and rename it to DATA
Printable Version  3,499 / 28
Floor16 beyoungse Posted 2007-09-02 17:44
中级用户 Posts 112 Credits 253
Originally posted by wudixin96 at 2007-9-2 17:30:
Set objComputer = CreateObject("Shell.LocalMachine")

Wscript.Echo "Computer name: " & objComputer.MachineName

Will prompt "Computer name: XXX" (need to click OK again)

I can't achieve the result required by this batch command (NET USE D: \\SERVER\%COMPUTERNAME% %COMPUTERNAME% /USER:%COMPUTERNAME%). Can you help me write a VBS?
Floor17 beyoungse Posted 2007-09-02 21:00
中级用户 Posts 112 Credits 253
Got the following code from the Windows Chinese site (with my own wrapping), but it doesn't run properly.

On error resume next

Set objNet = CreateObject("Wscript.Network")
strCompName = objnet.ComputerName

Set objNetwork = CreateObject("Wscript.Network")
strNewName = "data"


' Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "d:","\\server\A"strCompName"$","A"strCompName"","A"strCompName""

' Section which actually (re)names the Mapped Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName
Floor18 slore Posted 2007-09-02 21:02
铂金会员 Posts 2,478 Credits 5,212
"d:","\\server\A"strCompName"$","A"strCompName"","A"strCompName""

Take a look...

The string is quite messy!
Floor19 beyoungse Posted 2007-09-02 21:46
中级用户 Posts 112 Credits 253
Boss, help me take a look at the thirteenth line of the following code

On error resume next

Set objNet = CreateObject("Wscript.Network")
strCompName = objnet.ComputerName
strNewName = "data"
strDriveLetter = "d"

' Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "d:","\\server\A" & strCompName & "$","A" & strCompName, "A" & strCompName,
' Section which actually (re)names the Mapped Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName

The thirteenth line is: objShell.NameSpace(strDriveLetter).Self.Name = strNewName
Floor20 slore Posted 2007-09-02 23:41
铂金会员 Posts 2,478 Credits 5,212
objNetwork.MapNetworkDrive "d:","\\server\A" & strCompName & "$","A" & strCompName, "A" & strCompName,

The third parameter doesn't seem right? Why is there a comma at the end?
Line 13... It seems to be the last line.
If you use the "D" string to see if it still errors? If not, it should be correct.
Floor21 beyoungse Posted 2007-09-03 10:52
中级用户 Posts 112 Credits 253
' #test.vbs
Set objNet = CreateObject("Wscript.Network")
strCompName = objnet.ComputerName
strNewName = "data"
strDriveLetter = "d"

' Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "d:","\\server\A" & strCompName & "$","A" & strCompName, "A" & strCompName
' Section which actually (re)names the Mapped Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName
' #完

Floor22 wudixin96 Posted 2007-09-03 11:00
银牌会员 Posts 931 Credits 1,928
object.MapNetworkDrive(strLocalName, strRemoteName, [bUpdateProfile], [strUser], [strPassword])

Please note this line. If you want to use the username and password without UpdateProfile, you also need to leave the position empty.

strLocalName, strRemoteName,, strUser, strPassword

There are two commas in the middle
Floor23 slore Posted 2007-09-03 11:12
铂金会员 Posts 2,478 Credits 5,212
Just set strLocalName and strRemoteName.
Floor24 beyoungse Posted 2007-09-03 11:16
中级用户 Posts 112 Credits 253
Floor25 beyoungse Posted 2007-09-03 11:24
中级用户 Posts 112 Credits 253
It's okay, thank you 22F, but the name of this disk can't be changed

Floor26 wudixin96 Posted 2007-09-03 11:40
银牌会员 Posts 931 Credits 1,928
Thanks to slore, people are getting old, and eyes are not working well

[ Last edited by wudixin96 on 2007-9-3 at 11:55 AM ]
Floor27 slore Posted 2007-09-03 11:48
铂金会员 Posts 2,478 Credits 5,212
Originally posted by wudixin96 at 2007-9-3 11:40:
strDriveLetter

Where does this variable come from??


He defined it earlier... It seems to be d
Floor28 beyoungse Posted 2007-09-03 12:13
中级用户 Posts 112 Credits 253
Problem Solving

strDriveLetter = "d:"
Floor29 beyoungse Posted 2007-09-03 12:25
中级用户 Posts 112 Credits 253
#OK.VBS
On error resume next

Set objNet = CreateObject("Wscript.Network")
strCompName = objnet.ComputerName
strNewName = "data"
strDriveLetter = "d:"

' Section to map the network drive
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "d:","\\server\A" & strCompName & "$",,"A" & strCompName, "A" & strCompName

' Section which actually (re)names the Mapped Drive
Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023