域環境users提權調用lsrunase.exe 批處理完成安裝字體

字體安裝2.0
由於字體安裝之前的批處理採用字體文件複製到c:\windows\fonts下再註冊註冊表的方式,一部分字體安裝不上,重新修改了批處理方式。

一. 字體安裝批處理
1.vbs腳本運行安裝D:\fonts下的字體安裝包,安裝時fonts.vbs同時會檢測C:\windows\fonts\字體名稱與D:\fonts裏的字體名是否一致,如果存在則忽略掉。缺點:若是表面字體名不一致,會提示重複安裝,手動單擊選擇即可。
參考的事例:
http://blog.jasondahmen.com/2011/11/24/the-true-ultimate-font-install-for-windows-7-and-xp-vbs/
代碼如下fonts.vbs
Option Explicit
' Installing multiple Fonts in Windows 7
' http://www.cloudtec.ch 2011
' Edited by Jason Dahmen

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

strFontSourcePath = "D:\fonts\"
If objFSO.FolderExists(strFontSourcePath) Then
If objFSO.FolderExists("C:\Users\") Then
' Start Windows 7/Vista
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" OR LCase(right(objFile,4)) = ".ttc" Then
Set objFont = objNameSpace.ParseName(objFile.Name)
If objFSO.FileExists("C:\WINDOWS\Fonts\" & objFile.Name) = False Then
objFont.InvokeVerb("Install")
Set objFont = Nothing
Else
End If
End If
Next
Else
' Start Windows XP
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" OR LCase(right(objFile,4)) = ".ttc" Then
Set objFont = objNameSpace.ParseName(objFile.Name)
If objFSO.FileExists("C:\WINDOWS\Fonts\" & objFile.Name) = False Then
objFSO.CopyFile "D:\fonts*", "c:\windows\fonts\"
Set objFont = Nothing
Else
End If
End If
Next
End If
Else
Wscript.Echo "Font Source Path does not exists"
End IF

注意:安裝只包含ttf,otf,ttc三種字體文件,可以自己在代碼加字體後綴( If LCase(right(objFile,4)) = ".ttf" OR LCase(right(objFile,4)) = ".otf" OR LCase(right(objFile,4)) = ".ttc" Then),滿足95%,特殊類型的字體安裝再擴展。

  1. 使用vbs封裝成exe文件工具,封裝vbs腳本,命名可執行文件的fonts.exe。
    (bat不能直接運行VBS,水平有限直接做成了exe來執行)
    下載地址:https://download.csdn.net/download/qq_16066381/9760279

域環境users提權調用lsrunase.exe 批處理完成安裝字體

二.使用Quick_Batch_File_Compiler封裝以管理員運行的批處理.批處理用到lsrunas.exe加密域管理員密碼來運行fonts.exe

  1. 代碼:Fonts-intsall.bat
    @echo off
    if "%1"=="h" goto begin
    start mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
    :begin
    \10.10.12.201\soft\install\lsrunase\lsrunase.exe /user:administrator /password:3lp9huRP3uydxg== /domain:zzecwwmir.com /command:d:\fonts\fonts.exe /runpath:d:\fonts\
    rem 利用lsrunase調用域管理員權限來運行本地自解壓文件完成軟件安裝rem 利用lsrunase調用域管理員權限來運行本地自解壓文件完成軟件安裝

參考lsrunase.exe
https://www.cnblogs.com/colinliu/p/5666715.html

2.Quick_Batch_File_Compiler封裝命名爲 雙擊本軟件_安裝字體.exe

三.介於軟件bug,做了其他輔助性的批處理來完善使用
字體提示已安裝太多情況1.強制結束安裝進程,2.清理fonts下已安裝的字體

11強制結束_安裝字體.bat
@echo off
taskkill /f /im fonts.exe
結束字體安裝進程

12刪除以前的文件裏的字體安裝文件.bat
@echo off
del /f /q /a /s D:\fonts*.otf
del /f /q /a /s D:\fonts*.ttf
del /f /q /a /s D:\fonts*.fon
del /f /q /a /s D:\fonts*.ttc
rem 刪除字體

Desk.bat 刪除之前的快捷方式,創建新的快捷方式,並運行完刪除自己
@echo off
copy /y "D:\fonts\安裝字體.lnk" c:\users\public\desktop
rem 在公共桌面創建快捷方式
ping 127.1 -n 2 >nul
del D:\fonts\安裝字體.lnk
del /f /q /a /s %0
rem 刪除批處理本身

四.封裝自解壓
自解壓的封裝方法百度一下。
域環境users提權調用lsrunase.exe 批處理完成安裝字體

1.解壓後的Fonts.exe 屬性隱藏,防止誤刪
2.注意命名的安裝軟件排在所有文件前面。字體文件很多情況下,會造成找不到
域環境users提權調用lsrunase.exe 批處理完成安裝字體

五.宣導,或者編輯安裝方法文檔。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章