Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Folder at Login with UserName

Status
Not open for further replies.

youngoz

Programmer
Jun 12, 2004
7
0
0
US
Hey Guys

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.

Thanks in Advance

Sincerely; Oscar
 
Good Morning,


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

Thanks in Advance

Sincerely; Oscar
 
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.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top