Hi -

I have made a user-creation script (by taking bits and pieces from
various sources, which works nicely, except for one thing - this code
creates the homefolders nicely, but doesn't apply the right security
settings:

objFSO.CreateFolder "\\SERVER\data$\" & strUserName

strFolder = "\\SERVER\data$\" & strUserName

strXcacls = "Xcacls " & strFolder & " /C /P system:f ""Domain
Admins"":f " & strUserName & ":M /Y"

WshShell.Run strXcacls, 0


It doesn't give any errormessages when run. Can anybody see what I have
missed?

Additionally, I forgot to assign logon-script to some of the groups of
accounts I created - anybody know of a way to assign a logon-script for
accounts that doesn't have one?

Kind regards

Re: Trouble with xcacls in usercreation by dNagel

dNagel
Mon Sep 03 09:07:40 PDT 2007

try it something like this

command_string = "cscript c:\windows\xcacls.vbs c:\transfer /F /T /G
everyone:F"

D.


Unhappy MacbbokOwner wrote:
> Hi -
>
> I have made a user-creation script (by taking bits and pieces from
> various sources, which works nicely, except for one thing - this code
> creates the homefolders nicely, but doesn't apply the right security
> settings:
>
> objFSO.CreateFolder "\\SERVER\data$\" & strUserName
>
> strFolder = "\\SERVER\data$\" & strUserName
>
> strXcacls = "Xcacls " & strFolder & " /C /P system:f ""Domain
> Admins"":f " & strUserName & ":M /Y"
>
> WshShell.Run strXcacls, 0
>
>
> It doesn't give any errormessages when run. Can anybody see what I
> have missed?
>
> Additionally, I forgot to assign logon-script to some of the groups of
> accounts I created - anybody know of a way to assign a logon-script
> for accounts that doesn't have one?
>
> Kind regards

Re: Trouble with xcacls in usercreation by Richard

Richard
Mon Sep 03 09:43:54 PDT 2007


"Unhappy MacbbokOwner" <noob@invalid.not> wrote in message
news:fbh8bb$g3l$1@news.net.uni-c.dk...
> Hi -
>
> I have made a user-creation script (by taking bits and pieces from various
> sources, which works nicely, except for one thing - this code creates the
> homefolders nicely, but doesn't apply the right security settings:
>
> objFSO.CreateFolder "\\SERVER\data$\" & strUserName
>
> strFolder = "\\SERVER\data$\" & strUserName
>
> strXcacls = "Xcacls " & strFolder & " /C /P system:f ""Domain Admins"":f
> " & strUserName & ":M /Y"
>
> WshShell.Run strXcacls, 0
>
>
> It doesn't give any errormessages when run. Can anybody see what I have
> missed?
>
> Additionally, I forgot to assign logon-script to some of the groups of
> accounts I created - anybody know of a way to assign a logon-script for
> accounts that doesn't have one?
>
> Kind regards

I use code similar to below:
==========
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " _
& strHomeFolder & " /T /E /C /G " & strNetBIOSDomain _
& "\" & strNTName & ":F", 2, True)
If (intRunError <> 0) Then
Wscript.Echo "Error assigning permissions for user " _
& strNTName & " to home folder " & strHomeFolder
End If
=========
I use %comspec% /c so the command will work properly with any OS. I suspect
you are missing the echo of the "Y" to the command, although I cannot recall
if this is need with xcacls, or only cacls. I assign the permissions to a
trustee in the form:

MyDomain\UserName

where MyDomain is the NetBIOS name of the domain and UserName is the NT name
of the user (also called the "pre-Windows 2000 logon name", or
sAMAccountName). Similar syntax is necessary for domain groups:

MyDomain\GroupName

where GroupName is the NetBIOS name of the group. I also run the command
with options so I get an error code back, which I can test to see if there
was an error.

You command resolves to:

Xcacls /C /P system:f "Domain Admins":f :M Y

I don't believe the trustee "Domain Admins" will be understood without the
domain name. I'm not sure about "system". If the trailing " Y" means to
answer "Yes" to the prompt, then the "Echo Y|" in my example is not needed.
I would try:
=========
strXcacls = ""%COMSPEC% /c Xcacls " & strFolder _
& " /C /P system:f ""MyDomain\Domain Admins"":f MyDomain\" _
& strUserName & ":M Y"

intError = WshShell.Run(strXcacls, 2, True)
If (intError <> 0) Then
Wscript.Echo "Error assigning permissions with the command: " strXcacls
End If
=========
This assumes that "system:f" is correct and we don't need to echo the "Y" to
the command. This will return error information if the Xcacls command raises
an error.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Trouble with xcacls in usercreation by Richard

Richard
Mon Sep 03 09:58:58 PDT 2007


"Unhappy MacbbokOwner" <noob@invalid.not> wrote in message
news:fbh8bb$g3l$1@news.net.uni-c.dk...
> Hi -
>
> I have made a user-creation script (by taking bits and pieces from various
> sources, which works nicely, except for one thing - this code creates the
> homefolders nicely, but doesn't apply the right security settings:
>
> objFSO.CreateFolder "\\SERVER\data$\" & strUserName
>
> strFolder = "\\SERVER\data$\" & strUserName
>
> strXcacls = "Xcacls " & strFolder & " /C /P system:f ""Domain Admins"":f
> " & strUserName & ":M /Y"
>
> WshShell.Run strXcacls, 0
>
>
> It doesn't give any errormessages when run. Can anybody see what I have
> missed?
>
> Additionally, I forgot to assign logon-script to some of the groups of
> accounts I created - anybody know of a way to assign a logon-script for
> accounts that doesn't have one?
>
> Kind regards

In addition, I have an example VBScript program that assigns values to the
userProfile attribute for users in bulk from the information in a
spreadsheet. The program is linked here:

http://www.rlmueller.net/UpdateUserProfile2.htm

This example can be easily modified to update any single-valued string
attribute of user objects, like the scriptPath attribute (which is the
attribute that corresponds to the logon script field on the "Profile" tab of
user properties in ADUC). Just replace all instances of "profilePath" in the
program with "scriptPath". The input spreadsheet should have user NT names
(sAMAccountNames) in the first column and logon script in the second column.

If instead you are assigning the same value for everyone for scriptPath, and
you want to search AD for all accounts that do not have a value assigned to
scriptPath, you could use ADO to retrieve the Distinguished Names of all
such users. See this link for details on using ADO in a VBScript program:

http://www.rlmueller.net/ADOSearchTips.htm

In this case, using the syntax from this link, your filter to retrieve users
would be:

strFilter = "(&(objectCategory=person)(objectClass=user)(!scriptPath=*))"

The "!" is the NOT operator, "&" is the AND operator, and "*" is a wild
card. This returns all users with no value assigned to scriptPath. Since ADO
cannot be used to modify objects in AD, you would retrieve Distinguished
Name for all such users so you can bind to each object and assign the
hardcoded value for scriptPath. You would use:

strAttributes = "distinguishedName"

then in the loop where you enumerate the recordset, you would bind to each
user and assign the scriptPath:
===============
strScript = "MyLogon.vbs"

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF

' Retrieve values.
strDN = adoRecordset.Fields("distinguishedName").Value

' Bind to the user object.

Set objUser = GetObject("LDAP://" & strDN)

' Assign logon script.

objUser.scriptPath = strScript

' Save changes.

objUser.SetInfo

' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop


--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Trouble with xcacls in usercreation by Unhappy

Unhappy
Thu Sep 13 09:22:45 PDT 2007

Hello Richard.

Thank you very much for your input, which helped me out - using code
similar to what you suggested, I finally got it to work by setting
permissions for one user at a time; which I find a bit strange, I
haven't had problems setting permissions for more users at once using
other methods than VBscript.

Again, Thank you very much!

Richard Mueller [MVP] skrev:

> I use code similar to below:
> ==========
> intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " _
> & strHomeFolder & " /T /E /C /G " & strNetBIOSDomain _
> & "\" & strNTName & ":F", 2, True)
> If (intRunError <> 0) Then
> Wscript.Echo "Error assigning permissions for user " _
> & strNTName & " to home folder " & strHomeFolder
> End If
> =========