General help and info provided by Helewix.com Webmasters

« Manage Local Groups using VBSDetermine the SCHEMA MASTER FSMO holder in your Forest »

Logon VB Script to Create folder with shortcuts on Users Desktop and File Server

09/22/10 | by Helewix.com Webmaster [mail] | Categories: Scripting

Plutus Hosting - Quality and Affordable Website and Email Hosting

The following script will:
1. Check your File and Print server to make sure that the user has got a home folder created on \\ServerName\userdata$\ using the usrName that we have declared in the first part of the code.
2. If the folder does not exist it will create the following folders:
a. Create a folder using the username
b. Now we will create a folder called "My Documents" inside the Username folder and for the purpose of this test we will also create and additional folder called "Personal Data"
3. Next it will assign rights to the user (Modify Rights) and Domain Admins (Full Control)
4. Now after the server side has been sorted, we can start creating shortcuts to the shares on the users desktop
5. Ones again we will first check to see if the folder already exist on the user's Desktop, if not we will create it with the shortcuts.
6. If the previous script identified no documents on the user's desktop it will create a folder called "Company Documents"
7. Inside this folder it will create 2 shortcuts, one that points directly to the "My Documents" on the server and the other pointing to the "Personal Data"

Plutus Hosting - Quality and Affordable Website and Email Hosting

You can also download the code below. Please let me know if this helped, any feedback will be appreciated.

Dim objFSO, objFolder, strDirectory, WshS, WSHSell, intRunError, objShell, strUser
Set WshS = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

'Expand Environment
'Create const's to spare time and place
usrProfile = WshS.ExpandEnvironmentStrings("%UserProfile%")
usrName = WshS.ExpandEnvironmentStrings("%UserName%")

' Message to prove my string contains the path to my profile
strProfilepath = usrProfile

' CREATE FOLDERS ON USER SHARE IF IT DOES NOT EXIST AND ASSIGN RIGHTS
strDirectory = "\\ServerName\userdata$\" & usrName

'WScript.Echo "username is " & strDirectory
' Create FileSystemObject. So we can apply .createFolder method
Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.CreateFolder(strDirectory)
Set objFolder = objFSO.CreateFolder(strDirectory & "\My Documents")
Set objFolder = objFSO.CreateFolder(strDirectory & "\Personal Data")
End If

Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strDirectory) Then
' Assign user permission to home folder.
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " & strDirectory & " /t /c /g " & usrName & ":C ""Domain Admins"":F", 2, True)

If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " & strUser & " to home folder " & strDirectory
End If
End If


' CREATE FOLDER AND LINKS ON USERS DESKTOP
strDirectory = strProfilepath & "\Desktop\Company Documents"
' Create FileSystemObject. So we can apply .createFolder method
Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FolderExists(strProfilepath & "\Desktop\Company Documents") Then
Set objFolder = objFSO.CreateFolder(strDirectory)
End If
' WScript.Echo "Just created " & strDirectory

set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")

strLink = strDesktop & "\Company Documents" & "\My Documents.lnk"
set oShellLink = WshShell.CreateShortcut(strLink)
oShellLink.TargetPath = "\\ServerName\userdata$\%username%\My Documents"
oShellLink.Description = "My Documents"
oShellLink.WorkingDirectory = "\\ServerName\userdata$\%username%\My Documents"
oShellLink.Save

strLink2 = strDesktop & "\Company Documents" & "\Personal Data.lnk"
set oShellLink2 = WshShell.CreateShortcut(strLink2)
oShellLink2.TargetPath = "\\ServerName\userdata$\%username%\Personal Data"
oShellLink2.Description = "Personal Data"
oShellLink2.WorkingDirectory = "\\ServerName\userdata$\%username%\Personal Data"
oShellLink2.Save

Download Script: Helewix.com - CreateFolders-and-Links

Plutus Hosting - Quality and Affordable Website and Email Hosting

Permalink

Trackback address for this post

This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)
General help and info provided by Helewix.com Webmasters
May 2012
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Blogger Rating

Ads

Plutus Hosting - Quality and Affordable Website and Email Hosting
usafis
Loanfinder SA
AreYouInterested

WiCount

Listing4me

MarisIT

Search

Flag Counter

free counters

XML Feeds

powered by b2evolution free blog software