Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBscript to create folder named the same as the current user

Posted on 2009-07-10
5
Medium Priority
?
606 Views
Last Modified: 2012-05-07
Hello,

We are working on our logon script.  Every user in our organization has a "U:" drive. This is their personal storage place on the network.  We want to have our script check to see if there is a folder already there, and if there is, it should map it.  If there is not a folder there, it should create one named the same as the current user, and then map it.  All of our folders in this location are named the same as the username of the computer user.  Also, we would like to set the security on the folder so that only the current user, and our admin group on our domain can access it.. not sure if this is possible.. Very little VB experience unfortunately..

any help would be great
0
Comment
Question by:OSXaddict
[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
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24824870
Hi, OSXaddict.

I'm unclear on whether the the script is supposed to map the U: drive to the user's folder or it is supposed to check the U: drive to see if the folder exists there.  f the former, then where would the script check to see if the folder exists?  If the latter then what drive letter is the script supposed to map to the folder?
0
 

Author Comment

by:OSXaddict
ID: 24824933
Hello! The Script should check to see if there is a folder named the same as the current user sitting on one of our servers.  If the folder exists, then it should map the drive letter "U" to this folder.  

If the folder did not exist, (first time login) it should create a folder on this network server, and then name it the same as the current user.  Then it should map the folder to drive letter "U".

sorry to be unclear, thank you for the response!
0
 
LVL 76

Accepted Solution

by:
David Lee earned 1000 total points
ID: 24825125
Try this.
Dim objFSO, objNetwork, objSysInfo, strUser, strPath
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the path on the next line'
strPath = "\\Server\Path\" & strUser
If Not objFSO.FolderExists(strPath) Then
    objFSO.CreateFolder strPath
    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.MapNetworkDrive "U:", strPath
End If
Set objFSO = Nothing
Set objNetwork = Nothing
Set objSysInfo = Nothing

Open in new window

0
 
LVL 2

Assisted Solution

by:JManicki
JManicki earned 1000 total points
ID: 24825416
While BlueDevilFan's code would work, If your users have enough access to the root of the U: drive to create a folder then--unless you do a lot of extra rights changing--they have access to ALL of the other Users' folders as well.  From a user file security standpoint, this is unacceptable.

What I would do is simply check to see if a User's folder exists then map it if it is there.  If it's not (due to file rights or it hasn't been created yet) then pop up an error to let the user know to contact the IT Department to fix the problem.

In order to maintain the proper security on the U: drive, your administrators would have to be the only ones with file rights to the root of the drive/folder where your User Folders are stored and they'd be the ones to manually create the user folders and assign the file rights to just that one user.

Here's the code for the user login part.  All you'd have to do is change the **SERVERNAME** to match the your server's name and change the MsgBox text to fit what you'd like the popup to say to the user when there was a problem mapping the drive.
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strServerName = "**SERVERNAME**"
strUserName = objNetwork.UserName
strFolderPath = "\\" & strServerName & "\" & strUserName
If objFSO.FolderExists(strFolderPath) Then
	objNetwork.MapNetworkDrive "U:", strFolderPath
Else
	MsgBox "There was a problem mapping your User Folder." & vbCRLF & "Please contact the IT Department to fix this problem."
End If

Open in new window

0
 
LVL 2

Expert Comment

by:JManicki
ID: 24825494
Also, if you use the ADSystemInfo's UserName property (as in BDF's code) you're going to get the "Distinguished Name" for the user's folder which would look something like: "CN=John Doe,OU=Users,DC=fabrikam,DC=com".

The WScript.Network's UserName property would only be the user's Login Name, "JDoe"
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

636 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