Display Name drive mapping in VB

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
LVL 2
nemesis1210Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PePiCommented:
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
Shiju SasidharanAssoc Project ManagerCommented:
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
nemesis1210Author Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

nemesis1210Author Commented:
I dont need the username I need the display name, also I need to know how to put this together in a script
0
PePiCommented:
just to be clear... you want us to provide you with a login script?
0
nemesis1210Author Commented:
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
aelatikCommented:
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
nemesis1210Author Commented:
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
aelatikCommented:
Test mine, and we can work on that...
0
aelatikCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nemesis1210Author Commented:
aelatik, looks very close to what I need other than I need display name not username

0
nemesis1210Author Commented:
aelatik I tested it works perfect other than the need for Display name over Username
0
aelatikCommented:
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
PePiCommented:
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
nemesis1210Author Commented:
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
aelatikCommented:
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
nemesis1210Author Commented:
it is an active directory domain
0
aelatikCommented:
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
nemesis1210Author Commented:
could I use the username variable in this as I wont be able to enter it
0
aelatikCommented:
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
nemesis1210Author Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.