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
    Posts
    3

    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...
    SCANNER
    | | |__ABARROSO
    | |____ BGARCONE
    |______JREYES

    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
    Next

    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
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    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%
    Code:
    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)
        Else
            UserAccount = vbNullString
        End If
        
    End Sub
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Feb 2009
    Posts
    3

    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
    next
    '### 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.

    Thanks,

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Here is how to check if a folder exists
    Code:
    If Dir$("c:\hack", vbDirectory) <> vbNullString Then
       MsgBox "directory exists"
    Else
       MsgBox "directory does not exist"
    End If
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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