Solved

VBS Network Login Script

Posted on 2006-06-28
5
283 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 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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