Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB script - create folder, map as specific drive letter.  Need to add user in Security tab

Posted on 2011-04-27
6
Medium Priority
?
584 Views
Last Modified: 2012-06-27
Here's the portion of our login script that creates, and maps a drive for a users folder.  I didn't realize it then, but this did not give the user modify rights.  Which is what I need help doing now.  I just want to add to the code I hve now, with what's needed to add the user to the security tab with modify rights.
''''''''''''''''''''''''''''''create user folder'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CheckForUserFolder(UserName)
On Error Resume Next
Dim ObjFSO
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
	If Not(ObjFSO.FolderExists("\\jak-2k3-mss\users\" & UserName)) Then 
		Set newfolder = ObjFSO.CreateFolder("\\jak-2k3-mss\Users\" & UserName)
	End If
End Sub

Open in new window

0
Comment
Question by:Ben Hart
6 Comments
 
LVL 15

Expert Comment

by:greg ward
ID: 35477699
to change permissions you need the command cacls
cacls /? at the command prompt to see which switches you need.
The below link shows you how to use it with vb script.

http://www.appdeploy.com/messageboards/tm.asp?m=15015

Greg
0
 
LVL 8

Accepted Solution

by:
jawa29 earned 500 total points
ID: 35484104
Hi ubadmin

These two lines added to your code will set Full control for the user on thier folder

Set oShell = CreateObject("Wscript.Shell")
intRunError = oShell.Run("cacls \\jak-2k3-mss\Users\" & UserName & " /t /c /g " & Username & ":F ", 2, True)

If you want to set to modify then change :F to :C

Jawa29
0
 
LVL 7

Expert Comment

by:CitizenRon
ID: 35487438
Is this for Active Directory users?  If so, you don't need to do this in a login script, you could just add a "Home Folder" to the user's "Profile" tab in AD Users and Computers.

If you have a large number of Users to add this do, in ADUC create a Query called "All Users" and Define the Query so that on the "Users" tab, "Name" "Has a Value" and run the query.  Select all the users in the result, right click and pick "Properties" and you'll be able to modify them all at once.

Go to the "Profile" tab, check the "Home Folder" box, select "Connect", choose a Drive Letter for the mapping and put in
\\jak-2k3-mss\users\%USERNAME%
for the value in the "To:" field.  

Once a user has a connected Home Folder value, the system should create the folder if it doesn't exist and automatically apply the rights needed for the user to use their home folder and also map the selected drive letter to the home folder each time they log in.
0
Industry Leaders: 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!

 
LVL 14

Author Comment

by:Ben Hart
ID: 35487480
Thanks CitizenRon.. I recall we used to have a line similar to that in the Home Folder field however it never actually created the folder.  Last year when I had help creating this portion of the script I forgot totally about the Home Folder's use..  I will test it, as well as Jawa29's code..

Thanks both of you.
0
 
LVL 7

Assisted Solution

by:CitizenRon
CitizenRon earned 500 total points
ID: 35487894
I just looked at jawa29's script again and have a BIG issue with it.  He does NOT use the /E switch to tell CACLS to EDIT the permissions.  Without it, the ONLY permissions left on the folder will be what you tell it in the command.  All other permissions will be removed from the folder and all files and folders underneath it.

With the /E switch, CACLS will just EDIT the ACLs and add permissions instead of completely replacing them.
Set oShell = CreateObject("Wscript.Shell")
intRunError = oShell.Run("cacls \\jak-2k3-mss\Users\" & UserName & " /t /e /c /g " & Username & ":F ", 2, True)

Open in new window

0
 
LVL 14

Author Comment

by:Ben Hart
ID: 35488250
Ahh nice catch.  I'm fighting AV issues at the moment but glad you caught that.  Probably just a typo though.
0

Featured Post

Industry Leaders: 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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

564 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