dear vbs-ng, i could not find any help in the wsh-ng; may be you have an
idea:

the following script runs as a logon-script for a w2k3 domain for every
user. it creates a home-folder and should set the permission for the
administrator and the user. the permissions for the administrator are
correct, but the user who started the script during login, does not have any
rights. how can i give the user full right for its own home folder in a
script ?
thanx alot
tim

Dim WshNetwork, LogonUser
Set WshNetwork = WScript.CreateObject("WScript.Network")
Const WAIT_ON_RETURN = True
Const HIDE_WINDOW = 0
Const USER_ROOT_UNC = "\\server01\home$"
Const USER_ROOT_LOCAL = "D:\home"
LogonUser = WshNetwork.UserName
Call CreateHomeFolder(LogonUser)
Sub CreateHomeFolder(strUser)
Dim WshShell, objFS
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFS = CreateObject("Scripting.FileSystemObject")
Call objFS.CreateFolder(USER_ROOT_UNC & "\" & strUser)
Call WshShell.Run("cacls " & USER_ROOT_UNC & "\" & strUser & _
" /e /g Administrators:F", HIDE_WINDOW, WAIT_ON_RETURN)
'--> setting the users permission
Call WshShell.Run("cacls " & USER_ROOT_UNC & "\" & strUser & _
" /e /g " & strUser & ":F", HIDE_WINDOW, WAIT_ON_RETURN)

End Sub

Re: let user change permission on his home-folder by billy

billy
Fri Dec 02 00:10:31 CST 2005

your script presumes that standard "domain users" have full permission
and security rights in \\server01\home$ (must be able to create a
folder and set acl). many domain admins would consider this a mistake,
but all networks are different and you may have a good reason for
having it this way. you use cacls with the /e switch - which edits the
acl instead of replacing it. if this is so then every user in the
domain (including the intended user) will have full access to the
folder and you should not be having any problem. as you are having a
problem, perhaps there is a permission or security issue with your
home$ share. attempt to manually create the folder and set security as
a standard domain user.

if it does work manually, perhaps the script needs a breather between
creating the folder and setting the acl; try adding a half second
sleep. also, cacls will take multiple users with one command; try
combining the last two lines of your sub routine. try this:

Dim WshNetwork, WshShell, objFS, strUser
Const USER_ROOT_UNC = "\\server01\home$"
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")
strUser = WshNetwork.UserName
objFS.CreateFolder(USER_ROOT_UNC & "\" & strUser)
WScript.Sleep 500
WshShell.Run("cacls " & USER_ROOT_UNC & "\" & strUser & _
" /g Administrators:F /g " & strUser & ":F",0,True)