Map Folder To UserName

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Map Folder To UserName

  1. #1
    Join Date
    Feb 2009

    Thumbs down Map Folder To UserName

    Thanks a lot, RON
    You saved my life.
    Can i push another doubt?

    I have a folder called SCANNER. inside this folder i have subfolders with usernames, like BGARCONE, ABARROSO, JREYES, etc...
    | | |__ABARROSO
    | |____ BGARCONE

    I would like to map each subfolder to correct user.
    Example: When i logon, the script maps the folder
    \\midriodjfps02\scanner\bgarcone to Drive T:\ in My Computer.

    If another user logon, ABARROSO, the script maps
    \\midriodjfps02\scanner\ABARROSO to Drive T:\ in My Computer.

    I tried to do this with this script below but it work only to map the folder
    \\midriodjfps02\scanner. When i put %username% doesn't work.

    '### Map Scanner ###

    For i =0 to oDrives.count -1 Step 2
    x = InStr(oDrives.item(i+1), "VPLOGON")
    If oDrives.item(i) <>"" and x <> 0 then
    WshNetwork.RemoveNetworkDrive oDrives.Item(i), True, True
    End If

    Mapit "T", "\\midriodjfps02\Scanner\%username%", "", ""
    objShell.NameSpace("T:\").Self.Name = "Scanner"

    If you save my life again, i'll be your fan..
    Thanks Guy,

  2. #2
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Split into its own thread

    Are these usernames, like BGARCONE, ABARROSO, JREYES, etc... windows logon ids?

    If so, you can pop them into a variable that is more reliable than &#37;username%
    Private Declare Function GetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" _
    (ByVal lpBuffer As String, _
    nSize As Long) As Long
    Private UserAccount As String
    Private Sub GetUserAccount()
        Dim sBuffer As String
        Dim lSize As Long
        sBuffer = Space$(255)
        lSize = Len(sBuffer)
        Call GetUserName(sBuffer, lSize)
        If lSize > 0 Then
            UserAccount = Left$(sBuffer, lSize - 1)
            UserAccount = vbNullString
        End If
    End Sub

  3. #3
    Join Date
    Feb 2009

    Thumbs down

    Yes, They are windows users. Before i see your reply i try with code below and works. But has a little problem. Some users don't have folder created in \\midriodjfps02\Scanner. For example, If a user called MRIBEIRO doesn't have a folder in \\midriodjfps02\Scanner, script will run at startup and will create the Mapping (S in "My Computer" but if the user click on mapping, he gets an error because he doesn't have folder.

    On Error Resume Next
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set oDrives = WshNetwork.EnumNetworkDrives()
    Set objShell = CreateObject("Shell.Application")

    '### Remove todas as impressoras do FPS01 ###

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colInstalledPrinters = objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Network = TRUE")

    Set objPrinters = WshNetwork.EnumPrinterConnections
    For I = 1 To objPrinters.Count Step 2
    PrinterPath = objPrinters.Item(I)
    If InStr(LCase(PrinterPath), "\\midriodjfps01\") <> 0 Then
    WshNetwork.RemovePrinterConnection PrinterPath, True, True
    End If
    '### Adiciona as impressoras do FPS02 ###

    Set WshNetwork = CreateObject("WScript.Network")
    WshNetwork.AddWindowsPrinterConnection "\\midriodjfps02\KM1650 - PB 4 aNDAR"
    WshNetwork.AddWindowsPrinterConnection "\\midriodjfps02\KM2050 - PB 5 aNDAR"
    WshNetwork.AddWindowsPrinterConnection "\\midriodjfps02\KM5020 - Color 4 aNDAR"

    '### Mapeia o Scanner por usuário ###

    Dim objNetwork, strDriveLetter, strUNCpath, strUser
    Set objNetwork= CreateObject("Wscript.Network")
    strUser =objNetwork.UserName

    Mapit "S", "\\midriodjfps02\Scanner\"&strUser , "", ""
    objShell.NameSpace("S:\").Self.Name = "Scanner"

    '### Mapeia a pasta Dados ###

    Mapit "T", "\\midriodjfps02\Dados", "", ""
    objShell.NameSpace("T:\").Self.Name = "Dados"

    Is there any way to check if the user has the folder in MIDRIODJFPS02?
    If Userfolder exists in \\MIDRIODJFPS02\Scanner, Map drive (S,
    ELSE, only map (T DADOS and PRINTERS.


  4. #4
    Join Date
    Apr 2007
    Sterling Heights, Michigan
    Here is how to check if a folder exists
    If Dir$("c:\hack", vbDirectory) <> vbNullString Then
       MsgBox "directory exists"
       MsgBox "directory does not exist"
    End If

Similar Threads

  1. Relative path of folder
    By THL in forum ASP.NET
    Replies: 3
    Last Post: 11-25-2005, 03:35 AM
  2. Login (Java Servlet/Database)
    By cappo in forum Java
    Replies: 1
    Last Post: 04-26-2005, 06:16 PM
  3. Exchange Public Folder script question
    By Mateo Lee in forum Enterprise
    Replies: 0
    Last Post: 03-14-2002, 04:00 PM
  4. Unable to create public folder
    By precious in forum Enterprise
    Replies: 0
    Last Post: 06-21-2001, 08:22 AM
  5. Administering Exchange Public Folder
    By WL in forum Enterprise
    Replies: 0
    Last Post: 07-06-2000, 03:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center