Solved

Display Name drive mapping in VB

Posted on 2004-10-28
263 Views
Last Modified: 2012-06-27
Ok here is what I want to achieve :

VB Login Script to do the following

set a variable equal to the display name or the logged in user

check a share for a folder name equal to the variable

if it exists then map that to a drive letter

if not then do nothing

Any help is appreciated
0
Question by:nemesis1210
    22 Comments
     
    LVL 6

    Expert Comment

    by:PePi
    if you are looking for a local shared folder then you can find out by looking in the Registry

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanManServer\Shares

    here you will see all the locally shared folders


    cheers!
    0
     
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    Hi

    Try these links
    '------------------------------------------------------------------------------------
    >>Retrieving User, Share and Share User Name for Network Resources

    http://vbnet.mvps.org/index.html?code/network/wnetdemo.htm

    >>Determining if a Machine is Sharing a Specific Folder or Device

    http://vbnet.mvps.org/index.html?code/network/netsharecheck.htm
    '------------------------------------------------------------------------------------
    ;-)
    Shiju

    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    I think maybe my question was not clear enough

    I want a login script for a start

    this script needs to check within a share on the network for a folder named the same as the full users display name who is logged on, if the folder exists then i need to have the script map that folder to a drive letter on the machine which it is running on
    0
     
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    I dont need the username I need the display name, also I need to know how to put this together in a script
    0
     
    LVL 6

    Expert Comment

    by:PePi
    just to be clear... you want us to provide you with a login script?
    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    For example

    username : jbloggs
    Display Name : Joe Bloggs
    Share location \\server1\share1\
    Foldername in share : Joe Bloggs

    Script needs to check for the folder called Joe Bloggs (or whoever is logged in) if it exists then map that to a drive letter

    0
     
    LVL 14

    Expert Comment

    by:aelatik
    Here you go, if i think this is what you ment...

    SearchAndHook "\\SERVER-NAME\SHARE-NAME"

    Function SearchAndHook(Serverpath)
       
        ' Get the username
       
        Dim WSH_NET, USERNAME
        Set WSH_NET = CreateObject("wscript.network")
            USERNAME = WSH_NET.USERNAME
       
        ' Check for user in all folders in given serverpath.
        ' Note : try keeping all folders under one folder, with recursive loops it takes too long
       
        Dim FSO, FOLDER, SUBFOLDERS, FOLDER_ITEM
        Set FSO = CreateObject("scripting.filesystemobject")
        Set FOLDER = FSO.GetFolder(Serverpath)
        Set SUBFOLDERS = FOLDER.SUBFOLDERS
            For Each FOLDER_ITEM In SUBFOLDERS
                If LCase(FOLDER_ITEM.Name) = LCase(USERNAME) Then
                    ' Map the drive
                        WSH_NET.MapNetworkDrive "Z:", FOLDER_ITEM.Path
                End If
            Next
        Set WSH_NET = Nothing
        Set SUBFOLDERS = Nothing
        Set FOLDER = Nothing
        Set FSO = Nothing
       
    End Function
    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    Pretty much yes I have little VB knowledge I can tweak a script or an example to suit my needs but would not know where to start putting this together

    0
     
    LVL 14

    Expert Comment

    by:aelatik
    Test mine, and we can work on that...
    0
     
    LVL 14

    Accepted Solution

    by:
    Oops, forgot an EXIT FOR command....

    SearchAndHook "\\SERVER-NAME\SHARE-NAME"

    Function SearchAndHook(Serverpath)
       
        ' Get the username
       
        Dim WSH_NET, USERNAME
        Set WSH_NET = CreateObject("wscript.network")
            USERNAME = WSH_NET.USERNAME
       
        ' Check for user in all folders in given serverpath.
        ' Note : try keeping all folders under one folder, with recursive loops it takes too long
       
        Dim FSO, FOLDER, SUBFOLDERS, FOLDER_ITEM
        Set FSO = CreateObject("scripting.filesystemobject")
        Set FOLDER = FSO.GetFolder(Serverpath)
        Set SUBFOLDERS = FOLDER.SUBFOLDERS
            For Each FOLDER_ITEM In SUBFOLDERS
                If LCase(FOLDER_ITEM.Name) = LCase(USERNAME) Then
                    ' Map the drive
                        WSH_NET.MapNetworkDrive "Z:", FOLDER_ITEM.Path
                        Exit For
                End If
            Next
        Set WSH_NET = Nothing
        Set SUBFOLDERS = Nothing
        Set FOLDER = Nothing
        Set FSO = Nothing
       
    End Function
    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    aelatik, looks very close to what I need other than I need display name not username

    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    aelatik I tested it works perfect other than the need for Display name over Username
    0
     
    LVL 14

    Expert Comment

    by:aelatik
    Just a tip :

    In our company we have 7000 employees where some of them have the same First and Lastname.
    So in your case if someone would have the same displayname you won't be able to do a correct mapping. ( since the folders for both persons would be the same )
    And in NT or Novell a username is always unique.

    By the way, where do you wan't to fetch the Displayname from ? The local system does not store that information !

    0
     
    LVL 6

    Expert Comment

    by:PePi
    hope this helps

       Dim fso, f, f1, fc, s, objNet
       Set objNet = CreateObject("Wscript.Network")
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set f = fso.GetFolder(share_location)
       Set fc = f.SubFolders
       For Each f1 in fc
          If f1.name = display_name then
              objNet.MapNetworkDrive f1.path
          end if
       Next
    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    This factor is not a concern in this application only 300 users on this domain and maybe only 30 will utilize the script, however I believed the display name to be in the local system somewhere as when you press Ctrl Alt Del, it says displayname is logged in as domain\username, also it shows at the top of the start menu on windows XP clients

    0
     
    LVL 14

    Expert Comment

    by:aelatik
    I don't really think they (or you )  manually added Displayname's to all 300 user computers. It must be comming from the domain.
    The computer they logon to ( AKA Domain ) which contains the user accounts also contains the displaynames ( and many other info ).
    So if you wan't to fetch such info you need to know where to fetch it from. Is it NT, Active Directory or Novell ?

    Note : I a'm not an experts in Domains and Clients etc. But i'm pretty sure that the info comes from elsewhere...

    BTW. You can test it by making new User Accounts in XP. You only get to enter 1 name !
    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    it is an active directory domain
    0
     
    LVL 14

    Expert Comment

    by:aelatik
    Try something like this ;

    255.255.255.255 represents the Domain
    Johndoe001 represents the username

    USERNAME = GetObject("WinNT://255.255.255.255/Johndoe001,user").FullName
    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    could I use the username variable in this as I wont be able to enter it
    0
     
    LVL 14

    Expert Comment

    by:aelatik
    SearchAndHook "\\SERVER-NAME\SHARE-NAME"

    Function SearchAndHook(Serverpath)
       
        ' Get the username
       
        Dim WSH_NET, USERNAME
        Set WSH_NET = CreateObject("wscript.network")

            USERNAME = GetObject("WinNT://255.255.255.255/" & WSH_NET.USERNAME & ",user").FullName
       
        ' Check for user in all folders in given serverpath.
        ' Note : try keeping all folders under one folder, with recursive loops it takes too long
       
        Dim FSO, FOLDER, SUBFOLDERS, FOLDER_ITEM
        Set FSO = CreateObject("scripting.filesystemobject")
        Set FOLDER = FSO.GetFolder(Serverpath)
        Set SUBFOLDERS = FOLDER.SUBFOLDERS
            For Each FOLDER_ITEM In SUBFOLDERS
                If LCase(FOLDER_ITEM.Name) = LCase(USERNAME) Then
                    ' Map the drive
                        WSH_NET.MapNetworkDrive "Z:", FOLDER_ITEM.Path
                        Exit For
                End If
            Next
        Set WSH_NET = Nothing
        Set SUBFOLDERS = Nothing
        Set FOLDER = Nothing
        Set FSO = Nothing
       
    End Function
    0
     
    LVL 2

    Author Comment

    by:nemesis1210
    Not entirely what I wanted as far as the username, fullname goes but you have definetly pointed me in the right direction, I will post another question to help me where I am on the Active Directory Query thanks for your help

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    933 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

    15 Experts available now in Live!

    Get 1:1 Help Now