Link to home
Start Free TrialLog in
Avatar of polshek
polshek

asked on

Need help to overwrite file in vbscript

Hello Experts -

I am trying to install additional fonts for windows 7 users via a vbscript.  The problem is that I want to overwrite the existing font if it exists.  With the code below, it will prompt to overwrite if the file is existing.  Is there a way to just overwrite without prompting ?   thanks...

Here is the code :

Option Explicit
' Installing multiple Fonts in Windows 7
 
Dim objShell, objFSO, wshShell
Dim strFontSourcePath, objFolder, objFont, objNameSpace, objFile
 
Set objShell = CreateObject("Shell.Application")
Set wshShell = CreateObject("WScript.Shell")
Set objFSO = createobject("Scripting.Filesystemobject")
 
Wscript.Echo "--------------------------------------"
Wscript.Echo " Install Fonts "
Wscript.Echo "--------------------------------------"
Wscript.Echo " "
 
strFontSourcePath = "\\servername\sharefolder\stdfonts\"
 
If objFSO.FolderExists(strFontSourcePath) Then
 
Set objNameSpace = objShell.Namespace(strFontSourcePath)
Set objFolder = objFSO.getFolder(strFontSourcePath)
 
For Each objFile In objFolder.files
    If LCase(right(objFile,4)) = ".ttf" OR LCase(right(objFile,4)) = ".otf" Then
                    Set objFont = objNameSpace.ParseName(objFile.Name)
            objFont.InvokeVerb("Install")
            Wscript.Echo "Installed Font: " & objFile.Name
            Set objFont = Nothing
        End If
    Next
    Else
        Wscript.Echo "Font Source Path does not exists"
    End If
ASKER CERTIFIED SOLUTION
Avatar of zalazar
zalazar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

The website with the same script including the grammatical error ("does not exists") is here:
http://www.cloudtec.ch/blog/tech/install-font-command-line-script-windows-7.html

has a comment from the author to run as admin.

Mike
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.