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.Applic ation")
Set wshShell = CreateObject("WScript.Shel l")
Set objFSO = createobject("Scripting.Fi lesystemob ject")
Wscript.Echo "------------------------- ---------- ---"
Wscript.Echo " Install Fonts "
Wscript.Echo "------------------------- ---------- ---"
Wscript.Echo " "
strFontSourcePath = "\\servername\sharefolder\ stdfonts\"
If objFSO.FolderExists(strFon tSourcePat h) Then
Set objNameSpace = objShell.Namespace(strFont SourcePath )
Set objFolder = objFSO.getFolder(strFontSo urcePath)
For Each objFile In objFolder.files
If LCase(right(objFile,4)) = ".ttf" OR LCase(right(objFile,4)) = ".otf" Then
Set objFont = objNameSpace.ParseName(obj File.Name)
objFont.InvokeVerb("Instal l")
Wscript.Echo "Installed Font: " & objFile.Name
Set objFont = Nothing
End If
Next
Else
Wscript.Echo "Font Source Path does not exists"
End If
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.Applic
Set wshShell = CreateObject("WScript.Shel
Set objFSO = createobject("Scripting.Fi
Wscript.Echo "-------------------------
Wscript.Echo " Install Fonts "
Wscript.Echo "-------------------------
Wscript.Echo " "
strFontSourcePath = "\\servername\sharefolder\
If objFSO.FolderExists(strFon
Set objNameSpace = objShell.Namespace(strFont
Set objFolder = objFSO.getFolder(strFontSo
For Each objFile In objFolder.files
If LCase(right(objFile,4)) = ".ttf" OR LCase(right(objFile,4)) = ".otf" Then
Set objFont = objNameSpace.ParseName(obj
objFont.InvokeVerb("Instal
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
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