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-08-05 17:57
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » (Closed) Seeking VBS to automatically map a network drive and rename it to DATA View 3,500 Replies 28
Original Poster Posted 2007-09-02 02:15 ·  中国 广东 深圳 福田区 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
I'm using a diskless WinXP SP2. I want to place user configuration files in a network folder (map the network folder as local D: when booting). I used a batch script:

net use d: \\server\%computername%$ %computername% /user:%computername%

But the batch script runs after the user logs in, so there's an error.

Please help me write a startup script.

I can't describe clearly, so let's take an example.

Data server computer name: server

Share names: A001$, A002$, A003$ ……A040$

Client computer names: 001, 002, 003……040

Access user names: A001, A002, A003……A040

Share passwords: A001, A002, A003……A040

Finally, change the mapped drive name to: DATA

[ Last edited by beyoungse on 2007-9-3 at 12:14 PM ]

Here's a possible startup script example (assuming you can use a VBScript or a batch with proper handling):

@echo off
set "server=server"
set "clientname=%computername%"
set "sharename=A%clientname%$"
set "username=A%clientname%"
set "password=A%clientname%"
net use d: \\%server%\%sharename% %password% /user:%username%
if %errorlevel% equ 0 (
ren d: DATA
) else (
echo Failed to map drive
)

But you may need to adjust based on your exact environment. Make sure to save this as a .bat file and set it as a startup script in your boot configuration.
```vbscript
Set objNetwork = CreateObject("WScript.Network")
strServer = "server"
strClientName = WScript.CreateObject("WScript.Shell").ExpandEnvironmentStrings("%computername%")
strShareName = "A" & strClientName & "$"
strUserName = "A" & strClientName
strPassword = "A" & strClientName
objNetwork.MapNetworkDrive "D:", "\\ " & strServer & "\" & strShareName, False, strUserName, strPassword
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.GetDrive("D:").ShortName = "DATA"
```
Floor 2 Posted 2007-09-02 02:16 ·  中国 广东 深圳 福田区 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
The name and password of the shared file I set up on the server correspond to the computer names of the following workstations.
Floor 3 Posted 2007-09-02 02:25 ·  中国 广东 深圳 福田区 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
Is there any better way to enable personalized settings for diskless users, such as desktop configuration environment and appearance, shortcuts, start menu...?

I am using a workgroup.
Floor 4 Posted 2007-09-02 02:46 ·  中国 广东 深圳 福田区 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
I can't test it now. I don't know if this is okay.

I just saw it.
Put the batch file in C:\WINDOWS\SYSTEM32\GROUPOLICY\MACHINE\SCRIPTS\ and edit SCRIPTS.INI here.
The content is as follows:
[startup]
0cmdline=batch file name
0parameters=
Floor 5 Posted 2007-09-02 10:43 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
Is there anyone who can help me write a script? Thanks in advance here
Floor 6 Posted 2007-09-02 13:33 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
What I tried just now, the 4th floor is not feasible
Floor 7 Posted 2007-09-02 14:00 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
Passing bosses, help me out
Floor 8 Posted 2007-09-02 14:25 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
Can you tell me how to specify the user name and password?

The following is the script I used written by someone else:

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
lng_timeout=8
Wscript.Sleep lng_timeout*1000
WshNetwork.MapNetworkDrive "D:", "\\server\%computername%$"
Floor 9 Posted 2007-09-02 14:26 ·  中国 香港 腾讯云
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Add a shared network drive to the computer system.

object.MapNetworkDrive(strLocalName, strRemoteName, [bUpdateProfile], [strUser], [strPassword])
Parameters
object
WshNetwork object.
strLocalName
A string value representing the local name of the mapped drive.
strRemoteName
A string value representing the UNC name of the share (\\xxx\yyy).
bUpdateProfile
Optional. A boolean value indicating whether the mapping information is stored in the current user profile. If the provided value of bUpdateProfile is true, the mapping is stored in the user's profile (default is false).
strUser
Optional. A string value representing the user name. If mapping the network drive using credentials of a user other than the current user, this parameter must be provided.
strPassword
Optional. A string value representing the user password. If mapping the network drive using credentials of a user other than the current user, this parameter must be provided.
Floor 10 Posted 2007-09-02 14:45 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
When I run, it prompts a compiler error... And how to change the volume label of the mapped disk
Floor 11 Posted 2007-09-02 16:03 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
Modify the VBS in building 8, still not working

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
lng_timeout=8
Wscript.Sleep lng_timeout*1000
WshNetwork.MapNetworkDrive "D:", "\\server\%computername%$",“%computername%”,“%computername%”
Floor 12 Posted 2007-09-02 16:03 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
The mapping was not successfully achieved after running.
Floor 13 Posted 2007-09-02 16:51 ·  中国 香港 腾讯云
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
WshNetwork.MapNetworkDrive "D:", "\\server\%computername%$",,“%computername%”,“%computername%”

By the way, are those %computername% variables not applicable in VBS?

[ Last edited by wudixin96 on 2007-9-2 at 04:53 PM ]
Floor 14 Posted 2007-09-02 17:07 ·  中国 广东 深圳 电信
中级用户
★★
Credits 253
Posts 112
Joined 2005-12-20 00:31
20-year member
UID 47500
Status Offline
How to use variables in VBS?
Floor 15 Posted 2007-09-02 17:30 ·  中国 香港 腾讯云
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Set objComputer = CreateObject("Shell.LocalMachine")

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