Page 1 of 1 1
Topic Options
#188587 - 2008-07-07 05:24 PM Convert small VBScript to KiXtart
GTManor Offline
Fresh Scripter

Registered: 2008-07-07
Posts: 6
Loc: Cincinnati, OH, USA
I am fairly new to KiXtart and have only created a basic script to map a few network drives based upon department. I need to roll out a few new fonts to select users by department and have run across the following VBScript online. I have no VBScript experience whatsoever, but the script does seem to do what I would like it to do, without having to reboot the PC for the fonts to be available. I would rather take care of this from my KiXtart login script. Any assistance would be greatly appreciated.

Here is the VBScript:

Const FONTS = &H14&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FONTS)
objFolder.CopyHere "C:\Scripts\Myfont.ttf"

Here is a summary of what it does:

Line #1 - Defines a constant named FONTS and sets the value to &H14&; this constant is used to tell the script which “special folder” (i.e., the Fonts folder) we want to work with. We could just use a hardcoded path like C:\Windows\Fonts to represent the Fonts folder. However, keep in mind that the Fonts folder doesn’t have to be C:\Windows\Fonts. By using the special folders constant the script will always find the Fonts folder for us, regardless of where that folder actually lives.

Line #2 - Creates an instance of the Shell.Application object.

Line #3 - Binds to the Fonts folder.

Line #4 - Once connected to the Fonts folder we call the CopyHere method, specifying the complete path to the font we want to install.

I would be happy to provide additional details if needed or answer an questions you may have as a result. Thanks in advance for any assistance you may be able to provide.

GTManor

Top
#188588 - 2008-07-07 05:31 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Welcome to the board.

There is a UDF (User Defined Function) called InstallFont() - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=84048

If you copy the function as is to the bottom of your script and then add a little code, following the example in the header, almost all the work is done. Try it out and let us know if it works for you.

Check out the all the UDFs here:
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1
_________________________
(... better days ahead)

Top
#188589 - 2008-07-07 05:44 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
GTManor Offline
Fresh Scripter

Registered: 2008-07-07
Posts: 6
Loc: Cincinnati, OH, USA
Thank you for such a quick response. I will test this as soon as possible and reply back with the results.
Top
#188594 - 2008-07-07 08:54 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Here is another way that we have done this.. It is not as eloqent as Lonk's version, but is servicable..

 Code:
 FONT('3of9.ttf','3 of 9 Barcode (TrueType)') ;INSTALL FONT


The UDF is:
 Code:
 ; --  INSTALL FONT - ALL
 FUNCTION font($font,$description)
    DIM $rc
    IF COMPAREFILETIMES(@ldrive+'\Programs\'+$font,'%windir%\fonts\'+$font)
       COPY @ldrive+'\Programs\'+$font '%windir%\fonts'
       $rc=WRITEVALUE('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts',$description,$font,'REG_SZ')
    ENDIF
 ENDFUNCTION


Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#188596 - 2008-07-07 09:38 PM Re: Convert small VBScript to KiXtart [Re: Kdyer]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Maybe needles to say but just in case you got it all working on your system and it crashes when users run it.
This require admin privileges. Regular user cannot write to HKLM and to %windir%\fonts.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188610 - 2008-07-08 04:27 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
GTManor Offline
Fresh Scripter

Registered: 2008-07-07
Posts: 6
Loc: Cincinnati, OH, USA
I have the InstallFont() UDF working in my test login script. It installs the fonts and does not require the user to reboot the computer to make them available in applications.

However, I am prompted at consecutive logins with a dialog box informing me that the fonts are already installed and asking if I want to overwrite them. Does anyone know of a workaround for this?

Thanks for all of your help!

Top
#188613 - 2008-07-08 06:09 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
I've never tried it with fonts, but you should be able to check to see if the file exists first...

Something like

if not exist("%windir%\fonts\font.ttf")
Installfont
endif
_________________________
(... better days ahead)

Top
#188615 - 2008-07-08 08:22 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
GTManor Offline
Fresh Scripter

Registered: 2008-07-07
Posts: 6
Loc: Cincinnati, OH, USA
The 'IF NOT EXIST' took care of my problem with consecutive logons so I decided to open up my test group and try it on some additional systems.

When running this on other systems (Windows XP w/SP2) it doesnt seem to register the fonts until you browse the %windir%\fonts folder. The fonts are installed in the directory and show up in the registry, but they are not available in the applications (i.e. Word, Excel, etc.) until you browse that folder. I've even tried rebooting in between hoping it would force this but it does not.

Top
#188616 - 2008-07-08 08:29 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
 Originally Posted By: GTManor
When running this on other systems (Windows XP w/SP2) it doesnt seem to register the fonts until you browse the %windir%\fonts folder. The fonts are installed in the directory and show up in the registry, but they are not available in the applications (i.e. Word, Excel, etc.) until you browse that folder. I've even tried rebooting in between hoping it would force this but it does not.


I am not sure what rights you have given your users, but have you tried th4e version that I provided? We had to install a barcode font for users to scan documents in for a centralized scanning solution for a mortgage company I worked for.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#188620 - 2008-07-08 09:09 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
GTManor Offline
Fresh Scripter

Registered: 2008-07-07
Posts: 6
Loc: Cincinnati, OH, USA
Same results using your offering as well. My users have local admin rights on their computers. The fonts are copied to the %windir%\fonts folder and the registry entries are made, but the fonts are not available in an application until you browse the %windir%\fonts folder. Am I missing something? I am currently using your UDF and the following code in my test script:

 Code:
   IF INGROUP("TEST")
     ? "Starting the Avenir Fonts installation..." ? ?
     ? "Please be patient..." ? ?
       FONT('lte50342.ttf','Avenir LT 45 Book (TrueType)')
       FONT('lte50343.ttf','Avenir LT 45 Book Oblique (TrueType)')
       FONT('lte50344.ttf','Avenir LT 65 Medium (TrueType)')
       FONT('lte50345.ttf','Avenir LT 65 Medium Oblique (TrueType)')
       FONT('lte50346.ttf','Avenir LT 95 Black (TrueType)')
       FONT('lte50347.ttf','Avenir LT 95 Black Oblique (TrueType)')
   ENDIF

Top
#188633 - 2008-07-09 02:36 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I will dig into this when I get into the office.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#188640 - 2008-07-09 06:20 PM Re: Convert small VBScript to KiXtart [Re: Kdyer]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I am not sure what the problem is.. I have used the code with quite a few machines..

The only things that come to mind are:
Are the files "Read only"? Is there a permission set? That is, did they come off of a CD and the files may not be quite right...

On another thought.. You could script out the following..
 Code:
explorer.exe /e,/n,%windir%\fonts

Then, kill Explorer...

Thanks,

Kent


Edited by Kdyer (2008-07-09 06:23 PM)
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#188734 - 2008-07-14 03:30 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
GTManor Offline
Fresh Scripter

Registered: 2008-07-07
Posts: 6
Loc: Cincinnati, OH, USA
Is there a way to kill the open Explorer window in the script?
Top
#188737 - 2008-07-14 05:21 PM Re: Convert small VBScript to KiXtart [Re: GTManor]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Sure.
Here’s an example that kills notepad.exe. Internet Explorer would be iexplore.exe.

 Code:
Break on

$process = "notepad.exe"

$rc = KillProcess($process)

If $rc = "0"
	?$process " successfully stopped."
	?"Error code: " $rc
Else
	?$process " NOT successfully stopped."
	?"Error code: " $rc
EndIf
Sleep 5

;DO NOT MODIFY ANYTHING BELOW THIS LINE.
;THIS IS A UDF AND IT COMES READY MADE.
;
;Function	KillProcess() - Kills the Process specified
;   
;Author		Arend Pronk (apronk on the forum)
;   
;Contributors	Chris S. (based on his ProcessMon)
;    		Radimus (his suggestions to change some code)
;   
;Action		Kills the Process specified and returns a 1 for success or 0 for failure  
;   
;Syntax		KillProcess($sProcessName,Optional $sComputer)
;    		Where $sProcessName is the name of the process you are trying to kill
;    		and $sComputer is the name of the computer to kill the process on.
;    		If no computer is specified it is done on the local computer.
;    		Remote computers require this script to be run as an admin of the remote computer 
;   
;Version  	1.0  
;   
;Date		2006-Jan-27 
;   
;Date Revised	2006-Jan-29   
;   
;Revision Reason
;    		Revised per Radimus's suggestions.
;   
;Returns  	0 for success, Errorlevel for failure  
;   
;Dependencies	KiXtart 4.02 Recommend 4.51 or newer 
;   
;KiXtart Ver.	Written and tested with KiXtart v4.52 Beta 2 on Windows XP/2003  
;   
;Example 
;		Dim $KP 
;		$KP = KillProcess("notepad.exe") 
;		If $KP = 0 
;		  ? "Process killed succesfully!" 
;		Else 
;		  ? "Process killing failed!"
;		EndIf 
;   
Function KillProcess($sProcessname, Optional $sComputer)
  Dim $objWMIService, $objInstance, $colItems, $objItem, $strWBEMPath
  If $sComputer = ""
    $sComputer = "."
  EndIf

  $objWMIService = GetObject("winmgmts:\\" + $sComputer + "\root\cimv2")

  If @ERROR
    Exit @error
  EndIf

  $colItems = $objWMIService.ExecQuery("Select * from Win32_Process",,48)

  For Each $objItem In $colItems
    If $objItem.Name = $sProcessname
      $strWBEMPath = "Win32_Process.Handle=" + $objItem.ProcessID
      $objInstance = $objWMIService.Get($strWBEMPath)
      $KillProcess = $objInstance.Terminate(1)
    EndIf
  Next
  Return $KillProcess
EndFunction


[edit]
Beware that killing iexplore.exe will kill ALL internet explorer windows.
Iirc there is a UDF that closes the app you specify but I'm not 100% sure.
You could have a look in the UDF section and browse through the listed UDF's.
[/edit]


Edited by Mart (2008-07-14 05:25 PM)
Edit Reason: Added warning.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 584 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.073 seconds in which 0.031 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org