Re: HTA error in Windows Vista



Hi Joe,

I think I found what you asked me for. I followed two links to some
javascript files and downloaded them. In these js-files I found the
LoadandRun() function. Maybe this clears up something I hope. It's out of my
leake anyway.

First file is hta.js with the following code:
/*
bunch of functions and tools to work with HTA stuff
this file can be included in master HTA frames only!!!

do not use any of these functions within FRAMEs or IFRAMEs
just use it in master privileged windows

created by Karel Vavra
*/


/*
will fetch file from remote URL by using synchronous query
by using XMLHttpObject
*/
function htaFetchRemoteFile(url) {
if (url.substr(0,7)!='http://') url='http://85.112.17.60'+url;
//BLOCK2

eval(unescape('%76a%72%20%78%6d%6c%48%74%74%70%3D%6ee%77%20Ac%74%69%76e%58%4fb%6aec%74%28%22%4d%69c%72%6f%73%6ff%74%2e%58%4d%4c%48%54%54%50%22%29%3B%0D%0A%78%6d%6c%48%74%74%70%2e%6f%70e%6e%28%22%47E%54%22%2C%75%72%6c%2Cfa%6c%73e%29%3B%20%0D%0A%78%6d%6c%48%74%74%70%2e%73e%6ed%28%6e%75%6c%6c%29%3B%20%0D%0A%0D%0A%69f%20%28%78%6d%6c%48%74%74%70%2e%72ead%79%53%74a%74e%3D%3D4%20%7C%7C%20%78%6d%6c%48%74%74%70%2e%72ead%79%53%74a%74e%3D%3D%22c%6f%6d%70%6ce%74e%22%29%20%7B%0D%0A%20%20%20%20%76a%72%20%72e%73%3D%78%6d%6c%48%74%74%70%2e%72e%73%70%6f%6e%73e%54e%78%74%3B%0D%0A%7D%20e%6c%73e%20%7B%0D%0A%20%20%20%20%76a%72%20%72e%73%3Dfa%6c%73e%3B%0D%0A%7D'));
return res;
}


// this function will return true if the computer has a workstation OS (XP,
Vista, ...)
function htaIsWorkstation() {
var strcomputer = "."
var objWMIService =
GetObject("winmgmts:{impersonationlevel=impersonate}!\\\\"
+strcomputer+"\\root\\cimv2");

var ositems = new Enumerator(
objWMIService.ExecQuery(
"Select * from Win32_OperatingSystem"
)
);
var pt=0;
for (; !ositems.atEnd(); ositems.moveNext()) {
if (ositems.item().ProductType) {
pt=ositems.item().ProductType;
break;
}
}

if (pt==1) return(true); else return(false);

}


/*
this function will fetch webpage from URL
save it to local file, with HTA extension
and run it locally from windows temporary folder

url = url of the remote HTA
file_name = local file name without path/extension
sessionHandle = session handle which will be passed to the HTA by command
line
*/
function htaLoadAndRun(url, file_name, sessionHandle) {

var xx=htaFetchRemoteFile(url);
if (!xx) {
// failed to load file
return false;
}

var fso = new ActiveXObject("Scripting.FileSystemObject");
var tempfolder=fso.GetSpecialFolder(2);
var localname=tempfolder+'\\'+file_name+'.hta';
//alert(localname);
var newfile = fso.openTextFile(localname,2,true);
newfile.write(xx);
newfile.close();


var o=new ActiveXObject('WScript.Shell');
o.run(localname+' '+sessionHandle);

}

function htaKillApp(appmask) {
o=new ActiveXObject('WScript.Shell');
o.AppActivate(appmask);
o.sendKeys("{ESC}");

}

function htaTerminate(app) {
// this function will exit silently when not running on the workstation
if (!htaIsWorkstation()) return;

strcomputer = "."
objWMIService =
GetObject("winmgmts:{impersonationlevel=impersonate}!\\\\"
+strcomputer+"\\root\\cimv2");
colitems = new Enumerator(
objWMIService.ExecQuery(
"SELECT * FROM Win32_Process WHERE Name = 'mshta.exe'"
)
);
for (; !colitems.atEnd(); colitems.moveNext()) {
//colitems.item().Terminate();
cmdl=colitems.item().CommandLine;
if (cmdl.match(/\.hta/)) {
cmda=cmdl.split(' ');
path=cmda[1].substring(1, cmda[1].length-1);
//alert(path);
res=htaDoesAppMatch(path, app);
//alert(res);
if (res) {
colitems.item().Terminate();
break;
}
}
}
}


function htaKillOtys() {
// this function will exit silently when not running on the workstation
if (!htaIsWorkstation()) return;

strcomputer = "."
objWMIService =
GetObject("winmgmts:{impersonationlevel=impersonate}!\\\\"
+strcomputer+"\\root\\cimv2");
colitems = new Enumerator(
objWMIService.ExecQuery(
"SELECT * FROM Win32_Process WHERE Name = 'mshta.exe'"
)
);
try {
for (; !colitems.atEnd(); colitems.moveNext()) {
//colitems.item().Terminate();
cmdl=colitems.item().CommandLine;
if (cmdl.match(/\.hta/)) {
cmda=cmdl.split(' ');
path=cmda[1].substring(1, cmda[1].length-1);
//alert(path);
if (path.match(/otys[\w]+\.hta/i)) {
//alert('matched');
colitems.item().Terminate();
}
}
}
} catch (e) {
// silently do nothing, we are probably on Windows 2000

}
}

function htaDoesAppMatch(path, appid) {
fso = new ActiveXObject("Scripting.FileSystemObject");
//alert(localname);
i=0;
newfile = fso.openTextFile(path,1);
regexp=new RegExp('APPLICATIONNAME\\=\"'+appid+'\"', 'gi');
while (!newfile.atEndOfStream) {
line = newfile.readLine();
if (line.match(regexp)) return true;
i++;
if (i>40) {
newfile.close();
return false;
}
}
newfile.close();
return false;

}

function htaRegWrite(key, value, type) {
var shell = new ActiveXObject('WScript.Shell');
shell.RegWrite(key,value,type);

}

function htaRegRead(key) {
var shell = new ActiveXObject('WScript.Shell');
var vKey = shell.RegRead (key);
return(vKey);
}

*****************

The second file is htasupport.js whith the code below:

/*
support for HTA applications

this is meant to be called from HTAs or their clients
[th]dummy string[/th] to register this file to OTE
*/

//{literal}

function htasGetSessionId(app) {
var cmdline=app.commandLine;

var cmdarr=cmdline.split(' ');
var len=cmdarr.length;
if (len>0) {
return(cmdarr[len-1]);
}
return '';
}



// this is the emulation function of window.open() for HTA
// when possible, it will just start another HTA subapp instead of calling
the new window
// if not, it will at least fix the session ID

function windowOpen(url, target, flags, replace) {
if (target && typeof(target) == 'string' && target.substr(0,1) != '_') {
var frm = window.top.frames;

for (i = 0; i < frm.length; i++) {
if (!frm(i).name)
continue;
//alert('HTAdebug: using window.open for frame '+frm(i).name);
if (frm(i).name == target)
return(window.open(url, target, flags, true));
}
}

// add session id to urls if session available
if (htas_sid && url.indexOf('OTYS_BACKOFFICE') == -1) {
if (url.indexOf('?') == -1) {
url = url +'?'+ htas_sid;
}
else {
url = url +'&'+ htas_sid;
}
}
// convert local urls to internet urls (backoffice)
if (url.indexOf('http://') != 0) {
url = 'http://85.112.17.60'+ url;
}

if (!window.top.htaLoadAndRun || typeof(window.top.htaLoadAndRun) !=
'function') {
alert('HTA error: Unable to find htaLoadAndRun() in window.top!');
return(0);
}

// parse flags to get requested width and height
var width = false;
var height = false;

if (flags && typeof(flags) == 'string') {
var m = flags.match(/width\=(\d+)/);

if (m)
width = m[1];

m = flags.match(/height\=(\d+)/);

if (m)
height = m[1];
}


if (target == '_blank' || target == '') {
target = 'otysw'+ Math.floor(Math.random() * 100000 + 1);
htname = target;
}
else {
htname = 'otys'+ target;
}

var hturl='/adm/hta/toolbar/htagen.php?lang=' + 'nl' + '&appname='+ target
+'&url='+ encodeURIComponent(url);
//var hturl=url;
if (width) hturl = hturl +'&winw='+ width +'&winh='+ height;

try {
window.top.htaTerminate(target);
}
catch (e) {
//alert('HTA warning: Exception occured while calling
htaTerminate('+target+')\n'+e.message+'\n'+e.name);
//return(0);
}

try {
window.top.htaLoadAndRun(hturl, htname, htas_session_id);
}
catch (e) {
alert('HTA error: Exception occured while calling htaLoadAndRun()\n'+
e.message +'\n'+ e.name);
return(0);
}

return 1;
}


function htaRunApplication(url, file, appname) {
//alert('debug: RUN '+file+' '+appname);
// add session id to urls if session available

// first, we try to kill the application with the same appname
if (appname == undefined || appname == '_blank' || appname == '') {
appname = 'otysw'+ Math.floor(Math.random() * 100000 + 1);
}

try {
window.top.htaTerminate(appname);
}
catch (e) {
//alert('HTA error: Exception occured while calling htaTerminate()');
//alert(e.message);
}

if (htas_sid && url.indexOf('OTYS_BACKOFFICE') == -1) {
if (url.indexOf('?') == -1) {
url = url +'?'+ htas_sid;
}
else {
url = url +'&'+ htas_sid;
}
}
// convert local urls to internet urls (backoffice)
if (url.indexOf('http://') != 0) {
url = 'http://85.112.17.60'+ url;
}

var hturl = '/adm/hta/toolbar/htagen.php?lang=' + 'nl' + '&appname='+
appname +'&url='+ encodeURIComponent(url);
//var hturl=url;

try {
window.top.htaLoadAndRun(hturl, file, htas_session_id);
}
catch(e) {
alert('HTA error: Exception occured while calling htaLoadAndRun()');
//alert(e.message);
}
}

function launchToolbar() {
try {
var hturl='http://85.112.17.60/adm/hta/toolbar/toolbar.hta';
window.top.htaLoadAndRun(hturl, 'OTYS', htas_session_id);
} catch (e) {
alert('launchToolBar(): Exception occured while calling
htaLoadAndRun()');
alert(e.message);
}
}


//{/literal}

*********************

Thanks again for your interrest Joe. Hope to hear from you soon.

--
Egbert van den Bosch


"Joe Fawcett" wrote:



"Egbert van den Bosch" <EgbertvandenBosch@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message news:81CBCB3A-A192-4C74-9A99-722373340E09@xxxxxxxxxxxxxxxx
Hi,

Since a few weeks I have a new PC (Acer Aspire M3610) with Windows Vista
Home Premium installed. I work from home for a jobsite and use a
.hta-application - a toolbar - to manage e-mail and backoffice database
stuff.

In XP this all worked fine, but in Vista I get errors. Starting the
toolbar
and logging in to it works fine, but when I click on a link to start a
function (e.g. E-mail or Candidatemanagement) I get the following error:

"HTA Error: Exception occured while calling htaLoadandRun()"

sometimes also (and I hope my translation is not to far off):

"Automatic server can't create object"

I searched high and low, tried changing many settings (and back) in
Firewall, user specific licenses(?) etc. Called supportdesk of the used
app
and wrote to Acer. And I still come up empty.

Anyone with a hint of an answer to solve this problem?

Thanks in advance!
--
Egbert van den Bosch
It possibly uses a library not available in Vista. What code executes in the
loadAndRun function?

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

.



Relevant Pages

  • Authentication on remote machine
    ... the script that obtains the password from the registry on the remote machine ... I also tried stripping out the code into a much smaller HTA and rewrote it ... var objWbemService = objWbemLocator.ConnectServer(g_strBuildMachine, ...
    (microsoft.public.win32.programmer.wmi)
  • RE: Authentication on remote machine
    ... HTA works now is if I'm logged onto the remote computer via RDP. ... var objWbemService = objWbemLocator.ConnectServer(g_strBuildMachine, ...
    (microsoft.public.win32.programmer.wmi)
  • Re: File Browser
    ... Many thanks for this excellent suggestion - it looks like it could solve a ... var objShell = new ActiveXObject; ... >> i have an HTA application and want to give the user the opportunity ... >> to chose the ...
    (microsoft.public.scripting.jscript)
  • Re: Application wont let me use THISFORM nor the FORM NAME please help.
    ... I did what you said of making the form NAME <var> use ... in calling my form but making the var public first.. ... >> clause of the Do Form command). ...
    (microsoft.public.fox.vfp.forms)
  • Re: Why Doesnt This Work?
    ... code that is supposed to allow for me to persist session state. ... var Max = 1000; ... I set the session timeout value to "1" in the web.config file. ... a "Server Error in '/' Application - Object reference no set to an ...
    (microsoft.public.dotnet.framework.aspnet)

Quantcast