中国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 18:36
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,505 / 28
Floor1 beyoungse Posted 2007-09-02 02:15
中级用户 Posts 112 Credits 253
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"
```
Floor2 beyoungse Posted 2007-09-02 02:16
中级用户 Posts 112 Credits 253
The name and password of the shared file I set up on the server correspond to the computer names of the following workstations.
Floor3 beyoungse Posted 2007-09-02 02:25
中级用户 Posts 112 Credits 253
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.
Floor4 beyoungse Posted 2007-09-02 02:46
中级用户 Posts 112 Credits 253
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=
Floor5 beyoungse Posted 2007-09-02 10:43
中级用户 Posts 112 Credits 253
Is there anyone who can help me write a script? Thanks in advance here
Floor6 beyoungse Posted 2007-09-02 13:33
中级用户 Posts 112 Credits 253
What I tried just now, the 4th floor is not feasible
Floor7 beyoungse Posted 2007-09-02 14:00
中级用户 Posts 112 Credits 253
Passing bosses, help me out
Floor8 beyoungse Posted 2007-09-02 14:25
中级用户 Posts 112 Credits 253
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%$"
Floor9 wudixin96 Posted 2007-09-02 14:26
银牌会员 Posts 931 Credits 1,928
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.
Floor10 beyoungse Posted 2007-09-02 14:45
中级用户 Posts 112 Credits 253
When I run, it prompts a compiler error... And how to change the volume label of the mapped disk
Floor11 beyoungse Posted 2007-09-02 16:03
中级用户 Posts 112 Credits 253
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%”
Floor12 beyoungse Posted 2007-09-02 16:03
中级用户 Posts 112 Credits 253
The mapping was not successfully achieved after running.
Floor13 wudixin96 Posted 2007-09-02 16:51
银牌会员 Posts 931 Credits 1,928
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 ]
Floor14 beyoungse Posted 2007-09-02 17:07
中级用户 Posts 112 Credits 253
How to use variables in VBS?
Floor15 wudixin96 Posted 2007-09-02 17:30
银牌会员 Posts 931 Credits 1,928
Set objComputer = CreateObject("Shell.LocalMachine")

Wscript.Echo "Computer name: " & objComputer.MachineName
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023