Announcement

Collapse
No announcement yet.

Logon script to tidy Desktops and load appropriate Shortcuts

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Logon script to tidy Desktops and load appropriate Shortcuts

    In a effort to bring some stability to our network we have started to implement group policies in AD. We are a charity with around 50 pc, throw have a high turnover of staff but the level always stays around 200 who work as they can.

    The logons on the network are user01, user002, user03 up to user50, since some pc's can have up to 5 people a day logging on using the same profile the desktops can become very messy with all their saved crap.

    I would like to create a logon script that will move all items on the desktop and put them in them filer01/usersmydocuments/username/desktop clean/
    And then Create 3 shortcuts to be placed on the desktop and Quick Launch bar

    The point of this script is to keep the desktops clean and tidy with the relevant shortcuts ready for the next user.

    Any help would be great.

    Kind Regards
    Macr

  • #2
    Re: Logon script to tidy Desktops and load appropriate Shortcuts

    Note, the desktop of an user also show items that are in the allusers desktop folder.
    - http://www.microsoft.com/technet/scr...7/hey0918.mspx
    - http://www.microsoft.com/technet/scr...6/hey0410.mspx

    I missed more details about;
    1. What is - "filer01/usersmydocuments/username/desktop clean/"
    2. What about - "Create 3 shortcuts"
    3. I assummed you meant by 'Items' on desktop; files, links and shortcuts (not subfolders).

    here is an idea
    Code:
    ' http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept07/hey0918.mspx
    
    Const DESKTOP = &H10& 
    
    strUserName = WScript.CreateObject("WScript.Network").UserName 
    
    strShortcut1 = "Name of shortcut1.lnk"
    strShortcut2 = "Name of shortcut2.lnk"
    strShortcut3 = "Name of shortcut3.lnk"
    
    strDestination = "\\filer01\usersmydocuments\" & strUserName & "\desktop clean" 
    
    
    If FolderTree(strDestination) =True Then
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
      Set objShell = CreateObject("Shell.Application") 
      Set objFolder = objShell.Namespace(DESKTOP)
      Set objFolderItem = objFolder.Self
    
    'You can use the variable 'strUserDesktopPath' with 'RoboCopy' (executed with objShell.Run)
      strUserDesktopPath = objFolderItem.path
    'Or, if you just want to MOVE files only from user's desktop, then,
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set colItems = objFolder.Items
      
      For Each objItem in colItems
        strItem = objItem.Path
        strItemName = objItem.name
    
        Select case LCase(strItemName)
          Case LCase(strShortcut1), _
               LCase(strShortcut2), _
               LCase(strShortcut3)
            fso.DeleteFile(strItem)
          Case Else
            fso.MoveFile strItem, _
             ReplaceFile(strDestination, strItemName)
        End Select
    
        strItem = Empty 
      Next
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    End If 
    
    ' Now, (re-)Create the shortcuts on the users's desktop.
    ' examples, 
    ' http://msdn2.microsoft.com/en-us/library/yf7kaky2.aspx 
    ' http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec06/hey1213.mspx 
    '
    ' Next, To add items to the Quick Launch area in the Taskbar,
    ' copy the same shortcuts also to the user's folder: %appdata%\Microsoft\Internet Explorer\Quick Launch
    
    wscript.quit 
    
    
    
    Function ReplaceFile(byval sDest, byval sItem) 
      ReplaceFile = sDest & "\" & sItem 
      If fso.FileExists(ReplaceFile) Then _ 
         fso.DeleteFile ReplaceFile 
    End function 
    
    Function FolderTree(byval sDir)
      Dim strParentPath
      With CreateObject("Scripting.FileSystemObject")
        If Not .FolderExists(sDir) Then
          strParentPath = .GetParentFolderName(sDir)
          If Not .FolderExists(strParentPath) Then FolderTree strParentPath
          If Not .FolderExists(sDir) Then .CreateFolder sDir
        End If 
        FolderTree = .FolderExists(sDir)
      End With
    End Function
    \Rems
    Last edited by Rems; 22nd February 2008, 17:57.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Logon script to tidy Desktops and load appropriate Shortcuts

      Hi Rems,

      Thanks for your reply,

      "filer01/usersmydocuments/username/desktop clean/" Filer01 is our server, there is a folder called usersmydoc witch is where everyones my documnts are stored under their username.



      2.the What about - "Create 3 shortcuts" is to place shotcuts to on the desktop to msword excel ect ??

      3. I assummed you meant by 'Items' on desktop; files, links and shortcuts (not subfolders). yes

      Hope i have been clear.

      Marc

      Comment


      • #4
        Re: Logon script to tidy Desktops and load appropriate Shortcuts

        Thanks,
        Ok, besites the script that cleans the users's desktop, you also need a part in the script that can create the shortcuts on the desktop (and QuicLaunch-shortcuts) for the Office applications.

        This is the code:
        Code:
        '---------------------------------------------------------------
        ' File name: Create_Office_(Quick Launch-)_Shortcuts.vbs
        ' Author: Remco Simons [NL] 2008
        '
        ' http://forums.petri.com/showthread.php?t=21789
        '---------------------------------------------------------------
        
        
        strAppName1 = "Excel.exe"
        ShortcutName1 = "Microsoft Excel"
        
        strAppName2 = "Winword.exe"
        ShortcutName2 = "Microsoft Word"
        
        
        ' the variables fso and WshShell have global scopes  
        Set fso = CreateObject("Scripting.FileSystemObject")
        set WshShell = WScript.CreateObject("WScript.Shell")
        
        ' http://msdn2.microsoft.com/en-us/library/0ea7b5xe(VS.85).aspx?wt.svl=overview
        strLocation = WshShell.SpecialFolders("allusersDesktop")
        
        call CreateShortcut (strLocation, strAppName1, ShortcutName1)
        call CreateShortcut (strLocation, strAppName2, ShortcutName2)
        
        call CreateQuickLaunch (strAppName1, ShortcutName1)
        call CreateQuickLaunch (strAppName2, ShortcutName2)
        
        Wscript.quit
        
        
        Sub CreateShortcut(byval scloc, byval scApp, byval scnm)
           ' http://msdn2.microsoft.com/en-us/library/yf7kaky2(VS.85).aspx
           scnm2 = scnm & ".LNK"
           strAppPath = GetAppPath(scApp)
           If fso.FileExists(strAppPath) Then
              set oShellLink = WshShell.CreateShortcut(scloc & "\" & scnm2)
              oShellLink.TargetPath = strAppPath
              oShellLink.WindowStyle = 1
              oShellLink.IconLocation = strAppPath & ", 0"
              oShellLink.Description = scnm
              oShellLink.Save
           End If
        End sub
        
        Function GetAppPath(byval strApp)
           RegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"
           GetAppPath = WSHShell.RegRead (regkey  & strApp & "\" & "")
        End Function
        
        Sub CreateQuickLaunch(byval scApp, byval scnm)
           strQLFolder = WshShell.SpecialFolders("APPDATA") _
                & "\Microsoft\Internet Explorer\Quick Launch"
           CreateShortcut strQLFolder, scApp, scnm
        End Sub
        Note, the script places the desktop shortcuts in the "allusersDesktop" folder, you can change the location to "Desktop" if you like.


        And now.. just combine the two scripts to just one script.


        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment

        Working...
        X