Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


August 28, 2001

Create Home Directories and Set NTFS Permissions with a Web Script


RSS
View this exclusive article with VIP access -- click here to join |
See More Active Server Pages (ASP) Articles Here | Reprints | Or sign up for our VIP Monthly Pass!
SideBar    Resources for the Script’s Technologies

To make the script easier to read, I defined the custom constant of CUSTCON_ALLOW_INHERIT, whose sum represents these three flags. This custom constant configures the ACE so that the DACLs below the home directory inherit the ACE.

The AceType value specifies whether the ACE will have Allow or Deny type permissions. In the script, I use the ACETYPE_ACCESS_ALLOWED constant to specify Allow type permissions. In other words, the subdirectories below the user account's home directory will inherit the ACE and the user account will have Allow type permissions.

The oTrustee value specifies the trustee that you want to assign to the ACE. To assign a trustee to the ACE, the SetACE function needs the trustee's user-account name, domain name, and SID. The SetTrustee function neatly compartmentalizes the trustee information for the SetACE function.

The SetTrustee function takes four parameters: the moniker to the CIMv2 namespace and the trustee's domain name, user-account name, and SID. The script obtains the domain name from the Web form's User account domain text box and the user-account name from the form's User account name text box. The script obtains the SID from the QuerySid function that I described earlier. . . .

Reader Comments
Awesome! But will it work on 'old' non Active Directory Win 2000 server?

sean August 28, 2001


The short answer is yes, with minor modifications it will work with a stand-alone computer running Windows 2000. You must change the QuerySid function so that it queries the SAM database on the stand-alone Windows 2000 computer rather than the Active Directory store on a domain controller. You might also have to modify the SetTrustee function because the domain name is one of its parameters.
Perhaps I could write a supplement to this article that shows the changes necessary to make this work on a stand-alone Windows 2000 computer.

Ethan Wilansky October 23, 2001


I tried putting the script into a Visual Basic component, which should not have presented any problems. However, when I try to set permission rights on the folder, I get an undefined automation error. My components run on the Web server, which is also the domain controller. However, the folders may be created on any file server within the domain. Can you tell me what the path to the folder should look like when passing it into the procedure? The path is always like this:<br>
<br>
\\SERVERNAME\Users\USERNAME<br>
<br>
where Users is a share that is located on the E: drive of the server. I have tried a few things, like<br>
<br>
\\SERVERNAME\Users$\USERNAME<br>
\\SERVERNAME\Users\USERNAME<br>
\\SERVERNAME\E:\Users\USERNAME<br>
<br>
If you can see why I get the undefined automation error, please let me know. I really need to be able to set security for the user on this folder, and I have not been able to find any other way to do it.


Inge Schepers December 05, 2001


<p>How can I do this with multiple users? I took your script and hacked it into a VBScript file to run against a large volume of data. The problem is that I can only use one user and it overwrites the existing ACE entries for the ACL. This is the best script I have found to do this so far. I commend you on your knowledge. Thanks for any help.</p><br>
<p><b>Braden</b> - Thanks for your kind words about the article. I have to tell you, I really sweated that one out because, as you've found, the documentation on configuring DACLs using WMI is somewhat incomplete.</p>
<p>In answer to your first question, you should wrap the modifications to the DACL inside a script that uses either ADO and the ADSI OLE DB provider or a script that enumerates containers using the ADSI IADsContainer interface.</p>
<p>Here's a script that uses ADO to return all user accounts that are security principals in a domain named na.fabrikam.com. Once that result set is returned, the script modifies the company attribute of each user account to Fabrikam. What you need to do is replace the bolded lines of the script below with the script I wrote to modify the DACL of user account folders. Of course, you should also change the distinguishedName specified in the query string. I know this isn't a complete solution but hopefully it puts you on the right track. This script is part of the System Administration Scripting Guide (SASG) that I'm contributing to for the Windows .NET Server Resource Kit. To see this and many other scripts, visit: http://www.microsoft.com/technet/scriptcenter. This is the area that our team is responsible for and the scripts there are derived primarily from the scripts that will eventually appear in the SASG.</p>
<br>
<pre>Set objConnection = CreateObject("ADODB.Connection")<br>
objConnection.Open "Provider=ADsDSOObject;"<br>
<br>
Set objCommand = CreateObject("ADODB.Command")<br>
objCommand.ActiveConnection = objConnection<br>
<br>
objCommand.CommandText = "LDAP://dc=NA,dc=fabrikam,dc=com;" & _ <br>
"(&(objectCategory=person)(objectClass=user));" & "ADsPath;subtree"
<br>
Set objRecordSet = objCommand.Execute<br>
<br>
While Not objRecordset.EOF<br>
strADsPath = objRecordset.Fields("ADsPath")<br>
Set objUser = GetObject(strADsPath) <br>
objUser.Put "company", "Fabrikam"<br>
objUser.SetInfo<br>
objRecordset.MoveNext<br>
Wend<br>
<br>
WScript.Echo objRecordSet.RecordCount & " user accounts modified."<br>
objConnect.Close</pre>
<br>
<p>About not overwriting the DACL, I would have to research this before feeling comfortable with answering your question. Unfortunately, I'm swamped right now with trying to get chapters delivered for the SASG. I hope, though, that I've helped put you on the right track for now. I suggest visiting the TechNet Script Center to see what you can dig up. You might also want to download the latest WMI SDK and read about the Security Provider.<b> --Ethan </b></p>



Braden Callahan August 28, 2002


Indeed this is the best script I've seen so far. But, one little tiny thing is missing....varType function is missing.

Remy March 29, 2004


The script is creating the users home directory but it si not giving it the necessary rights to the folder. The error I get is Unable to retrieve the Win32_LogicalFileSecurity Setting of d:\ririvera

RealBigTime November 04, 2004


I am a novice when it comes to ASP, so please bear with me. I have modified your UserCreate.asp and have it working fine, but when it comes to HomeFolderPerms.asp, the home directory on the file server is not created (although the script thinks it is) - until it tries to apply rights I have domain admin rights. I can run a test vbs script from the same directory on the domain server and create directories without a problem.

Anonymous User April 21, 2005 (Article Rating: )


I am not able to find the entire scripts to download. Any idea. Thanks

Moongate May 24, 2006 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 24, 2008

An often irreverent look at some of the week's other news, including a Vista Capable dismissal request, Zune price reductions, Morrow musings, Novell and Microsoft sitting in a tree ... two years later, Yahoo!, IE 6 on Windows Mobile, and so much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Next Version of Exchange Named Exchange 2010?

Microsoft apparently inadvertently announced the official name of the next version of Exchange Server. ...


Security Whitepapers The Impact of Messaging and Web Threats

Why SaaS is the Right Solution for Log Management

Protecting (You and) Your Data with Exchange Server 2007

Related Events Top 10 Email Security Challenges and Solutions

Introduction to Identity Lifecycle Manager "2"

Delivering Reliable and Effective Web-Based Applications

Check out our list of Free Email Newsletters!

Security eBooks Spam Fighting and Email Security for the 21st Century

Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

Related Security Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing