...

View Full Version : 2 questions actually...



Code Wizard
01-01-2004, 12:22 AM
1st of all....
var IE=new ActiveXObject("InternetExplorer.Applicaiton")
makes a new IE instance,I want to connect to the current running instance..HOW?
2nd......
what is GetObject() useful for? I need an example...

oh and almost 4got:
Happy new year!
:thumbsup:

swmr
01-01-2004, 01:41 AM
I don't know much about the GetObject method (- always get an error...), but there are WMI scripts that use it successfully. The link to the W2k Scripting Guide (in my sig) has examples.

Here's an IE object script (.wsf) that I've been working on; maybe it will give you some ideas:



<job>
<object id="ie" classid="0002DF01-0000-0000-C000-000000000046"/>

<script language="Jscript">

sPath = WScript.ScriptFullName;
sPath = sPath.slice(0, sPath.indexOf(WScript.ScriptName));
sPath = sPath.replace(/(\\)/g,"\\\\");

pageCode =
"<html><head>" +
"<title>Windows Media Player 6.4<\/title>" +
"<\/head><body style=\"margin:0;padding:0;background:threedface\" scroll=no >" +
"<OBJECT id=mp classid=clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95>" +
"<\/object>" +
"<br>" +
"<select size=1 id=s onchange=pList(this.options[this.selectedIndex].value)>" +
"<option value=0 style=\"background-color:buttonface;color:buttontext\">Select an Album" +
"<option value=Playlist1.m3u>Playlist1" +
"<option value=Playlist2.m3u>Playlist2" +
"<option value=Playlist3.m3u>Playlist3" +
"<option value=Playlist4.m3u>Playlist4" +
"<option value=Playlist5.m3u>Playlist5" +
"</select>" +
"<\/body>" +

"<script type=\"text\/JScript\">" +
"function cSize(){" +
"mp.showControls = 0;" +
"var x = new Number(mp.offsetHeight + mp.offsetTop);" +
"mp.showControls = 1;" +
"var y = new Number(mp.offsetHeight + mp.offsetTop);" +
"mp.style.height = y - x;" +
"s.style.width = mp.offsetWidth;" +
"var z = mp.offsetHeight + mp.offsetTop + s.offsetHeight;" +
"winPos(z);}" +

"function winPos(h){" +
"var ow = (mp.offsetWidth + mp.offsetLeft) - document.body.clientWidth;" +
"var oh = (h) - document.body.clientHeight;" +
"var sw = screen.availWidth;" +
"var sh = screen.availHeight;" +
"window.resizeBy(ow, oh);" +
"window.moveTo((sw - document.body.clientWidth)/2,(sh - document.body.clientHeight)/2);}" +

"function pList(fName){" +
"var pFix = " + "\"" + sPath + "\"" + ";" +
"mp.FileName = pFix + fName;}cSize();" +
"<\/script>" +
"<\/html>";


ie.RegisterAsBrowser = 1;ie.RegisterAsDropTarget = 0;
ie.AddressBar = 0;ie.MenuBar = 0;ie.ToolBar = 0;
ie.StatusBar = 0;ie.Top = 0;ie.Left = 0;
ie.Resizable = 0;ie.FullScreen = 0;
ie.TheaterMode = 0;ie.Silent = 0;

ie.navigate("about&#58;blank");
ie.Width = ie.document.parentWindow.screen.availWidth;
ie.Height = ie.document.parentWindow.screen.availHeight;

ie.document.open();
ie.document.write(pageCode);
ie.document.close();

ie.visible=1;

</script>
</job>


You'd need to have the .m3u (or other media) files in the same folder as the windows script file, for this to work.

swmr
01-01-2004, 05:33 AM
:rolleyes: Oh, I may have misread your question about IE...

Using WMI via WSH will allow you to connect to an open process of the browser.

This example will activate the last-active document:

<job>
<script language="JScript">
var WMI, IE, procID;
WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
IE = new Enumerator(WMI.InstancesOf("Win32_process Where Name = 'IEXPLORE.EXE'"));
for (;!IE.atEnd();IE.moveNext()){procID = IE.item().Handle;}
if(procID != undefined){new ActiveXObject("WScript.Shell").AppActivate(procID);}
else{WScript.Echo("no process of IE detected")}
</script>
</job>

(& that's about all I know how to do, so far): ;)

Code Wizard
01-01-2004, 10:44 AM
Nice....thx 4 the script there swmr.
Also how can I call WScript methods inside IE?
Like when I want to WScript.Echo() something??

swmr
01-01-2004, 03:11 PM
Not that I'm aware of, though it is possible to run an argument through a Windows Script File, which could then echo it back:

somePage.html

<html>
<head><title>WScript argument echo</title>
<script type="text/JScript">
function RunMethod(){
var wSs, WsFile, Arg;
wSs = new ActiveXObject("WScript.Shell");
WsFile = "C:\\someFolder\\aSubFolder\\myFile.wsf";
Arg = "\"My echoed argument";
wSs.Run(WsFile + " " + Arg, 0, true);
}
</script>
</head>
<body>
<button onclick="RunMethod()">test</button>
</body>
</html>


------------------------------------------------------------------------------

myFile.wsf

<job>
<script language="JScript">
WScript.Echo(WScript.Arguments.item(0));
</script>
</job>

Code Wizard
01-10-2004, 12:35 PM
Originally posted by swmr
:rolleyes: Oh, I may have misread your question about IE...

Using WMI via WSH will allow you to connect to an open process of the browser.

This example will activate the last-active document:

<job>
<script language="JScript">
var WMI, IE, procID;
WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
IE = new Enumerator(WMI.InstancesOf("Win32_process Where Name = 'IEXPLORE.EXE'"));
for (;!IE.atEnd();IE.moveNext()){procID = IE.item().Handle;}
if(procID != undefined){new ActiveXObject("WScript.Shell").AppActivate(procID);}
else{WScript.Echo("no process of IE detected")}
</script>
</job>

(& that's about all I know how to do, so far): ;)



That doesn't seem to work.....
I don't want the code from a WSH file,but code that would work inside IE,to acces the instance.
I just can't figure out why: IE=GetObject("InternetExplorer.Application") doesn't return the current running instance of IE....
Any help is welcomed.

Code Wizard
01-10-2004, 03:33 PM
This is taken from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/constructing_a_moniker_string.asp

It is not possible to use the GetObject function provided by VBScript and JScript when running scripts embedded within an HTML page, as Microsoft® Internet Explorer disallows the use of this call for security reasons.


So,this means that accesing the IE instance from which the script is executed isn't possible using WMI and GetObject().
Anyway,how can I acces the instance that is activated(focused) in this script(that is,how can I get a handle to it)?

swmr
02-04-2004, 10:07 PM
how can I get a handle to it

As far as I know, the "process id" is the handle.

Whether anything significant can be done with that is beyond me, but I'd guess that WMI would provide the method.

Have fun reading. ;)

BTW, if you're trying to do this outside of your local security zone, its not likely to ever work -- as you might have guessed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum