Jump to content

Recommended Posts

Posted

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 :)

Posted

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

 

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

Posted

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. :)

Posted
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. :)

 

 

 

 


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 ?

Posted

@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

 

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

Posted
@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

 

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 ?

Posted
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 :-)

Posted

Thanks for getting back to me so fast :D 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

Posted
Thanks for getting back to me so fast :D 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 ?

Posted

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.

Posted (edited)

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 )

Edited by mac_shinobi
Posted

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 :D

Posted
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 :D

 

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

 

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 1
Posted

:-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

------------------------

Posted (edited)

Another question apart from the one in the last box is:

 

Can i get the backup script to look for the default TEMP folder from the windows System Variable and copy the files in there under winteg e.g. so it doesnt matter which temp they use. And then i would like to copy the saved into the new c:\winteg\kcs\session605 folders:

 

 

Sctipt 1 - checks for C:\temp then creates it

-----------------

Option Explicit

Dim objFSO, objFolder, objShell, strDirectory

strDirectory = "c:\tempkcs"

 

' Create the File System Object

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

' Note If..Exists. Then, Else ... End If construction

If objFSO.FolderExists(strDirectory) Then

Set objFolder = objFSO.GetFolder(strDirectory)

Else

Set objFolder = objFSO.CreateFolder(strDirectory)

End If

 

If err.number = vbEmpty then

Set objShell = CreateObject("WScript.Shell")

Else WScript.echo "VBScript Error: " & err.number

End If

-----------------------

 

Script 2 - backup files from old Wintegrate version to c:\tempkcs\session

-----------------------

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

else

set oFile=ofso.getfile(sFile)

sfolder=oFile.parentfolder & "\session"

ofso.copyfolder sFolder , "c:\tempkcs\winteg", true

end if

------------------------

 

Script 3 - copys files in C:\new winteg folder\session

-------------------------

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:\tempkcs\winteg" , sFolder, true

end if

----------------------------

 

 

Ok questions

 

How do i add to Script 3 to copy everything from c:\tempkcs\winteg to the following folders:

C:\[Path from Ibs font]\Session

C:\[Path from Ibs font]\KCS\Session605

 

Also after that is completed i want it to remove the c:\tempkcs folder from the c: so everything is nice and tidy.

 

 

Thanks,

Simon

Edited by simons2009
Posted
Another question apart from the one in the last box is:

 

Can i get the backup script to look for the default TEMP folder from the windows System Variable and copy the files in there under winteg e.g. so it doesnt matter which temp they use. And then i would like to copy the saved into the new c:\winteg\kcs\session605 folders:

 

 

Sctipt 1 - checks for C:\temp then creates it

-----------------

Option Explicit

Dim objFSO, objFolder, objShell, strDirectory

Dim newfolder

strDirectory = "c:\tempkcs"

 

' Create the File System Object

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

' Note If..Exists. Then, Else ... End If construction

If objFSO.FolderExists(strDirectory) Then

Set objFolder = objFSO.GetFolder(strDirectory)

wscript.echo "Folder exists : " & strDirectory

Else

Set objFolder = objFSO.CreateFolder(strDirectory)

wscript.echo "Folder does not exist : " & strDirectory

Set newfolder = oFSO.CreateFolder(strDirectory)

wscript.echo "A new folder has been created at: " & strDirectory

End If

 

If err.number = vbEmpty then

Set objShell = CreateObject("WScript.Shell")

Else WScript.echo "VBScript Error: " & err.number

End If

-----------------------

 

Script 2 - backup files from old Wintegrate version to c:\tempkcs\session

-----------------------

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

else

set oFile=ofso.getfile(sFile)

sfolder=oFile.parentfolder & "\session"

ofso.copyfolder sFolder , "c:\tempkcs\winteg", true

end if

------------------------

 

Script 3 - copys files in C:\new winteg folder\session

-------------------------

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

ofso.copyfolder "c:\tempkcs\winteg" , sFolder & "\session", true

ofso.copyfolder "c:\tempkcs\winteg" , sFolder & "\KCS\Session605", true

oFSO.DeleteFolder "c:\tempkcs", True

end if

----------------------------

 

 

Ok questions

 

How do i add to Script 3 to copy everything from c:\tempkcs\winteg to the following folders:

C:\[Path from Ibs font]\Session

C:\[Path from Ibs font]

 

Also after that is completed i want it to remove the c:\tempkcs folder from the c: so everything is nice and tidy.

 

 

Thanks,

Simon

 

I have altered the script inside of the quote above some what so should help you out to a degree.

 

You should be able to combine the 3 scripts together ( obviously getting rid of the repeated variables ie oFSO etc and keep all the variables at the top of the script and it will obviously make it a longer script.

 

What you can also do is the common functions such as deleting the registry key etc you could make as functions and call the functions from within the main script.

 

I have not got time to have a go at it right now but will have a go at it when I get home this evening unless srochford beats me to it lol

Posted (edited)

Ill give the script you made try soon, the truth is I do not want to combine all 3, as I have the installer running in the correct order during the installation process so I am happy with them kept separate.

 

My boss asked me another question which makes things more complicated.

 

Can we adjust the script to look at and use the TEMP folder specified the windows environmental variables instead of specifying the folder and making it in the c:\ etc

For instance my TEMP location is %SystemRoot%\TEMP

 

Then we can make the tempkcs in that folder then delete it afterword.

 

Thanks again,

Simon :-D

Edited by simons2009
Posted
Ill give the script you made try soon, the truth is I do not want to combine all 3, as I have the installer running in the correct order during the installation process so I am happy with them kept separate.

 

My boss asked me another question which makes things more complicated.

 

Can we adjust the script to look at and use the TEMP folder specified the windows environmental variables instead of specifying the folder and making it in the c:\ etc

For instance my TEMP location is %SystemRoot%\TEMP

 

Then we can make the tempkcs in that folder then delete it afterword.

 

Thanks again,

Simon :-D

 

no problem - I will look into both either on my lunch or when I get home unless someone else beats me to it.

Posted (edited)

Looks like i bet you to it lol here is what im using now, thank you all so much.

 

Backup session script

 

set oFSO=createobject("scripting.filesystemobject")
set oShell=createobject("wscript.shell")
Dim objFSO, objFiles, objShell, intCount
Dim strFile, strName, strLongName, strDirectory, strEnv, strExt
Set objShell = CreateObject("Wscript.Shell")
strEnv = objShell.ExpandEnvironmentStrings("%temp%")
intcount = 0


on error resume next
sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
on error goto 0
if sFile="" then 
else
set oFile=ofso.getfile(sFile)
sfolder=oFile.parentfolder & "\session"
ofso.copyfolder sFolder , strEnv & "\tempkcs" , true
end if

Edited by simons2009
Posted
Looks like i bet you to it lol here is what im using now, thank you all so much.

 

Backup session script

 

set oFSO=createobject("scripting.filesystemobject")
set oShell=createobject("wscript.shell")
Dim objFSO, objFiles, objShell, intCount
Dim strFile, strName, strLongName, strDirectory, strEnv, strExt
Set objShell = CreateObject("Wscript.Shell")
strEnv = objShell.ExpandEnvironmentStrings("%temp%")
intcount = 0


on error resume next
sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
on error goto 0
if sFile="" then 
else
set oFile=ofso.getfile(sFile)
sfolder=oFile.parentfolder & "\session"
ofso.copyfolder sFolder , strEnv & "\tempkcs" , true
end if

Session Restore Script

 

set oFSO=createobject("scripting.filesystemobject")
set oShell=createobject("wscript.shell")
Dim objFSO, objFiles, objShell, intCount
Dim strFile, strName, strLongName, strDirectory, strEnv, strExt
Set objShell = CreateObject("Wscript.Shell")
strEnv = objShell.ExpandEnvironmentStrings("%temp%")
intcount = 0


on error resume next
sFile=oShell.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\IbsFont")
on error goto 0
if sFile="" then 
else
set oFile=ofso.getfile(sFile)
sfolder=oFile.parentfolder & "\session"
ofso.copyfolder sFolder , strEnv & "\tempkcs" , true
end if

 

whats the difference between the 2 scripts ?

Posted

Whoops the copy and paste from the VMWare machine played up

 

Here is the restore script:

 

set oFSO=createobject("scripting.filesystemobject")
set oShell=createobject("wscript.shell")

Dim objFSO, objFiles, objShell, intCount
Dim strFile, strName, strLongName, strDirectory, strEnv, strExt
Set objShell = CreateObject("Wscript.Shell")
strEnv = objShell.ExpandEnvironmentStrings("%temp%")
intcount = 0

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 
ofso.copyfolder strEnv & "\tempkcs" , sFolder & "\session", true
ofso.copyfolder strEnv & "\tempkcs" , sFolder & "\KCS\Session605", true
oFSO.DeleteFolder strEnv & "\tempkcs", True
end if

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...