Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

copy all contents of a folder to user's desktop VBS Logon Script

Posted on 2009-07-01
5
Medium Priority
?
239 Views
Last Modified: 2012-06-27
Hello, I am looking to copy some links and such to the desktop of my user's computers using a VB logon script.  any ideas?
0
Comment
Question by:OSXaddict
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:astroviper
ID: 24760088
Just change strSource to the folder that contains everything you want to end up on the desktop.

strSource = "E:\test"
 
Const FOF_CREATEPROGRESSDLG = &H0&
Set oShell = CreateObject("WScript.Shell")
ParentFolder = oShell.SpecialFolders("Desktop")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder) 
objFolder.CopyHere strSource & "\*", FOF_CREATEPROGRESSDLG

Open in new window

0
 

Author Comment

by:OSXaddict
ID: 24760490
Thank you! Will this replace the item if it is already on the desktop?
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24760516
See: http://msdn.microsoft.com/en-us/library/bb787866%28VS.85%29.aspx

I just tested it and it works the same as a Windows gui copy. It asks if you want to replace.
0
 

Author Comment

by:OSXaddict
ID: 24763998
is there any way that I can make it force to replace?
0
 
LVL 3

Accepted Solution

by:
astroviper earned 2000 total points
ID: 24764383
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21512937.html

This seems to work.


Set oShell = CreateObject("WScript.Shell")
ParentFolder = oShell.SpecialFolders("Desktop")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oSourceFolder = oFSO.GetFolder("C:\Users\Mike\Downloads\remote admin tools windows 7")
Set oTargetFolder = oFSO.GetFolder(ParentFolder)
 
RecursiveCopy oSourceFolder, oTargetFolder, True
 
Sub RecursiveCopy(ByRef oSource, ByRef oTarget, ByVal bOverWrite)
 
    Dim oFolder, oFile, szPath
 
    For Each oFile In oSource.Files
        szPath = Replace(oTarget.Path & "\" & oFile.Name, "\\", "\")
        If (oFSO.FileExists(szPath) And bOverWrite) Then
            If oFile.DateLastModified > oFSO.GetFile(szPath).DateLastModified Then oFile.Copy szPath, bOverWrite
        ElseIf (oFSO.FileExists(szPath) And Not(bOverWrite)) Then
            'DO NOTHING BECAUSE WE ARE NOT OVERWRITING
        ElseIf Not(oFSO.FileExists(szPath)) Then
            oFile.Copy szPath, bOverWrite
        End If
    Next
 
    For Each oFolder In oSource.Subfolders
        szPath = Replace(oTarget.Path & "\" & oFolder.Name, "\\", "\")
 
        If Not(oFSO.FolderExists(szPath) And bOverWrite) Then
            Set oNewTarget = oFSO.CreateFolder(szPath)
        Else
            Set oNewTarget = oSO.GetFolder(szPath)
        End If
 
        RecursiveCopy oFolder, oTarget, bOverWrite
    Next
 
End Sub

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question