China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-11-11 06:58
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » (Closed) Seeking VBS to automatically map a network drive and rename it to DATA View 4,094 Replies 28
Floor 16 Posted 2007-09-02 17:44 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
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?
Floor 17 Posted 2007-09-02 21:00 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
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
Floor 18 Posted 2007-09-02 21:02 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
"d:","\\server\A"strCompName"$","A"strCompName"","A"strCompName""

Take a look...

The string is quite messy!
Floor 19 Posted 2007-09-02 21:46 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
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
Floor 20 Posted 2007-09-02 23:41 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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.
Floor 21 Posted 2007-09-03 10:52 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
' #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
' #完

Floor 22 Posted 2007-09-03 11:00 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
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
Floor 23 Posted 2007-09-03 11:12 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Just set strLocalName and strRemoteName.
Floor 24 Posted 2007-09-03 11:16 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
Floor 25 Posted 2007-09-03 11:24 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
It's okay, thank you 22F, but the name of this disk can't be changed

Floor 26 Posted 2007-09-03 11:40 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
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 ]
Floor 27 Posted 2007-09-03 11:48 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
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
Floor 28 Posted 2007-09-03 12:13 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
Problem Solving

strDriveLetter = "d:"
Floor 29 Posted 2007-09-03 12:25 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
#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
Forum Jump: