Tim
Wed Mar 03 10:48:10 CST 2004
"Viatcheslav V. Vassiliev" <msnewsgroup@www-sharp.com> wrote in message
news:#f0N7RPAEHA.2660@TK2MSFTNGP10.phx.gbl...
> You can not. If application is not started from script (or other way with
> CreateObject("...")), its Application object may be even not initialized.
> COM does not have methods to get root object for the application.
>
> //------------------------------------
> Regards,
> Vassiliev V. V.
>
http://www-sharp.com -
> Scripting/HTA/.Net Framework IDE
Viatcheslav,
Thanks for the reply - I was afraid that might be the case.
Tim.
>
> "Tim Williams" <saxifrax at pacbell dot net> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ
> ÓÌÅÄÕÀÝÅÅ: news:ONvGP4LAEHA.2040@TK2MSFTNGP12.phx.gbl...
> > Soo Kuan ,
> >
> > Your code is functionally the same as my original js: it doesn't solve
> the
> > underlying question I have.
> >
> > That is, how do I use "App" (or convert App) so that I can use it to
call
> > the application's COM-exposed properties and methods ??
> >
> > Eg:
> >
> > For Each App In
> > GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select
*
> > from Win32_process Where Name Like 'myappname.exe'")
> > Wscript.echo App.Name ' OK
> > Wscript.echo App.Path '* Fails* with "application does not
support
> > this property or method"
> > Next
> >
> > APP.Name is fine, but App.Path is not recognised as a property of this
> > particular object, although the application in question *does* expose a
> > "Path" property.
> > Imagine the application was Excel: for example can I get to the Excel
> > "Workbooks" collection via "App".
> >
> > Thanks
> > Tim.
> >
> >
> > "Soo Kuan Teo [MS]" <sookuant@online.microsoft.com> wrote in message
> > news:eqQ3bZLAEHA.3828@TK2MSFTNGP10.phx.gbl...
> > > If I understand your question correctly, the following may be what you
> > need:
> > > For Each App In
> > >
GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select
> *
> > > from Win32_process Where Name Like 'myappname.exe'")
> > > Wscript.echo App.Name
> > > Next
> > >
> > > --
> > > This posting is provided "AS IS" with no warranties, and confers no
> rights
> > >
> > >
> > > "Tim Williams" <saxifrax at pacbell dot net> wrote in message
> > > news:#EJmk$KAEHA.3352@TK2MSFTNGP09.phx.gbl...
> > > >
> > > > "Robert Cohen" <dont@want.spam.com> wrote in message
> > > > news:ONru4CKAEHA.4012@tk2msftngp13.phx.gbl...
> > > > > why not post to a javascript group
> > > > >
> > > > > --
> > > > > Robert Cohen
> > > > > A legend in his own mind
> > > > > --
> > > >
> > > > I thought I had (although also included a couple of others). It's
not
> a
> > > > language-specific problem I'm having - really an interface issue.
> > > > I included the vbscript group because it seems to be a popular
> language
> > > for
> > > > this type of scripting.
> > > >
> > > > For those more comfortable with vbscript though, here it is again:
> > > >
> > > > For Each App In
> > > >
> > >
> >
>
GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_pr
> > > > ocess")
> > > > if ucase(App.Name)="MYAPPNAME.EXE" then
> > > > Msgbox "Found: " & App.Name & " " & App.Handle
> > > > end if
> > > > Next
> > > >
> > > > I'd like to find out if there's a way to convert the object
referenced
> > by
> > > > "App" to a scriptable reference through which I can access the COM
> > > > properties/methods exposed by the application.
> > > >
> > > > Thanks again,
> > > >
> > > > Tim.
> > > >
> > > >
> > > >
> > > > >
> > > > > "Tim Williams" <saxifrax at pacbell dot net> wrote in message
> > > > > news:uE24g7JAEHA.1036@TK2MSFTNGP10.phx.gbl...
> > > > > >
> > > > > > After having no luck using GetObject (I need to differentiate
> > between
> > > > two
> > > > > or
> > > > > > more already running instances of an application) I'm a little
out
> > of
> > > my
> > > > > > depth with this code (below). It does work - in that it returns
> the
> > > > right
> > > > > > count - but is there any way to use the "App" variable to get a
> > > > scriptable
> > > > > > reference to the particular application instance? This is an
app
> > that
> > > > is
> > > > > > COM scriptable.
> > > > > >
> > > > > > I can't just open a new instance and use that: I need to add
data
> to
> > > one
> > > > > of
> > > > > > the running instances.
> > > > > >
> > > > > > Appreciate any assistance. Apologies for posting javascript to
a
> > > > vbscript
> > > > > > group!
> > > > > >
> > > > > > Regards
> > > > > > Tim.
> > > > > >
> > > > > > // return the number of instances
> > > > > > function InstanceCount(){
> > > > > > var iCount=0;
> > > > > > var Apps = new
> > > > > >
> > > > >
> > > >
> > >
> >
>
Enumerator(GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesO
> > > > > > f("Win32_process"));
> > > > > > for (; !Apps.atEnd(); Apps.moveNext()) {
> > > > > > var App = Apps.item();
> > > > > > if(App.Name.toUpperCase()=="MYAPPNAME.EXE") iCount++;
> > > > > > }
> > > > > > return iCount;
> > > > > > }
> > > > > >
> > > > > > var s= new ActiveXObject("WScript.Shell");
> > > > > > s.Popup(InstanceCount());
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>