+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
Scripts Thread, VBS to Backup Folder and then Restore from Reg in Coding and Web Development; I would like to make a vbs script that backups up all the files located in x:\xxx\session\*.* to c:\temp\winteg by ...
  1. #1

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Wink VBS to Backup Folder and then Restore from Reg

    I would like to make a vbs script that backups up all the files located in x:\xxx\session\*.* to c:\temp\winteg by finding the path in the following registry key:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
    "IbsFont"="C:\\wInteg6\\IbsFont.fon"

    In other words it will get the current install location C:\wInteg6\ from the reg key mentioned above as different customers install this to different locations and then it can backup all files from C:\wInteg6\session to c:\temp.

    Im am currently getting the customers to do this manually using the following vbs script but would prefer this to be done seamlessly:

    ========================
    Const WINDOW_HANDLE = 0
    Const NO_OPTIONS = 0
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder _
    (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts")
    Set objFolderItem = objFolder.Self
    objPath = objFolderItem.Path

    Const OverWriteFiles = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.CopyFolder objPath , "C:\temp\winteg" , OverWriteFiles
    ==========================

    Please help me find a way to do this automatically.

    Thanks,
    Simon

  2. #2

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    I think this does what you want. It reads the fonts registry location and then copies everything from that folder to c:\temp\winteg

    It doesn't do much error checking, just a check to see if the font is installed

    Code:
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFolder=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFolder="" then
      wscript.echo "Font not installed"
    else
      wscript.echo "Font is in " & sFolder
      ofso.copyfolder sFolder , "c:\temp\winteg", true
    end if

  3. #3

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I think we are on the right track.

    But when i run the new script i get the following dialogs:

    • Font is in c:\wInteg6\IbsFont.fon
    • Line 10 Car 3 Error: Path not found Code: 800A004C Source: VBScript error.


    I think the issue is the value data in the registry contanis c:\wInteg6\IbsFont.fon and not just the path e.g. c:\wInteg6\ can we somehow get the vbs script to remove the IbsFont.fon so it will backup the folder correctly.

    Thankyou so far Steve.

  4. #4
    azrael78's Avatar
    Join Date
    Sep 2007
    Location
    Devon
    Posts
    383
    Thank Post
    47
    Thanked 37 Times in 33 Posts
    Rep Power
    20
    You wanted this as a VBS script or are you not picky about what scripting language?

    Az

  5. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Quote Originally Posted by simons2009 View Post
    I think we are on the right track.

    But when i run the new script i get the following dialogs:

    • Font is in c:\wInteg6\IbsFont.fon
    • Line 10 Car 3 Error: Path not found Code: 800A004C Source: VBScript error.


    I think the issue is the value data in the registry contanis c:\wInteg6\IbsFont.fon and not just the path e.g. c:\wInteg6\ can we somehow get the vbs script to remove the IbsFont.fon so it will backup the folder correctly.

    Thankyou so far Steve.



    Code:
    Dim x
    Dim strPath
    
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFolder=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFolder="" then
      wscript.echo "Font not installed"
    else
      wscript.echo "Font is in " & sFolder
    x = instrrev(sFolder,"\")
    strPath=Left(sFolder,x)
      ofso.copyfolder strPath , "c:\temp\winteg", true
    end if
    something along those lines ?

  6. #6

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    @macshinobi - that looks right; thanks. That'll teach me to try posting before my second cup of coffee :-)

    Slightly different version below - just uses "parentfolder" to find out the foldername

    Code:
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFile="" then
      wscript.echo "Font not installed"
    else
      set oFile=ofso.getfile(sFile)
      sfolder=oFile.parentfolder
      wscript.echo "Font is in " & sFolder
      ofso.copyfolder sFolder , "c:\temp\winteg", true
    end if

  7. #7

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Quote Originally Posted by srochford View Post
    @macshinobi - that looks right; thanks. That'll teach me to try posting before my second cup of coffee :-)

    Slightly different version below - just uses "parentfolder" to find out the foldername

    Code:
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFile="" then
      wscript.echo "Font not installed"
    else
      set oFile=ofso.getfile(sFile)
      sfolder=oFile.parentfolder
      wscript.echo "Font is in " & sFolder
      ofso.copyfolder sFolder , "c:\temp\winteg", true
    end if
    no problem - how does the parentfolder property work then ?

    so If I had

    c:\myFolder\sub_folder\file.txt

    Would that just take c:\myFolder\sub_folder and ignore the file.txt or what exactly ?

  8. #8

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,144
    Thank Post
    113
    Thanked 518 Times in 447 Posts
    Blog Entries
    2
    Rep Power
    121
    Quote Originally Posted by mac_shinobi View Post
    no problem - how does the parentfolder property work then ?

    so If I had

    c:\myFolder\sub_folder\file.txt

    Would that just take c:\myFolder\sub_folder and ignore the file.txt or what exactly ?
    Yes.

    I can't think of any situation in which your technique wouldn't work (and yours is probably marginally faster; my code will have to read the disc to find out about the file) but I think parentfolder is just a bit tidier :-)

  9. #9

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Thanks for getting back to me so fast i will have to test it out tommorow at work as my wife isnt well today.

    If this works like your saying and it picks up the correct folder c:\winteg and ignores the extension how to i get it to look in the folder below e.g. c:\winteg\session so i can backup everything in that folder to the c:\temp folder?

    Hope i make sense.

    Thanks,
    Simon

  10. #10

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Quote Originally Posted by simons2009 View Post
    Thanks for getting back to me so fast i will have to test it out tommorow at work as my wife isnt well today.

    If this works like your saying and it picks up the correct folder c:\winteg and ignores the extension how to i get it to look in the folder below e.g. c:\winteg\session so i can backup everything in that folder to the c:\temp folder?

    Hope i make sense.

    Thanks,
    Simon
    ok so you have the following paths / folders :

    c:\winteg\
    c:\winteg\session

    c:\temp

    Are you wanting to change the path where it is copying or do you want another line of code that copies folder one to folder two or what exactly ?

  11. #11

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Sorry for the confussion.

    What happens is the reg entry gives us the path c:\wInteg6\IbsFont.fon all i want is to drop the IbsFont.fon to so the path is c:\wInteg6 and then make the path = c:\winteg\session so i can backup that folder the folder to c:\temp.

  12. #12

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Code:
    Dim x
    Dim strPath
    
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFolder=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFolder="" then
      wscript.echo "Font not installed"
    else
      wscript.echo "Font is in " & sFolder
    x = instrrev(sFolder,"g")                 '<----- HERE
    strPath=lcase(Left(sFolder,x)) & "\session"
      ofso.copyfolder strPath , "c:\temp\winteg", true   '<-- Alter paths here
    end if
    You can alter the paths there ( strPath being the source and the latter being the destination of where you want the files to go from and to )

    strPath should now be c:\winteg\session and you said C:\temp so not sure if you mean just

    C:\temp or C:\temp\winteg

    but you can alter that yourself easily enough

    Also where it states HERE in the code above is where I have used the instrrev function to find the letter g in winteg and get rid of the rest of the text after the g hence chopping off the number 6 etc

    Hopefully the path in the registry key will always have something along the lines of

    x:\winteg

    where x is the drive letter ( C or whatever )
    Last edited by mac_shinobi; 26th May 2009 at 12:53 PM.

  13. #13

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    After playing around with your code sujestions this works for me as required:

    ---------------------
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFile="" then
    wscript.echo "Font not installed"
    else
    set oFile=ofso.getfile(sFile)
    sfolder=oFile.parentfolder & "\session"
    wscript.echo "Font is in " & sFolder
    ofso.copyfolder sFolder , "c:\temp\winteg", true
    end if
    ---------------------

    Can you please tell me how to remove the dialog infroming me that the font is installed or not installed as i want it to be seamless??

    Let me know.

    Thanks so much

  14. #14

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Quote Originally Posted by simons2009 View Post
    After playing around with your code sujestions this works for me as required:

    ---------------------
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFile="" then
    wscript.echo "Font not installed"
    else
    set oFile=ofso.getfile(sFile)
    sfolder=oFile.parentfolder & "\session"
    wscript.echo "Font is in " & sFolder
    ofso.copyfolder sFolder , "c:\temp\winteg", true
    end if
    ---------------------

    Can you please tell me how to remove the dialog infroming me that the font is installed or not installed as i want it to be seamless??

    Let me know.

    Thanks so much
    Just delete the 2 lines I have made in bold so it is like

    Code:
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFile="" then 
     ' DO NOTHING
    else
      ' Copy files from source to destination
      set oFile=ofso.getfile(sFile)
      sfolder=oFile.parentfolder & "\session"
      ofso.copyfolder sFolder , "c:\temp\winteg", true
    end if

  15. Thanks to mac_shinobi from:

    simons2009 (28th May 2009)

  16. #15

    Join Date
    May 2009
    Posts
    20
    Thank Post
    4
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    :-D It works!! :-)

    Thanks so much for your help you guys are awesome.

    One last request can you alter this code for me to pop up a message saying "Session Backup Does Not Exist" and if it does to popup a box saying "Session Files Restored Successfully"


    ------------------------
    set oFSO=createobject("scripting.filesystemobject")
    set oShell=createobject("wscript.shell")
    on error resume next
    sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
    on error goto 0
    if sFile="" then
    ' DO NOTHING
    else
    ' Copy files from source to destination
    set oFile=ofso.getfile(sFile)
    sfolder=oFile.parentfolder & "\session"
    ofso.copyfolder "c:\temp\winteg" , sFolder, true
    end if
    ------------------------

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 19
    Last Post: 5th March 2009, 08:13 PM
  2. Moodle - Backup and Restore
    By danIT in forum Virtual Learning Platforms
    Replies: 3
    Last Post: 17th December 2008, 10:11 PM
  3. VBS Script to copy a folder
    By FN-GM in forum Scripts
    Replies: 2
    Last Post: 23rd February 2008, 01:08 PM
  4. Replies: 4
    Last Post: 24th January 2007, 11:39 PM
  5. Simple backup and restore
    By adamyoung in forum Wireless Networks
    Replies: 7
    Last Post: 25th August 2006, 08:13 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
  •