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
|