I would like to create a Log In script that creates a folder on the server when the user first Logs In. If the Folder already created then to Exit otherwise create the folder with the username.
I found a script to create the folder and I have modified it. This script create a folder in the server\User\"UserName". If the Folder is already created then it exists otherwise it creates the folder.
Dim objNet,objFSO, objFolder, strDirectory,test
On Error Resume Next
Set objNet = CreateObject("WScript.NetWork")
Set objNet = CreateObject("WScript.NetWork")
If Err.Number <> 0 Then 'If error occured then display notice
MsgBox "Create User Folder on Log On." & vbCRLF &_
"Do not press ""No"" If your browser warns you."
Document.Location = "UserInfo.html"
'Place the Name of the document.
'It will display again
End if
Dim UserName
'Get the Current User Name
UserName = objNet.UserName
strDirectory = "\\10.1.2.34\users\" & UserName
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Note If..Exists. Then, Else ... End If construction
If objFSO.FolderExists(strDirectory) Then
'Open the Folder if it's already created
'Set objFolder = objFSO.GetFolder(strDirectory)
'WScript.Echo strDirectory & " already created "
WScript.Quit
ELSE
Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
Set objNet = Nothing 'Destroy the Object to free the Memory
End If
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" &" " & strDirectory & "\" )
Else
WScript.echo "VBScript Error: " & err.number
End If
WScript.Quit
Set objNet = Nothing 'Destroy the Object to free the Memory
I would point out that you are missing an integral part of this. Nowhere in this script are you setting security on the folder, so any other user will have access to the folder, plus the folder will only be inherriting security rights for the volume in which it was created.
You should look at using XCACLs and vbscript to assign permissions to the folder.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.