Batch, .vbs or something else???

Discussion in 'Software' started by nfv111, Aug 20, 2008.

  1. nfv111

    nfv111 Private E-2

    Hello all

    Typically I dont get much involved on the programming side of life but sometimes I need to tinker, like now. I needed to copy the contents of a Thunderbird email folder to a different drive. I made this batch and scheduled it to run as a Windows task. The folder is a few gigs and was taking far too long by typical graphical backup means, which is why I turned to xcopy.

    echo off
    cd \
    cd windows\system32
    start /min xcopy "%appdata%\Thunderbird\*.*" "Q:\test2\" /e /Y /h /c /i /r
    exit

    I would like to have this execute when the PC turns off. I think if I had a .vbs script with this (I dont know vbs) I could dump it into
    C:\WINDOWS\System32\GroupPolicy\User\Scripts\Logoff and then use a local group policy to run it. My main goal is to have this one particular folder get copied daily and without user awareness. Any thoughts or different ideas would greatly be appreciated.

    Thanks in advance,

    nfv
     
  2. PC-XT

    PC-XT Master Sergeant

    The vbs code would be
    Code:
    Set shell=CreateObject("WScript.Shell")
    dq=chr(34)
    shell.run("windows\system32\xcopy "&dq&"%appdata%\Thunderbird\*.*"&dq&" "&dq&"Q:\test2\"&dq&" /e /Y /h /c /i /r",0)
    The 0 will make it run in the background. If you want it to run normally, remove the 0 and the comma before it. You could also use vbs itself to copy the files, like
    Code:
    Set fSys = CreateObject("Scripting.FileSystemObject")
    'This part of the code would not be needed if you removed appdata& from the last line and edited the path to be the absolute path to the directory.
    'This code finds the environment entry %appdata%
    Set shell=CreateObject("WScript.Shell")
    appdata=""
    on error resume next
    For Each strEnv In shell.Environment("PROCESS")
     a=split(strEnv,"=",-1,1)
     if lcase(a(0))="appdata":appdata=a(1):exit for
    next
    on error goto 0
    if appdata="" then wscript.echo("ERROR: %appdata% can't be found."):wscript.quit
    'end of %appdata% finder
    fSys.CopyFile(appdata&"\Thunderbird\*.*","Q:\test2\",true)
    That will overwrite files of the same name in Q:\test2\ If you don't want that, change true to false.
     
  3. PC-XT

    PC-XT Master Sergeant

    Sorry, I left out the home backslash in the first code. :eek: It should be
    Code:
    Set shell=CreateObject("WScript.Shell")
    dq=chr(34)
    shell.run("\windows\system32\xcopy "&dq&"%appdata%\Thunderbird\*.*"&dq&" "&dq&"Q:\test2\"&dq&" /e /Y /h /c /i /r",0)
    Also, I missed the /E switch in the xcopy command, so the second one should be (changing the last line)
    Code:
    Set fSys = CreateObject("Scripting.FileSystemObject")
    'This part of the code would not be needed if you removed appdata& from the last line and edited the path to be the absolute path to the directory.
    'This code finds the environment entry %appdata%
    Set shell=CreateObject("WScript.Shell")
    appdata=""
    on error resume next
    For Each strEnv In shell.Environment("PROCESS")
     a=split(strEnv,"=",-1,1)
     if lcase(a(0))="appdata":appdata=a(1):exit for
    next
    on error goto 0
    if appdata="" then wscript.echo("ERROR: %appdata% can't be found."):wscript.quit
    'end of %appdata% finder
    fSys.CopyFolder(appdata&"\Thunderbird","Q:\test2\",true)
    to copy subfolders also, overwriting existing files. I am not sure about whether this is similar to the /c switch. It may stop if there is an error. It is possible to write something that won't stop for an error, but it is more complicated. It parses the directory tree and copies each file individually.
     
  4. nfv111

    nfv111 Private E-2

    Hey thanks for the responses. I am playing now.

    I get a syntax error when I run

    Set shell=CreateObject("WScript.Shell")
    dq=chr(34)
    shell.run("\windows\system32\xcopy "&dq&"%appdata%\Thunderbird\*.*"&dq&" "&dq&"Q:\test2\"&dq&" /e /Y /h /c /i /r",0)

    On line 3 it says cannot use parantheses when calling a sub
     
  5. PC-XT

    PC-XT Master Sergeant

    Sorry. That should be:
    Code:
    Set shell=CreateObject("WScript.Shell")
    dq=chr(34)
    shell.run "\windows\system32\xcopy "&dq&"%appdata%\Thunderbird\*.*"&dq&" "&dq&"Q:\test2\"&dq&" /e /Y /h /c /i /r",0
     
  6. nfv111

    nfv111 Private E-2

    that did it, thanks so much
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds