Solved

Help with mapping user home directory via vbs script

Posted on 2009-07-01
15
871 Views
Last Modified: 2012-05-07
Hi experts, I am just about finished with my login script thanks to some help I got already on here. Now I just need to map the home directory. I have included my entire script for reference but the part I am looking for help with is this line:

   MapDrive "g:", "\\server1\user$\" & CurrentUser

Can anyone tell me what I've done wrong?

Thanks!
' =========== Start Of Script
 

Option Explicit

' On Error Resume Next
 

DIM oShell, oNetwork, oPrinters, oDrives

DIM ADSysInfo, CurrentUser, LogServer

DIM UsrGrp, i

Dim strDriveLetter, strDrivePath
 
 
 

' =======================================================         Pull in logged on Users Info
 

  Set oShell = CreateObject("WScript.Shell")

  LogServer = oShell.ExpandEnvironmentStrings("%logonserver%")

  Set ADSysInfo = CreateObject("ADSystemInfo")

  Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)  
 
 

' =======================================================         Delete All Printers & Network Drives except the H: Drive

 

  Set oNetwork = CreateObject("WScript.Network")            

'  Set oPrinters = oNetwork.EnumPrinterConnections

'  

'  ' === Printers

'  

'     For i = 0 to oPrinters.Count - 1 Step 2

'      If Left(ucase(oPrinters.Item(i+1)),2) = "\\" Then

'        oNetwork.RemovePrinterConnection oPrinters.Item(i+1)

'      End If

'    Next

'  

'  ' === Drives

  

    Set oDrives = oNetwork.EnumNetworkDrives

    For i = 0 to oDrives.Count - 1 Step 2

'    	If oDrives(i) <> "H:" Then

       oNetwork.RemoveNetworkDrive oDrives(i), True, True

'     End If

    Next
 
 

' =======================================================        Map Printers
 

'To map printers use:

'oNetwork.AddWindowsPrinterConnection "PrinterLocation eg \\server\hp-printer"
 

'To set mapped printer as default:

'oNetwork.SetDefaultPrinter "PrinterPath"
 
 

' =======================================================        Map H & G Drives
 

   MapDrive "h:", "\\server1\dept"

   MapDrive "g:", "\\server1\user$\" & CurrentUser
 
 

' =======================================================        Map Drives Based on Group Membership

' 
 

   For Each UsrGrp In CurrentUser.Groups

  

     Select Case uCase(right(Usrgrp.Name,Len(UsrGrp.Name) - 3))

    

     Case "FINANCE"

       MapDrive "i:", "\\server7\finance"

       MapDrive "p:", "\\server4\fasserv"

 

     Case "CENTRAL SCANNER"

       MapDrive "j:", "\\server2\file_share"

 

     Case "R13 SHOP-AT-HOME DISTRIBUTION LIST"

       MapDrive "j:", "\\server2\file_share"

 

     Case "HELIOSPCUSERS"

       MapDrive "k:", "\\server3\marketing"

 

     Case "TECHNOLOGY"

       MapDrive "s:", "\\server1\install$"

       MapDrive "n:", "\\server1\Minime"

 

     Case "ONDEMANDDEV"

       MapDrive "l:", "\\server5\content"

 

     Case "HUMAN RESOURCES"

       MapDrive "k:", "\\server6\Connect"

 

     Case "BSTL"

       MapDrive "O:", "\\server1\BSTL$"  

 

     End Select

   Next

 

 Sub MapDrive(strDriveLetter, strDrivePath)

   oNetwork.MapNetworkDrive strDriveLetter, strDrivePath

 End Sub
 

' =======================================================        Set the default SAP Environment Variable
 
 

   oshell.run "setx SAPLOGON_INI_FILE ""h:\sapgui\all\saplogon.ini""", 6, True
 
 

' =======================================================        Map a SAP Group-Specific Environment Variable
 

  For Each UsrGrp In CurrentUser.Groups

 

    Select Case uCase(right(Usrgrp.Name,Len(UsrGrp.Name) - 3))
 

    Case "SAPGUIFULL"

      oshell.run "setx SAPLOGON_INI_FILE ""h:\sapgui\full\saplogon.ini""", 6, True
 

    Case "SAPGUIBWFULL"

      oshell.run "setx SAPLOGON_INI_FILE ""h:\sapgui\bwfull\saplogon.ini""", 6, True
 

    Case "SAPGUIBW"

      oshell.run "setx SAPLOGON_INI_FILE ""h:\sapgui\bw\saplogon.ini""", 6, True

   

    Case "SAPGUIDEV"

      oshell.run "setx SAPLOGON_INI_FILE ""h:\sapgui\dev\saplogon.ini""", 6, True
 

    Case "SAPGUIDOMAIN"

      oshell.run "setx SAPLOGON_INI_FILE ""h:\sapgui\DOMAIN\saplogon.ini""", 6, True

      

    End Select

  Next  

  

  WScript.Quit

Open in new window

0
Comment
Question by:wallakyl
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 47

Expert Comment

by:dstewartjr
ID: 24759514
Try

 oShell.MapNetworkDrive "g:", "\\server1\user$\" & CurrentUser,True
0
 

Author Comment

by:wallakyl
ID: 24759579
I had tried that, but it gives me an error:

Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment

See screenshot at bottom of thread.
0
 
LVL 47

Expert Comment

by:dstewartjr
ID: 24759605
What does line 59 now read?
0
 

Author Comment

by:wallakyl
ID: 24759631
The new line you gave me - I changed it to this...the last line is 59

MapDrive "h:", "\\server1\dept"
'MapDrive "g:", "\\server1\user$\" & CurrentUser
oShell.MapNetworkDrive "g:", "\\server1\user$\" & CurrentUser,True
0
 
LVL 47

Expert Comment

by:dstewartjr
ID: 24759738
Try creating a value for the path

set homepath="\\server1\user$\" & CurrentUser

add homepath to your dims

then change to

oShell.MapNetworkDrive "g:", homepath,True
0
 

Author Comment

by:wallakyl
ID: 24759966
Same error unfortunately - this time in the:


set homepath="\\server1\user$\" & CurrentUser
0
 
LVL 47

Expert Comment

by:dstewartjr
ID: 24760053
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:wallakyl
ID: 24760276
Yeah, that's why I don't understand why it isn't working. That's how I have it I think.
0
 
LVL 47

Expert Comment

by:dstewartjr
ID: 24760308
you can use wscript.echo to display any values getting set to see if the error may be with one of your values

Like

 wscript.echo CurrentUser
0
 

Expert Comment

by:napiercc
ID: 24760350
Hi,

here is a little tidbit of script courtesy of www.rlmueller.net.

---------------------------------------------------------------------------

' Map user home directory.
strHomeShare = objUser.homeDirectory
If (strHomeShare <> "") Then
    strHomeDrive = objUser.homeDirDrive
    If (strHomeDrive = "") Then
        strHomeDrive = "H:"
    End If
    On Error Resume Next
    objNetwork.MapNetworkDrive strHomeDrive, strHomeShare
    If (Err.Number <> 0) Then
        On Error GoTo 0
        objNetwork.RemoveNetworkDrive strHomeDrive, True, True
        objNetwork.MapNetworkDrive strHomeDrive, strHomeShare
    End If
    On Error GoTo 0
End If

-----------------------------------------------------------------------------------------

The full script can be found at: http://www.rlmueller.net/Programs/Logon1.txt

It uses a different method of determining the current user and does some checking to make sure the drive isn't already mapped.

Hope this is helpfull for you.

cheers
Glen
0
 

Accepted Solution

by:
wallakyl earned 0 total points
ID: 24760688
This seems to be working...
  strUserName = oNetwork.UserName

  strHomePath = "\\server1\users$" & "\" & strUserName

  oNetwork.MapNetworkDrive "g:", strHomePath 

Open in new window

0
 
LVL 47

Assisted Solution

by:dstewartjr
dstewartjr earned 500 total points
ID: 24760693
There you go ;^D
0
 
LVL 83

Expert Comment

by:oBdA
ID: 24761216
On a side note: if the home drive and share is defined in the user's properties in ADUC (as it should be), then you won't have to map it in the logon script at all (you'd only have to exclude it from being deleted in line 36ff).
During logon, this drive will be automatically mapped. In addition, having the home drive property set in AD will as well set the environment variables HOMEDRIVE, HOMEPATH, HOMESHARE correctly; some programs evaluate these variables, and if there's no home drive specified in the user's properties, these variable will point to the local profile.
0
 

Author Comment

by:wallakyl
ID: 24764099
The attached file replaces the file I attached in comment 24759579.
screenshot.jpg
0
 
LVL 83

Expert Comment

by:oBdA
ID: 24765489
Line 61 above is empty; you'll need to post the exact script that is producing this error.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now