Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBS Network Login Script

Posted on 2006-06-28
5
Medium Priority
?
287 Views
Last Modified: 2010-04-30
I am using the following code to create my login script that will map network drives.  However, I am having a few problems.

1. In Active directory I have login script path pointing to the login.vbs,  The problem is everytime I login, I get an error the drive is already in use.  Is there an overwrite command?  I dont want to disconnect all because some users may have their own manually mapped drives.  I suppose I could also just disconnect the drives the drives that are about to be mapped again.  Just not sure what is the best way or how to do it.

2.  Is it possible to prevent the name of the mapped drive from being stored in the users profile or wherever it is stored?  If I try to the net use command on an existing letter I get the renamed version from the script I had run instead of "share on server."

3.  Is there away to do a "net time \\servername /set /y"

Here is my what I have:

Option Explicit
Dim objNetwork, strDrive, objShell, objUNC
Dim strRemotePath, strDriveLetter, strNewName


strDriveLetter = "H:"
strRemotePath = "\\server\share1"
strNewName = "Share Name 1"

strDriveLetter = "I:"
strRemotePath = "\\server\share1"
strNewName = "Share Name 1"

strDriveLetter = "J:"
strRemotePath = "\\server\share3"
strNewName = "Share Name 3"


Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath,,Username,Password


Set objShell = CreateObject("Shell.Application")
objShell.NameSpace(strDriveLetter).Self.Name = strNewName

WScript.Quit
0
Comment
Question by:ohmErnie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 17001555

Hi there,

1. Not as such. You can approach the problem a number of different ways.

 - Supress the error completely by adding "On Error Resume Next" into your script

On Error Resume Next
objNetwork.RemoveNetworkDrive strDriveLetter, False, True
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath,,Username,Password

 - Check and see if the drive is mapped before trying to map it:

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
If objFileSystem.DriveExists("H:") Then
    objNetwork.RemoveNetworkDrive strDriveLetter, False, True
End If
strDriveLetter = "H:"
strRemotePath = "\\server\share1"
strNewName = "Share Name 1"
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath,,Username,Password


The rest will follow in a moment.

Chris
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 17001601

As far as the rest of drive mapping goes I use a slightly modified version of the subroutine below to handle ours. This means each mapping can be added with:

MapDrive "H:", "\\Server\Home\User"

Sub MapDrive(strDrive, strShare)
      Dim objFileSystem, objDrive, objNetwork

      Set objFileSystem = CreateObject("Scripting.FileSystemObject")
      If objFileSystem.DriveExists(strDrive) Then
            Set objDrive = objFileSystem.GetDrive(strDrive)
            If objDrive.DriveType <> 3 Then
                  ' Drive Type is not a Network Drive
                  Exit Sub
            End If
      End If
      Set objFileSystem = Nothing
      Set objNetwork = CreateObject("WScript.Network")
      On Error Resume Next
      objNetwork.RemoveNetworkDrive strDrive, False, True
      objNetwork.MapNetworkDrive strDrive, strShare, True
      On Error Goto 0
      Set objNetwork = Nothing
End Sub


2. That's an issue with storing it in the users profile, I'm afraid I don't know of a fix for it.


3. Yep, nice and easy:

Set objShell = CreateObject("WScript.Shell")
objShell.Run "net time \\servername /set /y"


Chris
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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