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 ...
-
25th May 2009, 03:48 AM #1
-
-
IDG Tech News
-
25th May 2009, 08:21 AM #2 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
-
-
25th May 2009, 08:43 AM #3
- 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.
-
-
25th May 2009, 11:48 AM #4 You wanted this as a VBS script or are you not picky about what scripting language?
Az
-
-
25th May 2009, 01:30 PM #5 
Originally Posted by
simons2009
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 ?
-
-
25th May 2009, 04:42 PM #6 @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
-
-
25th May 2009, 05:38 PM #7 
Originally Posted by
srochford
@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 ?
-
-
25th May 2009, 06:38 PM #8 
Originally Posted by
mac_shinobi
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 :-)
-
-
26th May 2009, 02:00 AM #9
- 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
-
-
26th May 2009, 07:13 AM #10 
Originally Posted by
simons2009
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 ?
-
-
26th May 2009, 08:21 AM #11
- 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.
-
-
26th May 2009, 12:47 PM #12 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.
-
-
27th May 2009, 08:34 AM #13
- 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
-
-
27th May 2009, 08:36 AM #14 
Originally Posted by
simons2009
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
-
Thanks to mac_shinobi from:
simons2009 (28th May 2009)
-
28th May 2009, 02:51 AM #15
- 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: 
Similar Threads
-
Replies: 19
Last Post: 5th March 2009, 08:13 PM
-
By danIT in forum Virtual Learning Platforms
Replies: 3
Last Post: 17th December 2008, 10:11 PM
-
By FN-GM in forum Scripts
Replies: 2
Last Post: 23rd February 2008, 01:08 PM
-
By projector1 in forum Windows
Replies: 4
Last Post: 24th January 2007, 11:39 PM
-
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
-
Forum Rules