Jump to content

Automatic font installation


Recommended Posts

Hello Everybody!

Sorry for my bad english!

I'm newbie in AutoIT and Vbs,I've just started to learn it!

But... I need your help,guys!

I have a vbs script and want to convert it to AutoIt!

The code of vbs script is

Const FONTS = &H14&

Set objShell = CreateObject("Shell.Application")
Set ofso = CreateObject("Scripting.FileSystemObject")

SourceFolder = ofso.GetParentFolderName(Wscript.ScriptFullName)
Set oSource = objShell.Namespace(SourceFolder)
Set oWinFonts = objShell.Namespace(FONTS)

Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Pattern = "([\w\s]+?)(_[^_]*)?(\.(ttf|otf|pfm|fon))$"

FOR EACH FontFile IN oSource.Items()
fontFileName = ofso.GetFileName(FontFile.Path)
IF regEx.Test(fontFileName) THEN
Set objMatch = regEx.Execute(fontFileName)
win7FontFileName = objMatch.Item(0).Submatches(0) & objMatch.Item(0).Submatches(2)
localFontPath = oWinFonts.Self.Path & "\" & fontFileName
win7LocalFontPath = oWinFonts.Self.Path & "\" & win7FontFileName
IF NOT ofso.FileExists(localFontPath) AND NOT ofso.FileExists(win7LocalFontPath) THEN
oWinFonts.CopyHere FontFile.Path
END IF
END IF
NEXT

Automatic vbs to AutoIt convertors make lots of errors!

Please help me!

P.S. This is great script! It install fonts from the same directory WITHOUT RESTARTING SYSTEM!

P.S. I found some other scripts written on AutoIT,but they need the system restart after installing!

This installs fonts WITHOUT RESTARTING OS!

Please! If you convert it to AutoIt,it will be GREAT!

Link to comment
Share on other sites

Then I suggest you look at this other script you found and try to make connections

I'll start you off

Local $objShell = ObjCreate("Shell.Application")

Local $ofso = ObjCreate("Scripting.FileSystemObject")

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

JohnOne,your are great! Thank you very much!

So I converted it

Const $FONTS = &H14&
Local $objShell = ObjCreate("Shell.Application")
Local $ofso = ObjCreate("Scripting.FileSystemObject")
Local $SourceFolder = $ofso.GetParentFolderName(@ScriptFullPath)
Local $oSource = $objShell.Namespace($SourceFolder)
Local $oWinFonts = $objShell.Namespace($FONTS)
$regEx = $New $RegExp
$regEx.IgnoreCase = 1
$regEx.Pattern = "([ws]+?)(_[^_]*)?(.(ttf|otf|pfm|fon))$"
For $FontFile IN $oSource.Items()
$fontFileName = $ofso.GetFileName($FontFile.Path)
IF $regEx.Test($fontFileName) THEN
   $objMatch = $regEx.Execute($fontFileName)
  $win7FontFileName = $objMatch.Item(0).Submatches(0) & $objMatch.Item(0).Submatches(2)
  $localFontPath = $oWinFonts.Self.Path & "" & $fontFileName
  $win7LocalFontPath = $oWinFonts.Self.Path & "" & $win7FontFileName
  IF NOT $ofso.FileExists($localFontPath) AND NOT $ofso.FileExists($win7LocalFontPath) THEN
   $oWinFonts.CopyHere ($FontFile.Path)
  EndIf
EndIf
NEXT

But when I run it,I get a error

Posted Image

What's wrong? I don't understand my mistake! :)

Link to comment
Share on other sites

The vbscript number &h14 is 0x14 in AutoIt, the &H tells the script the number is in Hex, the trailing & tells you it's in the "Long" format. &h14& is equal to 20 in decimal.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

At last it works!

Const $FONTS = 0x14
$oShell = ObjCreate("Shell.Application")
$oWinFonts = $oShell.Namespace($FONTS)
; The fonts must be in the same directory
$sFirstFile = FileFindFirstFile("*.*")
If $sFirstFile = -1 Then
Exit
EndIf
While 1
Local $sFile = FileFindNextFile($sFirstFile)
If @error Then ExitLoop
Switch StringRight($sFile, 3)
Case 'ttf', 'otf', 'pfm', 'fon'
     $sWinFontsPath = @WindowsDir & 'Fonts' & $sFile
     $sLocFontsPath = @ScriptDir & '' & $sFile
     If NOT FileExists($sWinFontsPath) Then
         $oWinFonts.CopyHere($sLocFontsPath)
     Else
         MsgBox(262144, $sFile, 'The file is already installed', 1)
     EndIf
EndSwitch
WEnd

Thank you very much!

God bless you!

Edited by warezoogle3
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...