Script Center > Scripting Forums > The Official Scripting Guys Forum! > logon Script to copy folders to users desktop
Ask a questionAsk a question
 

Questionlogon Script to copy folders to users desktop

  • Wednesday, November 04, 2009 4:05 PMdalho Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello all.
    I have a logon script that needs help.

    'copy folder1 shortcuts folder to desktop
      Dim strDesktopFolder
      Set objShell = WScript.CreateObject("WScript.Shell")
      strDesktopFolder = objShell.SpecialFolders("Desktop")
      Set objShell = CreateObject("Shell.Application")
      Set objFolder = objShell.NameSpace(strDesktopFolder)

      objFolder.CopyHere "\\server\share\folder1", &H10&

    It works great, but now we want the script to check to see if that folder exists and if it does don't copy.

    Can any one help.?
    Thanks,

All Replies

  • Friday, November 06, 2009 5:51 PMRichard MuellerMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    The FileSystemObject has a FolderExists method. It also has a CopyFolder method, so you could skip binding to the "Shell.Application" object. For example:
    Option Explicit
    
    Dim objShell, strDesktop, objFSO
    
    ' Retrieve path to desktop.
    Set objShell = CreateObject("Wscript.Shell")
    strDesktop = objShell.SpecialFolders("Desktop")
    
    ' Check if folder exists.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If (objFSO.FolderExists(strDesktop & "\folder1") = False) Then
        ' Copy the folder.
        objFSO.CopyFolder "\\server\share\folder1", strDesktop
    End If
    

    Richard Mueller
    MVP ADSI