+ Post New Thread
Results 1 to 14 of 14
Scripts Thread, Create a VB Script to force SyncToy to run on log off/on in Coding and Web Development; I am trying to create a script to run at log off and also log on. The script is to ...
  1. #1
    Kyle's Avatar
    Join Date
    Jan 2006
    Posts
    972
    Thank Post
    91
    Thanked 14 Times in 13 Posts
    Rep Power
    21

    Create a VB Script to force SyncToy to run on log off/on

    I am trying to create a script to run at log off and also log on. The script is to be used to sync files on a laptop users. I have a group of students who have been given a pool of laptop s to be used in some government scheme. I want them to be able to have a local account on the laptop so they can log on while off the network ie, at home, library etc. I want their My Documents on the network to be synced with their My Documents of the local user. The laptop will be assigned to one person only.

    I have been playing with Microsoft Sync Toy and it will do exactly what I want without the need to configure some new OU and GPO. What I would like is a script (VB) to run when the user logs on and then when they log off to automatically sync the files. I found a bit of software called ‘Last Chance’ that’s does but I want a script but have no VB writing experience. The last Chance software calls the Synctoy.exe to run it and then it runs with a “-R2 parameter to run all the paired folders.

    So it runs the command C:\Program Files\Microsoft\SyncToy\SyncToy.exe
    With the Parameter "C:\Program Files\Microsoft\SyncToy\SyncToy.exe" –R
    In the working Directory of "C:\Program Files\Microsoft


    Can anybody put this in a VB script for me to get this to run on log on and log off.

  2. #2

    Join Date
    Nov 2007
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Create a VB Script to force SyncToy to run on log off/on

    The easiest thing to do would be to use a .bat file (only one line needed).

    If, however, you are enamored with the sleek beauty of VB script (and who isn't?) then the following should work:

    strCommandLine = "C:\Program Files\Microsoft\SyncToy\SyncToy.exe –R"
    Set objWshShell = WScript.CreateObject("WScript.Shell")
    objWshShell.Exec(strCommandLine)

    If that does not work try replacing the first line with the following:
    strCommandLine = chr(34) & "C:\Program Files\Microsoft\SyncToy\SyncToy.exe" & chr(34) & " –R"

    Copy the lines into notepad and save it as something.vbs

    Let everyone know if that does not work or if you have questions.
    Have a great day.

  3. #3

    maniac's Avatar
    Join Date
    Feb 2007
    Location
    Kent
    Posts
    3,037
    Thank Post
    209
    Thanked 425 Times in 306 Posts
    Rep Power
    144

    Re: Create a VB Script to force SyncToy to run on log off/on

    Quote Originally Posted by Zabu
    The easiest thing to do would be to use a .bat file (only one line needed).

    If, however, you are enamored with the sleek beauty of VB script (and who isn't?) then the following should work:
    Yay!! Someone else who's a fan of VB scripts, I have lots of them all over my network doing various things, much slicker than a batch file, even if there is a few more lines of code sometimes!

    Mike.

  4. #4
    Kyle's Avatar
    Join Date
    Jan 2006
    Posts
    972
    Thank Post
    91
    Thanked 14 Times in 13 Posts
    Rep Power
    21

    Re: Create a VB Script to force SyncToy to run on log off/on

    Hi Zabu,


    I have tried both ways you posted and can't seem to get it to work fully. The script runs either manually or through GPO but just opens Synctoy and does not do a automated 'Run@ even though the -R option is in the script.


    I have now created a Short Cut to Sync Toy and edited the shortcut path by adding the "-R2 option and it seems to work.


    Any thoughts on why the VB does not fully automate the process?

  5. #5

    Join Date
    Apr 2006
    Location
    Hertfordshire
    Posts
    69
    Thank Post
    2
    Thanked 3 Times in 3 Posts
    Rep Power
    17

    Re: Create a VB Script to force SyncToy to run on log off/on

    Don't you need to tell SyncToy which "job" to run?

    Like...

    C:\Program Files\Microsoft\SyncToy\SyncToy.exe –R "MyFolderPair"

    There is also a file installed with SyncToy called SyncToyEngine.dll. This does all the logic for SyncToy which is .net 2.0....so all you funky coders out there can call synctoy with with .net apps.

  6. #6
    Kyle's Avatar
    Join Date
    Jan 2006
    Posts
    972
    Thank Post
    91
    Thanked 14 Times in 13 Posts
    Rep Power
    21

    Re: Create a VB Script to force SyncToy to run on log off/on

    Will try that.

  7. #7

    Join Date
    Nov 2007
    Location
    Chicago, IL
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Create a VB Script to force SyncToy to run on log off/on

    Hey keep us up to date on this thing! because i am a network admin at a company and i would like to make a similar scripts so when people log on it syncs to their domain folder and when they log off it syncs again. this way they arnt pulling so much bandwidth off our main file server.

    I know offline folders works the same somewhat but still would like a different alternative to show the boss.

  8. #8

    Join Date
    Nov 2007
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Create a VB Script to force SyncToy to run on log off/on

    Hi Kyle,
    This was bugging me so I downloaded SyncToy and tried it out. Acrolite is correct, you do need the job name for it to run.

    strCommandLine = "C:\Program Files\Microsoft\SyncToy\SyncToy.exe –R MyFoldersTest"
    Set objWshShell = WScript.CreateObject("WScript.Shell")
    objWshShell.Exec(strCommandLine)

    The addition of the job name does the trick.

  9. #9

    Join Date
    Nov 2007
    Location
    Chicago, IL
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Create a VB Script to force SyncToy to run on log off/on

    When i ran the script it did not run the program. It just loaded it for me.

  10. #10

    Join Date
    Nov 2007
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Create a VB Script to force SyncToy to run on log off/on

    Hi Screweduphead (funny name by the way, I like it),
    If you haven't, you first need to go into the program and set up the folders you want to synchronize. After that you can name your job. The name of the job in the script should match the name that you gave the job in the SyncToy program.

    Once that has been done then it should work (or at least it does for me).
    I have never used SyncToy so for questions that are less scripty and more SyncToy-ish I'll leave you in the hands of others more knowledgeable than I.

  11. #11

    Join Date
    Nov 2007
    Location
    Chicago, IL
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Create a VB Script to force SyncToy to run on log off/on

    I have no idea what i did differently but i got it to run when playing around with it! yet i cant get it to run only a specific folder, it wants to run all tasks. Now i am also have the problem if when i logon it runs it...no program. but when logging out it only runs the scripts not the application so yea...

  12. #12

    Join Date
    Nov 2007
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Create a VB Script to force SyncToy to run on log off/on

    The problem that you are having screwuphead is because I have never seen SyncToy until today. Sorry about the confusion.

    The correct format that you want to use is (and I used a variable for the job name so it's easier to modify):
    strJobName = "MyReallyNeatJobName"
    strCommandLine = chr(34) & "C:\Program Files\Microsoft\SyncToy\SyncToy.exe" & chr(34) & " –R" & chr(34) & strJobName & chr(34)
    Set objWshShell = WScript.CreateObject("WScript.Shell")
    objWshShell.Exec(strCommandLine)

    According to the documentation there should be a space before the -r but none after the -r so that's what I did.

    Hope that helps.

  13. #13
    Kyle's Avatar
    Join Date
    Jan 2006
    Posts
    972
    Thank Post
    91
    Thanked 14 Times in 13 Posts
    Rep Power
    21

    Re: Create a VB Script to force SyncToy to run on log off/on

    I have also created a shortcut to Sync Toy and modified the properties to add the -R at the end. This works.......it runs the program, syncs the folder and then closes the program. I am going to try putting this in Log on and Off in a GPO to see if it works.

    I suppose the only downside of this is that the users need to have sync toy installed in the GPO you are running it in.

    I guess the vb scripters amongst you could add a line to the currently posted script along the lines of ........Check to see if Crogram files \sync toy exists. If it does then run the script, if it does not then don't run.



    Your thoughts please?

  14. #14

    Join Date
    Nov 2007
    Location
    Chicago, IL
    Posts
    8
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Re: Create a VB Script to force SyncToy to run on log off/on

    Actually kyle this is what i think would be better, if you had sync toy on the file server that you are saving the documents to and the login and logoff files call that program. This way not every user needs it. Then only the script needs to be on the computer.
    mostly if you got students who like to screw around with their computers and remove programs they think they dont need, in my case employees. Most people dont even know how to get to the GPO so they wouldnt miss with it.

    Just a thought.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 18
    Last Post: 12th September 2013, 05:44 PM
  2. Script to create a VPN connection
    By Norphy in forum Scripts
    Replies: 5
    Last Post: 20th April 2010, 11:37 AM
  3. VB Script to create folders
    By markesmith in forum Scripts
    Replies: 2
    Last Post: 26th April 2007, 03:03 PM
  4. Script to Create My Documents Subject Folders
    By SwedishChef in forum Scripts
    Replies: 15
    Last Post: 5th July 2006, 08:14 AM
  5. Script to create a local user on a XP box.
    By tosca925 in forum Scripts
    Replies: 3
    Last Post: 12th October 2005, 12:04 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •