[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Display Name drive mapping in VB

Posted on 2004-10-28
22
Medium Priority
?
273 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
Comment
Question by:nemesis1210
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
  • 3
  • +1
22 Comments
 
LVL 6

Expert Comment

by:PePi
ID: 12436256
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
ID: 12436317
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
ID: 12436354
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Author Comment

by:nemesis1210
ID: 12436429
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
ID: 12436433
just to be clear... you want us to provide you with a login script?
0
 
LVL 2

Author Comment

by:nemesis1210
ID: 12436455
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
ID: 12436456
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
ID: 12436467
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
ID: 12436501
Test mine, and we can work on that...
0
 
LVL 14

Accepted Solution

by:
aelatik earned 2000 total points
ID: 12436526
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
ID: 12436531
aelatik, looks very close to what I need other than I need display name not username

0
 
LVL 2

Author Comment

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

Expert Comment

by:aelatik
ID: 12436583
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
ID: 12436630
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
ID: 12436637
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
ID: 12436715
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
ID: 12436775
it is an active directory domain
0
 
LVL 14

Expert Comment

by:aelatik
ID: 12436972
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
ID: 12437014
could I use the username variable in this as I wont be able to enter it
0
 
LVL 14

Expert Comment

by:aelatik
ID: 12437030
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
ID: 12444338
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

650 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