All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help needed with folder creation and permission Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I would like to use a logon script that will create a folder for a user on a different server, if that folder doesn't already exist. It will also assign proper permissions to that folder. I have the following script, but it's not working. Any suggestions?
Set objNet = WScript.CreateObject("WScript.Network") Set FSO = CreateObject("scripting.filesystemobject") sUserName = objNet.UserName sDomainName= objNet.UserDomain folderToCheckFor = "\\clt-ftptest\tyler-ftp\users" & sUserName If (FSO.FolderExists(folderToCheckFor)) = False Then FSO.CreateFolder(folderToCheckFor) Set WshShell = WScript.CreateObject("WScript.Shell") Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\" & sUserName & ":F",2,True) Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\Domain Admins:F",2,True) Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\GLOBAL_SUPERVISORS:F",2,True) Set WshShell = nothing End If Set FSO = nothing Set objNet = nothing
I logon using the test user's name and I get no errors. It just doesn't create the folder If I just double click on the script that I have on the domain controller it gives me the error: Line: 9 char: 5 Error: Permission Denied Code: 800A0046 Source: Microsoft VBScript runtime error
I've given the user write permissions on the Users folder, though. Do they need more permissions? Forgive me, I'm new.
I would like to use a logon script that will create a folder for a user on a different server, if that folder doesn't already exist. It will also assign proper permissions to that folder. I have the following script, but it's not working. Any suggestions?
Set objNet = WScript.CreateObject("WScript.Network") Set FSO = CreateObject("scripting.filesystemobject") sUserName = objNet.UserName sDomainName= objNet.UserDomain folderToCheckFor = "\\clt-ftptest\tyler-ftp\users" & sUserName If (FSO.FolderExists(folderToCheckFor)) = False Then FSO.CreateFolder(folderToCheckFor) Set WshShell = WScript.CreateObject("WScript.Shell") Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\" & sUserName & ":F",2,True) Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\Domain Admins:F",2,True) Call WshShell.Run("CACLS " & folderToCheckFor & " /T /E /C /G " & sDomainName & "\GLOBAL_SUPERVISORS:F",2,True) Set WshShell = nothing End If Set FSO = nothing Set objNet = nothing
Seems you're calling the wrong path in your script:
Your trying to change the permissions on \\clt-ftptest\tyler-ftp\users folder that I'm guessing your user doesn't have rights. You need to add after folderToCheckFor the users folder (sUserName)
I also had problems with using the CACLS command through VBS but found an online doc that helped. If you also have probs try changing the CACLS line to mirror
objShell.run "cmd /c echo y|CACLS " and then all your paths and permissions.