Solved

Distribute a folder to network pc's

Posted on 2006-07-05
32
292 Views
Last Modified: 2008-01-09
Hi,

On our SBS2003 server we have a program which updates quite often. When this program updates a user manually has to copy a source folder to it's own harddisk.

I'd like to use the startupscript or maybe a startup policy that does the following:

1. Check tho see if there's a more recent version on the server (maybe by the folder's data, or executable's version)
2. Compare that to the version that's locally installed
3. If a newer version exists on the server copy the whole source folder to the harddisk, OR
4. If the version on the server is the same, do nothing

Please advise which way to accomplish this.
0
Comment
Question by:Constant IT Support
  • 11
  • 9
  • 7
  • +1
32 Comments
 
LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 17047946
This probably can be accomplished quite easily with a VBScript... Since there are a lot of VBScript experts in that TA, I'd suggest that you post a pointer question over in http:Visual_Basic

You can do that by using the new pointer question wizzard at:  http://www.ee-stuff.com/Expert/pointer/?

Jeff
TechSoEasy
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17049065

Hi there,

I have VbScript functions that do both of those things. For updating by version it assumes the version is a number; i.e. 1.2.345

You would use them like this:

Dim objFileSystem

' We need this one:

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

' Update something by the Date

UpdateByDate "C:\Program Files\Something\SomeFile.dll", "\\YourServer\SomeShare\SomeFile.dll"

' Update something by Version

UpdateByVersion "C:\Program Files\Something\SomeFile.dll", "\\YourServer\SomeShare\SomeFile.dll"

'
' Subroutines
'

Sub UpdateByDate(strSource, strDestination)

      ' Updates a file based on the Modified date

      Dim objSource, objDestination
      Dim datSource, datDestination

      If objFileSystem.FileExists(strSource) Then
            Set objSource = objFileSystem.GetFile(strSource)
            datSource = objSource.DateLastModified

            If objFileSystem.FileExists(strDestination) Then
                  Set objDestination = objFileSystem.GetFile(strDestination)
                  datDestination = objDestination.DateLastModified
                  Set objDestination = Nothing
            Else
                  datDestination = CDate("1/1/1960")
            End If

            If datSource > datDestination Then
                  On Error Resume Next
                  objSource.Copy strDestination, True
                  On Error Goto 0
            End If
            Set objSource = Nothing
      End If
End Sub

Sub UpdateByVersion(strSource, strDestination)

      ' Updates a file by Numeric Version Number

      Dim objSource
      Dim strSrcVersion, strDstVersion
      Dim dblSrcVersion, dblDstVersion

      If objFileSystem.FileExists(strSource) Then
            Set objSource = objFileSystem.GetFile(strSource)
            strSrcVersion = objFileSystem.GetFileVersion(strSource)
            dblSrcVersion = CDbl(Replace(strSrcVersion, ".", ""))

            If objFileSystem.FileExists(strDestination) Then
                  strDstVersion = objFileSystem.GetFileVersion(strDestination)
                  dblDstVersion = CDbl(Replace(strDstVersion, ".", ""))
            Else
                  dblDstVersion = 1
            End If

            If dblSrcVersion > dblDstVersion Then
                  On Error Resume Next
                  objSource.Copy strDestination, True
                  On Error Goto 0
            End If
            Set objSource = Nothing
      End If
End Sub
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17049082

Erm sorry about this.. it really does help if I write my examples the right way around.. You still need the subroutines... but the main bit of code looks like this:

Dim objFileSystem

' We need this one:

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

' Update something by the Date

UpdateByDate "\\YourServer\SomeShare\SomeFile.dll", "C:\Program Files\Something\SomeFile.dll"

' Update something by Version

UpdateByVersion "\\YourServer\SomeShare\SomeFile.dll", "C:\Program Files\Something\SomeFile.dll"
0
 

Author Comment

by:Constant IT Support
ID: 17049218
Thanks. Will have to test it out, since i'm not an experienced VBscript user.

But the main goal, copy a folder from a network share \\server\applications\programA to local disk c:\programA can be accomplished with your script?

edit/Save this script as login.vbs and implement it in our login policy?
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17049289

Yep, login.vbs would do quite nicely. You can either set that up as a Policy or as a script in the user profiles.

When you're copying an entire folder you run into a bit of a problem basing things on the date or version (since neither is going to be all that useful on a folder).

Is there a particular file you want to base the move on within the folder? If so I'll just edit the subroutines so they copy the entire folder.

Chris
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17049428

It could be simplified a lot if you don't mind just overwriting the files each time someone logs on, the disadvantage of that is that if it's a big file you add a lot of extra time to whatever is happening during logon.

This would just copy over the entire folder; nice and easy, but none of the checking for dates so it would run every time:

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSystem.GetFolder("\\server\applications\programA\")
objFolder.Copy "c:\", True

Chris
0
 

Author Comment

by:Constant IT Support
ID: 17049749
I deleted the code for the date, because the file has a usefull version number as a property of the .exe. My code is now as follows. But i'd like it to copy the whole MyProgram folder to the local pc's harddisk:

Dim objFileSystem

' We need this one:

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

' Update something by Version

UpdateByVersion "\\server\MyProgram\MyProgram.exe", "C:\MyProgram\MyProgram.exe"

'
' Subroutines
'

Sub UpdateByVersion(strSource, strDestination)

     ' Updates a file by Numeric Version Number

     Dim objSource
     Dim strSrcVersion, strDstVersion
     Dim dblSrcVersion, dblDstVersion

     If objFileSystem.FileExists(strSource) Then
          Set objSource = objFileSystem.GetFile(strSource)
          strSrcVersion = objFileSystem.GetFileVersion(strSource)
          dblSrcVersion = CDbl(Replace(strSrcVersion, ".", ""))

          If objFileSystem.FileExists(strDestination) Then
               strDstVersion = objFileSystem.GetFileVersion(strDestination)
               dblDstVersion = CDbl(Replace(strDstVersion, ".", ""))
          Else
               dblDstVersion = 1
          End If

          If dblSrcVersion > dblDstVersion Then
               On Error Resume Next
               objSource.Copy strDestination, True
               On Error Goto 0
          End If
          Set objSource = Nothing
     End If
End Sub
0
 

Author Comment

by:Constant IT Support
ID: 17049760
I don't just want to copy it everytime someone logs on. By doing that, 50 users would have to copy 100mb to their harddisk each morning..
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17049898

That's understandable... This version below has a few alterations... it still bases everything on the file version, but it has an additional field to pass through - the destination folder. It's done like that purely because it's the easiest way to get the destination, if it's not acceptable that way then it is possible to rip the destination path from the destination file name itself.


Dim objFileSystem

' We need this one:

Set objFileSystem = CreateObject("Scripting.FileSystemObject")

' Update something by Version

UpdateByVersion "\\server\MyProgram\MyProgram.exe", "C:\MyProgram\MyProgram.exe", "C:\MyProgram\"

'
' Subroutines
'

Sub UpdateByVersion(strSource, strDestination, strDestinationFolder)

      ' Updates a file by Numeric Version Number

      Dim objSource, objSourceFolder
      Dim strSrcVersion, strDstVersion
      Dim dblSrcVersion, dblDstVersion

      If objFileSystem.FileExists(strSource) Then
            Set objSource = objFileSystem.GetFile(strSource)
            strSrcVersion = objFileSystem.GetFileVersion(strSource)
            dblSrcVersion = CDbl(Replace(strSrcVersion, ".", ""))

            If objFileSystem.FileExists(strDestination) Then
                  strDstVersion = objFileSystem.GetFileVersion(strDestination)
                  dblDstVersion = CDbl(Replace(strDstVersion, ".", ""))
            Else
                  dblDstVersion = 1
            End If

            If dblSrcVersion > dblDstVersion Then
                  On Error Resume Next
                  Set objSourceFolder = objFileSystem.GetFolder(objSource.Path)
                  objSourceFolder.Copy strDestinationFolder, True
                  Set objSourceFolder = Nothing
                  On Error Goto 0
            End If
            Set objSource = Nothing
      End If
End Sub
0
 

Author Comment

by:Constant IT Support
ID: 17050013
Thanks. Going to test it now. Could the script be improved by a dialog to the user: "New version detected, please wait while copying files"
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17050373

It's possible to pop up a message box to say that. But progress dialogues and such aren't possible in VbScript unfortunately - and it wouldn't be possible to make the message automatically disappear after the file has copied.

Chris

0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17050435

If we're going to add a message then it would be best here:

          If dblSrcVersion > dblDstVersion Then
               MsgBox("New version detected, please wait while copying files", VbOkayOnly + VbInformation, "Copying")
               On Error Resume Next
               Set objSourceFolder = objFileSystem.GetFolder(objSource.Path)
               objSourceFolder.Copy strDestinationFolder, True
               Set objSourceFolder = Nothing
               On Error Goto 0
          End If

Which will display a little message with an OK button and the "i" in a speech bubble.

Chris
0
 
LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 17050781
Since the server isn't rebooted all that often (I've got some SBS's that don't get rebooted unless a Windows Update forces it... which can be as long as 5 months).. I'd suggest that you use a scheduled task to run the script at a pre-determined interval.

Jeff
TechSoEasy
0
 
LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 17050894
Sorry... I just saw the title of the question again... and thought it was perhaps something that was being replaced on the server.

FYI, if you are going to make it a login item... create a CALL line in the \\SBSSERVER\NETLOGON\SBS_LOGIN_SCRIPT.bat file and place your VBScript in that same directory.

Jeff
TechSoEasy
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 10

Expert Comment

by:fostejo
ID: 17054837
DennisFeiken,

While the VBScripts above will certainly work, this really sounds like an ideal job for something like RoboCopy, one of the Microsoft Resource Kit tools, available at http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

You could fire RoboCopy from an extremely simple VBScript if necessary and let it do all the hard work - from many years experience of using it I can say it's a very, very good utility and, as it's name suggests, very Robust being able to intelligently handle those odd occasions where the target files can't be updated because they're in use etc.

To synchronise a whole folder for instance you'd could use a command similar to:

RoboCopy \\MyServer\MyShare\MyFolder C:\Target\MyTargetFolder /MIR /W:2 /R:2 /LOG:synclog.log

This would ensure that the folders are totally identical (ie. MIRrored) but will only copy the files that are different by date/time/size, log it's actions to a file called 'SyncLog.txt' and retry to copy files which are currently in use on the target computer twice with a pause of 2 seconds in between each try... That's just touching upon its functionality, you can also..  copy files based on whether they're older, newer, copy their security, move them rather than copy, exclude specific filenames or files  younger or older than a specified number of days, control the bandwidth the copy uses, show an ETA for each file and do 'trial' runs ... to name a few of the more common functions.

A potential VBScript using RoboCopy would, at its simplest, look like:

Dim oWSH
Set oWSH = CreateObject("Wscript.Shell")
oWsh.Run "RoboCopy \\MyServer\MyShare\MyFolder C:\Target\MyTargetFolder /MIR /W:2 /R:2 /LOG:synclog.log"

If you do decide to use RoboCopy, please ensure you have a good look at the help so you understand what the parameters do, also always ensure you take advantage of the /L(ist only) parameter! - please ask if you're unsure.

Hope that helps..
0
 
LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 17055107
That's a good idea... I would think that it doesn't really matter if it's changed or not... no reason to check the version.. it can copy anyhow.

Jeff
TechSoEasy
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17056774

Well except that it's 100Mb that would be pretty painful for mass-copying every morning.

Chris
0
 

Author Comment

by:Constant IT Support
ID: 17057114
adding this line:

MsgBox("New version detected, please wait while copying files", VbOkayOnly + VbInformation, "Copying")

results in an VBscript error: cannot use parentheses when calling a sub
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17057227

Oops sorry... took them out in my test bit and left them in there... change it to:

MsgBox "New version detected, please wait while copying files", VbOkayOnly + VbInformation, "Copying"

And it'll stop complaining.

Chris
0
 

Author Comment

by:Constant IT Support
ID: 17080651
Chris-Dent,

Was able to test your script today. Unfortunateley it doesn't work yet. It does give me the dialog, but then I have the idea that nothing is being copied from the server share. The message 'new version detected' is also being displayed everytime. I guess the version is being detected correctly only the folders contents is not being overwritten by the data from the server. Could you check your script please?

BTW havent started trying the robocopy suggestion.
0
 
LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 17080881
I don't know why I didn't think of this first, but I was just helping someone to get Active Directory reports and telling them how much I like adventnet.com's tools... especially because they are usually free in the SBS realm.

Their RoboIQ would work perfectly for this:  http://manageengine.adventnet.com/products/roboiq/server-automation-triggers-actions.html#Actions

It offers folder and file synchronization!

Jeff
TechSoEasy
0
 

Author Comment

by:Constant IT Support
ID: 17080893
Concerning the suggestion TechsoEasy: Starting your script gives me the following error:

Line:3
Char: 1
The system cannot find the file specified
0
 
LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 17080912
Even if the free version wouldn't work the paid version for what I think you want to do is under $300.00.

Jeff
TechSoEasy
0
 
LVL 74

Expert Comment

by:Jeffrey Kane - TechSoEasy
ID: 17080984
Starting WHAT script?  You mean within RoboIQ?  

TSE
0
 

Author Comment

by:Constant IT Support
ID: 17081186
Excuse me. User Fostjeo posted a Robocopy script above. That script gave me an error.
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 150 total points
ID: 17099166

We just need to capture the error message - or at least see if it's throwing one up. So in this one the "On Error Resume Next" line is commented out which will make the script popup an error message if it's having problems:

Sub UpdateByVersion(strSource, strDestination, strDestinationFolder)

     ' Updates a file by Numeric Version Number

     Dim objSource, objSourceFolder
     Dim strSrcVersion, strDstVersion
     Dim dblSrcVersion, dblDstVersion

     If objFileSystem.FileExists(strSource) Then
          Set objSource = objFileSystem.GetFile(strSource)
          strSrcVersion = objFileSystem.GetFileVersion(strSource)
          dblSrcVersion = CDbl(Replace(strSrcVersion, ".", ""))

          If objFileSystem.FileExists(strDestination) Then
               strDstVersion = objFileSystem.GetFileVersion(strDestination)
               dblDstVersion = CDbl(Replace(strDstVersion, ".", ""))
          Else
               dblDstVersion = 1
          End If

          If dblSrcVersion > dblDstVersion Then
               ' On Error Resume Next
               Set objSourceFolder = objFileSystem.GetFolder(objSource.Path)
               objSourceFolder.Copy strDestinationFolder, True
               Set objSourceFolder = Nothing
               On Error Goto 0
          End If
          Set objSource = Nothing
     End If
End Sub
0
 
LVL 10

Expert Comment

by:fostejo
ID: 17102957
DennisFeiken,

The three line 'script' in my initial response is probably failing because it can't find the RoboCopy executable.

After downloading, I'd suggest copying Robocopy.exe into a directory on the path, or, preferably, straight into the Windows directory so anything can find it..

Hope that helps..

0
 

Author Comment

by:Constant IT Support
ID: 17166882
ChrisDent,

The error that's given is the following. Line 39,  'cannot find path'. Code: 800A004C

line 39:

Set objSourceFolder = objFileSystem.GetFolder(objSource.Path)

0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 17182260

Ahh sorry, I choose the wrong attribute. Change:

Set objSourceFolder = objFileSystem.GetFolder(objSource.Path)

To:

Set objSourceFolder = objFileSystem.GetFolder(objSource.ParentFolder)

And it should work (leave "On Error Resume Next" commented out for now so we can make sure).

Chris
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Written by Glen Knight (demazter) as part of a series of how-to articles. Introduction One of the biggest consumers of disk space with Small Business Server 2008(SBS) is Windows Server Update Services, more affectionately known as WSUS. For t…
The SBS 2011 release date (RTM) is supposed to be around Christmas, 2011.  This article is a compilation of my notes -- things I have learned first hand.  The items are in a rather random order, but I think this list covers most of what is new and d…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now