For those of you who are interested in using HTAs Thread last updated on 2006-08-22 15:58:25

Posted by member 321598 on 2006-08-12 06:01:37

Here's a little library I wrote for my HTA programs. Just copy and paste and save it as LSlib.js (or anything). And include it in your HTA.

There's basically 5 functions

(1)Read_Evars(File) - Reads all Evars from a file and returns two arrays of Evar Names and Evar Values.

(2)Save_Evars(File,Evar_Names,Evar_Vals) - Write the evars to the file, it overwrites everything in the destination file, so you have to have all the evars in it.

(3)Read_Evar(File,Evar_Name) - Reads a single evar from a file.

(4)Save_Evar(File,Evar_Name,Evar_Val) - Saves a single evar to a file.

(5)Set_Evar(Evar_Name,Evar_Val) - Uses !SetEvar from xLabel to set an evar value

(6)Exec_Bang(Bang) - Executes the Bang

I'm also thinking of adding a Get_evar function to get the evar value from memory, but I don't think I'll be using it though.

//Get litestep process path
var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var objProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'litestep.exe'");
var enumProcess = new Enumerator(objProcess);
var lspath = enumProcess.item().ExecutablePath;
//Create file objects for reading/writing text
var objPref=new ActiveXObject("Scripting.FileSystemObject");
//create shell
var objShell = new ActiveXObject("WScript.Shell");

//Function to read in evars
function Read_Evars(File) {
// Open Preference file
var objPFile=objPref.GetFile(File)
var objPData = objPFile.OpenAsTextStream(1, 0 );
//Define variables
var curr_line;var Curr_Evar=new Array();
Evar_Heads=new Array();Evar_Values=new Array();
// Read Evars
for(count=0; !objPData.AtEndOfStream; count++){
curr_line = objPData.ReadLine();
Curr_Evar = curr_line.split(" ");
Evar_Heads[count]=Curr_Evar[0];
Evar_Values[count]=Curr_Evar[1].slice(1,-1);
}
//close file
objPData.Close();
return [Evar_Heads,Evar_Values]
}
//Function to save evars
function Save_Evars(File,Evar_Names,Evar_Vals) {
// Open Preference file
var objPFile=objPref.GetFile(File)
var objPData = objPFile.OpenAsTextStream(2, 0 );
//Write Evars
for(count=0; count < Evar_Heads.length; count++){
objPData.Write(Evar_Names[count]+' "'+Evar_Vals[count]+'"\n');
}
//close file
objPData.Close();
}
function Read_Evar(File,Evar_Name) {
// Open Preference file
var objPFile=objPref.GetFile(File)
var objPData = objPFile.OpenAsTextStream(1, 0 );
//Define variables
var Evar_Val;
var curr_line; var Curr_Evar=new Array();;
Evar_Heads=new Array();Evar_Values=new Array();
// Read Evars
for(count=0; !objPData.AtEndOfStream; count++){
curr_line = objPData.ReadLine();
Curr_Evar = curr_line.split(" ");
Evar_Heads[count]=Curr_Evar[0];
if (Evar_Heads[count]==Evar_Name) {Evar_Val=Curr_Evar[1].slice(1,-1);break}
}
//close file
objPData.Close();
return Evar_Val
}
//Function to save a single evar
function Save_Evar(File,Evar_Name,Evar_Val) {
//Open Preference file
var objPFile=objPref.GetFile(File)
var objPData = objPFile.OpenAsTextStream(1, 0 );
//Read all data to string
var Text=objPData.ReadAll();
objPData.Close();
//Open again for writing
objPData=objPFile.OpenAsTextStream(2, 0 );
//Split at each line
Text=Text.split("\n");
//Loop through the file until evar is found
for (count=0;count < Text.length;count++){
if (Text[count].match(Evar_Name)) {objPData.Write(Evar_Name + ' "'+Evar_Val+'"\n');}
else{
objPData.Write(Text[count]);
//Prevent trailing empty lines
if (Text[count]!=""){objPData.Write("\n");}
}
}
objPData.Close();
}
//Function to set Evar value (Uses xLabel's !SetEvar)
function Set_Evar(Evar_Name,Evar_Val) {
//Create bang
Bang="!SetEvar "+Evar_Name+" "+Evar_Val;
//Pass bang to LS
Exec_Bang(Bang);
}
//Function to get Evar value

//Function to execute bang
function Exec_Bang(Bang){
//Pass bang to LS
objShell.Run(lspath + " " + Bang);
}

Posted by member 321598 on 2006-08-12 06:03:43 link

Edit: Hmm, odd behavior, I thought the thread truncated my posts due to word limit, turns out wasn't the case.

Posted by member 248213 on 2006-08-12 07:32:51 link

wow too cool!

Posted by member 5575 on 2006-08-12 11:38:11 link

Hmmm, should we post the vbscript equivalents, frac?

Posted by member 1885 on 2006-08-12 12:01:53 link

Does the Explorer shell count as an HTA program, i.e. a Highly Tiresome Application?

Posted by member 5575 on 2006-08-12 12:06:53 link

It certainly fits *that* acronym,

Posted by member 248213 on 2006-08-12 13:57:40 link

I dunno Brian, I guess that we could.
You could also post your wallpaper changer code too.

Oh yeah and I sent Tobbe those tools to play with, maybe he might possibly use them maybe in his installer maybe.

Posted by member 5575 on 2006-08-12 14:24:38 link

I need to implement some thumbnail caching though. It's too slow to switch between pages when you display more than 4 thumbnails on a page.