• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Distribute a folder to network pc's

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
Constant IT Support
Asked:
Constant IT Support
  • 11
  • 9
  • 7
  • +1
1 Solution
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
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
 
Chris DentPowerShell DeveloperCommented:

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
 
Chris DentPowerShell DeveloperCommented:

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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Constant IT SupportAuthor Commented:
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
 
Chris DentPowerShell DeveloperCommented:

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
 
Chris DentPowerShell DeveloperCommented:

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
 
Constant IT SupportAuthor Commented:
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
 
Constant IT SupportAuthor Commented:
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
 
Chris DentPowerShell DeveloperCommented:

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
 
Constant IT SupportAuthor Commented:
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
 
Chris DentPowerShell DeveloperCommented:

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
 
Chris DentPowerShell DeveloperCommented:

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
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
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
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
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
 
fostejoCommented:
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
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
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
 
Chris DentPowerShell DeveloperCommented:

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

Chris
0
 
Constant IT SupportAuthor Commented:
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
 
Chris DentPowerShell DeveloperCommented:

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
 
Constant IT SupportAuthor Commented:
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
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
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
 
Constant IT SupportAuthor Commented:
Concerning the suggestion TechsoEasy: Starting your script gives me the following error:

Line:3
Char: 1
The system cannot find the file specified
0
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
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
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
Starting WHAT script?  You mean within RoboIQ?  

TSE
0
 
Constant IT SupportAuthor Commented:
Excuse me. User Fostjeo posted a Robocopy script above. That script gave me an error.
0
 
Chris DentPowerShell DeveloperCommented:

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
 
fostejoCommented:
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
 
Constant IT SupportAuthor Commented:
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
 
Chris DentPowerShell DeveloperCommented:

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 11
  • 9
  • 7
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now