Solved

How to make drives persistent in vbs logon script?

Posted on 2008-06-24
11
553 Views
Last Modified: 2010-04-16
How to made the below mapping  persistent
----------------------------------------------------------------------------------------------------
Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath
strDriveLetter = "w:"
strRemotePath = "\\server1\xyz"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
WScript.Echo " Launch Explorer, check: "& strDriveLetter
WScript.Quit
--------------------------------------------------------------------------------------------------
0
Comment
Question by:Jameseka
  • 5
  • 4
11 Comments
 
LVL 13

Expert Comment

by:TheCapedPlodder
ID: 21853313
Add the bUpdateProfile value and set it to True as below:

objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, True


Cheers,

TCP
0
 

Author Comment

by:Jameseka
ID: 21853327
Can you complete the code ?

------------------------------------------------------------------------------------------------
Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath
strDriveLetter = "w:"
strRemotePath = "\\server1\xyz"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
WScript.Echo " Launch Explorer, check: "& strDriveLetter
WScript.Quit
------------------------------------------------------------------------------------------------
0
 

Author Comment

by:Jameseka
ID: 21853333
Oh I got it
0
 
LVL 13

Expert Comment

by:TheCapedPlodder
ID: 21853450
------------------------------------------------------------------------------------------------
Option Explicit
Dim objNetwork
Dim strDriveLetter, strRemotePath
strDriveLetter = "w:"
strRemotePath = "\\server1\xyz"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, True
WScript.Echo " Launch Explorer, check: "& strDriveLetter
WScript.Quit
------------------------------------------------------------------------------------------------
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Jameseka
ID: 21853720
the mapping disappear after the reboot.
0
 
LVL 13

Expert Comment

by:TheCapedPlodder
ID: 21853756
OK.

Well the bUpdateProfile value is the equivalent of /PERSISTENT:YES in net use so there must be some other factor at work.

Why don't you just run this as a login script rather than rely on persistency which is always a bit hit and miss?

Have you tried using a batch file (which is far simpler):

net use w: \\server1\xyz /PERSISTENT:YES

Cheers,

TCP

0
 

Author Comment

by:Jameseka
ID: 21862228
I know this command but VB scrip is what I need.
0
 
LVL 13

Accepted Solution

by:
TheCapedPlodder earned 500 total points
ID: 21863440
OK, two things.

If you must use VBScript then why not run it as a logon script so that the drive maps every time the user logs in and therefore you don't need to worry about persistency.

If that is unacceptable why not use net use as a troubleshooting step and see if the drive mapping is retained.  This will tell you whether something else is causing the drive mappings to be lost.
0
 
LVL 13

Expert Comment

by:TheCapedPlodder
ID: 21863503
I have provided the answer to your initial question and tried to help you beyond your initial issue.  You appear not to want to spend any effort on solving your own issue and that's fine however I should be awarded the points for providing a perfectly workable solution.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now