Google Answers Logo
View Question
 
Q: Login Scripts - Map Network Drives ( No Answer,   2 Comments )
Question  
Subject: Login Scripts - Map Network Drives
Category: Computers > Programming
Asked by: tiewire-ga
List Price: $10.00
Posted: 20 Jun 2003 10:58 PDT
Expires: 20 Jul 2003 10:58 PDT
Question ID: 219693
I have been trying to write a script to map network drives for a user
that is not a member of the domain, but with no luck.  Here are the
details:

language - vbscript/windows script host
OS - Win XP Home
Servers - Win2k server

When the user logs in, I need the script to map a drive to serverA
then map another drive to serverB and create a printer connection.

When I run my script, the first drive is mapped but the second doesn't
show up.  Another wrinkle to this is that when I use Start/run and
enter the UNC path, a login screen appears.  When I log in this way,
and then run the script, it works perfectly.

The script that I am using is:

Option Explicit
On Error Resume Next

Dim wshNetwork, wshShell, wshSysEnv, colDrives, nReturnCode
Dim i, strDrive1, strShare1, strLJPrinterPath , strDrive2, strShare2 
Dim sDrive


strDrive1 = "O:"
strShare1 = "\\server1\Operations"
strDrive2 = "W:"
strShare2 = "\\server2\vftw"

Set wshNetwork = WScript.CreateObject("WScript.Network")
Set wshShell = WScript.CreateObject("WScript.Shell")
Set wshSysEnv = wshShell.Environment("SYSTEM")

If (wshSysEnv("OS") = "Windows_NT") Then

'  Remove existing mappings
   Set colDrives = wshNetwork.EnumNetworkDrives
   'msgbox colDrives.Count
   If colDrives.Count <> 0 Then
   For i = 0 To colDrives.Count - 2 Step 2
	sDrive = colDrives(i)
	'msgbox colDrives.count
	'msgbox sDrive
        wshNetwork.RemoveNetworkDrive sDrive, True, True
   Next
   End If

'  Map Network Drives

   wshNetwork.MapNetworkDrive strDrive1, strShare1
   wshNetwork.MapNetworkDrive strDrive2, strShare2
   

'  synchronize the time
   nReturnCode = wshShell.Run("net time /domain:" &
wshNetwork.UserDomain & " /set /yes", 0, TRUE)
'  If (nReturnCode <> 0) Then
'     MsgBox "Unable to synchronize local clock."
'   End If

   'Remove old printer mappings 
   WshNetwork.RemovePrinterConnection "\\trifab\Konica"

   'Add the main network printer
   strLJPrinterPath = "\\trifab\Konica"
   WshNetwork.AddWindowsPrinterConnection strLJPrinterPath

Else

   WScript.Echo "This WSH logon script supports only Windows NT." &
vbNewLine & "Exiting..."
   Set wshNetwork = Nothing
   Set wshShell = Nothing
   WScript.Quit(1)

End If

Set wshNetwork = Nothing
Set wshShell = Nothing
WScript.Quit(nReturnCode)

I don't see any reason why this code doesn't work.  Please Help!

Request for Question Clarification by mathtalk-ga on 21 Jun 2003 20:18 PDT
Hi, tiewire-ga:

I concur with the approach suggested in the two independent comments
below, based on 'NET USE' commands.  Have you tried these types of
statements on the user's machine from a command line?

The issue is, I think, one you have identified in the question, "a
user that is not a member of the domain".  It is essential for the
purpose of making those network drive mappings that an appropriate
domain account (and password) be provided.  You may be the domain
administrator, or perhaps that role is taken by someone else.  In any
case the script shown presumably works under Windows NT because it
executes within a user session and "inherits" the user credentials for
that session.

It presumably fails one the Win XP Home machine simply because the
user is only logging into the local machine and has no network
credentials.  If this is the desired method of access, then the
network credentials must be validated as part of 'NET USE' commands. 
You can perhaps configure a domain 'guest' account (or have one
configured for you) that allows the minimum amount of permissions
necessary for the user/script to do what needs to be done.  A further
idea is to perhaps leave off the account password from the 'NET USE'
command, in which case the user should be prompted (automatically) to
enter that information (but only the first time the account credential
is validated).

If you are not satisfied with the 'NET USE' approach and would like
further advice, it would be helpful to hear from you what
considerations make that approach untenable or undesirable, so that
any further workaround suggestions are better informed.  Also, please
confirm that the network domain is indeed a Win2K domain; this opens
up a certain number of options as well as headaches.

regards, mathtalk-ga

Clarification of Question by tiewire-ga on 22 Jun 2003 11:46 PDT
mathtalk,

Thanks for your reply to my question.  To clarify:

The network is Win 2k Server based in Native Mode.

The 'Net Use' statements do work.  However, my question really
pertains to why the same functionality doesn't work when using Windows
script host.  The fact that the pc is not a member of the domain is an
issue, but the user has an account on the system.  When I run the
script using the user's account credentials, it still fails to map the
second drive.  The first one maps just fine.

The code that I have used to map the drives that includes the users
credentials is:

wshNetwork.MapNetworkDrive strDrive1, strShare1, True,
"domain\username", "Password"

It fails even when I use this.  However, I'd prefer not to use this
method because the login infomation is stored in the script in plain
text.

Any ideas on why this doesn't work?

Thanks for your help

Request for Question Clarification by mathtalk-ga on 22 Jun 2003 19:20 PDT
Have you tried switching the order of the drive mappings?  In other
words, if the order is reversed, is it still the same drive mapping
that fails or does the failure shift to the other network drive?  That
would pin down the order of the commands as a cause of the failure
(rather than something about the user's rights on the second machine).

If failure is tied to the "second" drive mapping (regardless of which
machine is placed there), then perhaps the problem is a timing issue. 
In other words the second command fails due to the first command not
having completed yet.  An issue of this type could be resolved by
inserting a delay into the script between the commands.

If the failure is tied to one of the network servers and the user's
network credentials seem to be in order as far as permissions on that
machine, then I c`an think of one (unlikely) suggestion to check. 
I've seen a conflict develop when a user had both a network login and
a local account on a particular (NT class) machine.

regards, mathtalk-ga
Answer  
There is no answer at this time.

Comments  
Subject: Re: Login Scripts - Map Network Drives
From: arimathea-ga on 20 Jun 2003 12:25 PDT
 
I can't help you with your code in specific, but from the command
prompt you can run the 'NET USE' command with parameters.  Maybe this
would be a suitable workaround.

--arimathea-ga
Subject: Re: Login Scripts - Map Network Drives
From: pokerpro-ga on 20 Jun 2003 15:28 PDT
 
I have a similar set up on my computer, however, I prefer using a batch file.

Sample:
net use o: /delete
net use w: /delete
net use o: \\server1\Operations /persistent:no /user:guest password
net use w: \\server2\vftw b /persistent:no /user:guest password

net use lpt2: /delete>nul
::LPT2 is an HP Laserjet 5040n
net use lpt2: "\\server3\printername" /persistent:no /user:guest password

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy