首页 > 解决方案 > Getting VBS script to use network share location

问题描述

Option Explicit

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 = "\\172.31.0.5\Fonts"



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

    If objFSO.FileExists("C:\Windows\Fonts\" & objFile.Name) Then

      Wscript.Echo "Font already installed: " & objFile.Name

    Else

      Set objFont = objNameSpace.ParseName(objFile.Name)

      objFont.InvokeVerb("Install")

      Wscript.Echo "Installed Font: " & objFile.Name

      Set objFont = Nothing

    End If

  End If

 Next

Else

 Wscript.Echo "Font Source Path does not exists"

End If

Source cannot be \\172.31.0.5\Fonts, I tried this and it won't load the fonts. However, when the drive number (X:\Fonts) is used, it works. How can I change this so I can just install them from the network location without using the drive letter? It is for a deployment server. Thank you.

标签: vbscript

解决方案


您省略了共享名称。X:\Fonts 表示 \172.31.0.5\sharename\Fonts。您需要找出共享名称并将其粘贴。


推荐阅读