[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

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
0
nemesis1210
Asked:
nemesis1210
  • 10
  • 7
  • 3
  • +1
1 Solution
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 10
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now