Solved

VBS Network Login Script

Posted on 2006-06-28
5
277 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
  • 2
5 Comments
 
LVL 70

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 70

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…

829 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