Re: Python Windows Scripting Engine

Valentin Abrutski <[email protected]> Thu, 1 Aug 2024 23:37:46 +0300
Newsgroups gmane.comp.python.windows
Message-ID <CADtR_MNDx_QgdmOCSFh_h9DAQKEJAOy+9TtiyL0WkTb5ZrcjqQ@mail.gmail.com>
--===============2324119398177611474==
Content-Type: multipart/alternative; boundary="0000000000009281aa061ea530a5"

--0000000000009281aa061ea530a5
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello Mark.

Sorry for bothering you again. I got another issue. When I call
IActiveScript method: SetScriptSite(IActiveScriptSite site)
I got invalid cast exception. Mostprobably it means that
IActiveScriptSite  can't be properly passed as argument to  SetScriptSite.
 My assumption that  my definition of IActiveScriptSite  is different from
one is used in py2in32 library.
I could find usages of   IActiveScriptSite   interface in the source code
of the library. But I can't find definition of this interface.
Can you advise me where I can find it?

On Thu, Aug 1, 2024 at 4:19=E2=80=AFPM Valentin Abrutski <[email protected]> w=
rote:

> Hi Mark, just to let you know. I found the root cause. I was trying to ge=
t
> 32bit version of interface and pywin32 export 64bit version(different GUI=
D
> and slightly different function signature)
>
> Thank you for your help.
>
> On Wed, Jul 31, 2024 at 5:08=E2=80=AFPM Valentin Abrutski <[email protected]=
> wrote:
>
>> Thank you Mark. I will try that. Appreciate
>>
>> =D1=81=D1=80, 31 =D0=B8=D1=8E=D0=BB. 2024=E2=80=AF=D0=B3., 17:01 Mark Ha=
mmond <[email protected]>:
>>
>>> Sorry, I can't explain that - running pyscript.py should register thing=
s
>>> and support for IActiveScriptParse is unconditional. You could try runn=
ing
>>> `pyscript.py --debug` which might print some debug stuff, or even add p=
rint
>>> statements to client.py's QueryInterface function to make sure it's
>>> actually being called. Also, executing
>>> win32comext/axscript/test/testHost.py should try and exercise the engin=
e.
>>>
>>> HTH,
>>>
>>> Mark
>>> On 2024-07-31 9:14 a.m., Valentin Abrutski wrote:
>>>
>>> Hi Mark. Thank you for the idea.  And appreciate your help.
>>>
>>> I tried it. And to be sure that I'm doing it right. I've tried to use
>>> this approach to get not only IActiveScriptParse, but also IActiveScrip=
t
>>> Still the same issue. I can get IActiveScript. But when try to get
>>> IActiveScriptParse I get error code: 0x80004002 (E_NOINTERFACE)
>>>
>>> I've double checked GUID of IActiveScriptParse which is used in
>>> QuearyInterface and it looks correct:  BB1A2AE2-A4F9-11cf-8F20-00805F2C=
D064
>>>
>>> I'm thinking about is it possible that the way I registered Python
>>> Script Engine is not correct? Is it possible that there are different w=
ay
>>> to do that?
>>> Just to remind you, I just run python pyscript.py
>>>
>>>
>>> On Wed, Jul 31, 2024 at 12:58=E2=80=AFAM Mark Hammond <mhammond@skippin=
et.com.au>
>>> wrote:
>>>
>>>>
>>>> On 2024-07-30 4:29 p.m., Valentin Abrutski wrote:
>>>>
>>>> Hi Mark.
>>>>
>>>> I double checked what I did with my previous attempt. And still can't
>>>> get success. Probably you can give me an idea of what I'm doing wrong.
>>>>
>>>> I am working on an application(.Net) which provides scripting
>>>> capabilities via AcriveScript Engine. With the ability to debug script=
 step
>>>> by step and etc. And we provide a standard set of languages VBScript a=
nd
>>>> JScript. And now we want to provide Python support.
>>>>
>>>> Obviously I need to add a new ActiveScript Engine for Python. to syste=
m
>>>>
>>>> What I did. I installed python and installed the pywin32 package.
>>>> Then I found this script
>>>> Python311\Lib\site-packages\win32comext\axscript\client\pyscript.py an=
d run
>>>> it :
>>>> python pyscript.py
>>>>
>>>> Requesting elevation and retrying...
>>>> Registered: Python
>>>>
>>>> After that, I go to my application code and do the same we already do
>>>> for Standard JScript or VBScript engines.
>>>> For example, import of COM JScript class  is defined
>>>>     [ComImport, Guid("F414C260-6AC0-11CF-B6D1-00AA00BBBB58")]
>>>>     public class JScript
>>>>     {
>>>>     }
>>>>
>>>> So I defined import class for Python using GUID from python class
>>>> implementation
>>>>     [ComImport, Guid("DF630910-1C1D-11d0-AE36-8C0F5E000000")]
>>>>     public class PythonScript
>>>>     {
>>>>     }
>>>>
>>>> Then my expectation is that I can cast it to IAcriveScript and
>>>> IActiveScripParse (like I do with standard languages)
>>>>     _engine =3D new PythonScript();
>>>>     _iap =3D _engine as IActiveScriptParse;
>>>>     _ias =3D _engine as IActiveScript;
>>>>
>>>> But IActiveScriptParse still is null, IActiveScript - is good.
>>>> I suppose that probably I did initialization in wrong way? or somethin=
g
>>>> like that?
>>>>
>>>> My best guess is that the "as" isn't working due to a lack of a typeli=
b
>>>> for the engine - but a QueryInterface(IID_IActiveScriptParse) on the
>>>> IActiveScript interface should work.
>>>>
>>>> HTH,
>>>>
>>>> Mark
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Jul 30, 2024 at 10:54=E2=80=AFPM Valentin Abrutski <va@zaptest=
.com>
>>>> wrote:
>>>>
>>>>> Hi Mark
>>>>>
>>>>> Appreciate for fast response. I will look into it. Thank you.
>>>>>
>>>>>
>>>>> On Tue, Jul 30, 2024 at 5:56=E2=80=AFPM Mark Hammond <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> IActiveScriptParse is supported - check out the
>>>>>> com/win32comext/axscript directory.
>>>>>>
>>>>>> Cheers,
>>>>>>
>>>>>> Mark
>>>>>> On 2024-07-30 10:14 a.m., Valentin Abrutski wrote:
>>>>>>
>>>>>> Hello all,
>>>>>>
>>>>>> Hopefully somebody can help me.
>>>>>>
>>>>>> Microsoft provides implementations for Microsoft Scripting Engine -
>>>>>> VbScript and JScript.
>>>>>> I need to add Python Script Engine support. I see that pywin32
>>>>>> already has a component for that(COM object). But it exposes only th=
e
>>>>>> IActiveScript interface. For my needs I also need  IActiveScriptPars=
e
>>>>>> interface.
>>>>>>
>>>>>> please advise me if pywin32 implements it also and I just missed
>>>>>> something? or if you have an idea what to do to get.. I will appreci=
ate for
>>>>>> your help.
>>>>>>
>>>>>> _______________________________________________
>>>>>> python-win32 mailing [email protected]://mail.python.=
org/mailman/listinfo/python-win32
>>>>>>
>>>>>>
>>> _______________________________________________
>>> python-win32 mailing [email protected]://mail.python.org=
/mailman/listinfo/python-win32
>>>
>>>

--0000000000009281aa061ea530a5
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello Mark.<br><br>Sorry for bothering you again. I got an=
other issue. When I call IActiveScript method: SetScriptSite(IActiveScriptS=
ite site)<br>I got invalid cast exception. Mostprobably it means that=C2=A0

IActiveScriptSite=C2=A0 can&#39;t be properly passed as argument to=C2=A0

SetScriptSite.=C2=A0 =C2=A0My assumption that=C2=A0 my definition of IActiv=
eScriptSite=C2=A0 is different from one is used in py2in32 library.<div>I c=
ould find usages of=C2=A0 =C2=A0IActiveScriptSite=C2=A0 =C2=A0interface in =
the source code of the library. But I can&#39;t find definition=C2=A0of thi=
s interface.=C2=A0</div><div>Can you advise me where I can find it?=C2=A0<b=
r></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmai=
l_attr">On Thu, Aug 1, 2024 at 4:19=E2=80=AFPM Valentin Abrutski &lt;<a hre=
f=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<br></div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px=
 solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Hi Mark, just to=
 let you know. I found the root cause. I was trying to get 32bit version of=
 interface and pywin32 export 64bit version(different GUID and slightly dif=
ferent function signature)<div><br></div><div>Thank you for your help.=C2=
=A0</div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gma=
il_attr">On Wed, Jul 31, 2024 at 5:08=E2=80=AFPM Valentin Abrutski &lt;<a h=
ref=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>&gt; wrot=
e:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"a=
uto">Thank you Mark. I will try that. Appreciate=C2=A0</div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">=D1=81=D1=80, 31 =D0=
=B8=D1=8E=D0=BB. 2024=E2=80=AF=D0=B3., 17:01 Mark Hammond &lt;<a href=3D"ma=
ilto:[email protected]" target=3D"_blank">[email protected]=
</a>&gt;:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p=
x 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u=
>

 =20
   =20
 =20
  <div>
    <p>Sorry, I can&#39;t explain that - running pyscript.py should registe=
r
      things and support for IActiveScriptParse is unconditional. You
      could try running `pyscript.py --debug` which might print some
      debug stuff, or even add print statements to client.py&#39;s
      QueryInterface function to make sure it&#39;s actually being called.
      Also, executing win32comext/axscript/test/testHost.py should try
      and exercise the engine.</p>
    <p>HTH,</p>
    <p>Mark<br>
    </p>
    <div>On 2024-07-31 9:14 a.m., Valentin
      Abrutski wrote:<br>
    </div>
    <blockquote type=3D"cite">
     =20
      <div dir=3D"ltr">Hi Mark. Thank you for the idea.=C2=A0 And
        appreciate=C2=A0your help.
        <div><br>
          I tried it. And to be sure that I&#39;m doing it right. I&#39;ve =
tried
          to use this approach to get not only IActiveScriptParse, but
          also IActiveScript
          <div>Still the same issue. I can get IActiveScript. But when
            try to get IActiveScriptParse I get error=C2=A0code:=C2=A0<code=
 style=3D"border-radius:4px;font-size:12px;padding:1px 3px">0x80004002</cod=
e><span style=3D"font-size:13px;color:rgb(204,204,204);font-family:&quot;Se=
goe WPC&quot;,&quot;Segoe UI&quot;,sans-serif;background-color:rgb(24,24,24=
)">=C2=A0(</span><code style=3D"border-radius:4px;font-size:12px;padding:1p=
x 3px">E_NOINTERFACE</code><span style=3D"font-size:13px;color:rgb(204,204,=
204);font-family:&quot;Segoe WPC&quot;,&quot;Segoe UI&quot;,sans-serif;back=
ground-color:rgb(24,24,24)">)</span></div>
          <div><span style=3D"font-size:13px;color:rgb(204,204,204);font-fa=
mily:&quot;Segoe WPC&quot;,&quot;Segoe UI&quot;,sans-serif;background-color=
:rgb(24,24,24)"><br>
            </span></div>
          <div>I&#39;ve double checked GUID of IActiveScriptParse which is
            used in QuearyInterface=C2=A0and it looks
            correct:=C2=A0=C2=A0BB1A2AE2-A4F9-11cf-8F20-00805F2CD064</div>
          <div><br>
          </div>
          <div>I&#39;m thinking about is it possible that the way I
            registered Python Script Engine is not correct? Is it
            possible=C2=A0that there are different way to do that?=C2=A0</d=
iv>
          <div>Just to remind you, I just run=C2=A0<span style=3D"font-fami=
ly:monospace">python pyscript.py=C2=A0</span></div>
          <div><br>
          </div>
        </div>
      </div>
      <br>
      <div class=3D"gmail_quote">
        <div dir=3D"ltr" class=3D"gmail_attr">On Wed, Jul 31, 2024 at
          12:58=E2=80=AFAM Mark Hammond &lt;<a href=3D"mailto:mhammond@skip=
pinet.com.au" rel=3D"noreferrer" target=3D"_blank">[email protected]=
u</a>&gt;
          wrote:<br>
        </div>
        <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div>
            <p><br>
            </p>
            <div>On 2024-07-30 4:29 p.m., Valentin Abrutski wrote:<br>
            </div>
            <blockquote type=3D"cite">
              <div dir=3D"ltr">Hi Mark.=C2=A0<br>
                <br>
                I double checked what I did with my previous attempt.
                And still can&#39;t get success. Probably=C2=A0you can give=
 me an
                idea of what I&#39;m doing wrong.
                <div><br>
                </div>
                <div>I am working on an application(.Net) which provides
                  scripting capabilities via AcriveScript Engine. With
                  the ability to debug script step by step and etc. And
                  we provide a standard set of languages VBScript and
                  JScript. And now we want to provide Python support.</div>
                <div><br>
                </div>
                <div>Obviously I need to add a new ActiveScript Engine
                  for Python. to system</div>
                <div><br>
                </div>
                <div>What I did. I installed python=C2=A0and installed the
                  pywin32 package.</div>
                <div>Then I found this script
                  Python311\Lib\site-packages\win32comext\axscript\client\p=
yscript.py
                  and run it : <br>
                  <font face=3D"monospace">python pyscript.py =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0
                    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
                    =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0
                    =C2=A0 =C2=A0 =C2=A0=C2=A0</font></div>
                <div><font face=3D"monospace">Requesting elevation and
                    retrying...</font></div>
                <div><font face=3D"monospace">Registered: Python</font></di=
v>
                <div><font face=3D"monospace"><br>
                  </font></div>
                <div><font face=3D"arial, sans-serif">After that,=C2=A0I go=
 to
                    my application code and do the same we already do
                    for Standard JScript or VBScript engines.</font></div>
                <div><font face=3D"arial, sans-serif">For example, import
                    of COM JScript class=C2=A0 is defined</font></div>
                <div><font face=3D"monospace">=C2=A0 =C2=A0 [ComImport,
                    Guid(&quot;F414C260-6AC0-11CF-B6D1-00AA00BBBB58&quot;)]=
<br>
                    =C2=A0 =C2=A0 public class JScript<br>
                    =C2=A0 =C2=A0 {<br>
                    =C2=A0 =C2=A0 }</font></div>
                <div><font face=3D"monospace"><br>
                  </font></div>
                <div><font face=3D"arial, sans-serif">So I defined import
                    class for Python using GUID from python class
                    implementation</font></div>
                <div><font face=3D"monospace">=C2=A0 =C2=A0 [ComImport,
                    Guid(&quot;DF630910-1C1D-11d0-AE36-8C0F5E000000&quot;)]=
<br>
                    =C2=A0 =C2=A0 public class PythonScript<br>
                    =C2=A0 =C2=A0 {<br>
                    =C2=A0 =C2=A0 }<br>
                  </font></div>
                <div><font face=3D"monospace"><br>
                  </font></div>
                <div><font face=3D"arial, sans-serif">Then my expectation
                    is that I can cast it to IAcriveScript and
                    IActiveScripParse (like I do with standard
                    languages)</font></div>
                <div><font face=3D"monospace">=C2=A0 =C2=A0 _engine =3D new
                    PythonScript();<br>
                    =C2=A0 =C2=A0 _iap =3D _engine as IActiveScriptParse;<b=
r>
                    =C2=A0 =C2=A0 _ias =3D _engine as IActiveScript;<br>
                  </font></div>
                <div><font face=3D"monospace"><br>
                  </font></div>
                <div><font face=3D"arial, sans-serif">But=C2=A0IActiveScrip=
tParse
                    still is null,=C2=A0IActiveScript - is good.</font></di=
v>
                <div><font face=3D"arial, sans-serif">I suppose that
                    probably I did initialization in wrong way? or
                    something like that?</font></div>
              </div>
            </blockquote>
            <p>My best guess is that the &quot;as&quot; isn&#39;t working d=
ue to a
              lack of a typelib for the engine - but a
              QueryInterface(IID_IActiveScriptParse) on the
              IActiveScript interface should work.</p>
            <p>HTH,</p>
            <p>Mark<br>
            </p>
            <p><br>
            </p>
            <blockquote type=3D"cite">
              <div dir=3D"ltr">
                <div><br>
                </div>
                <div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<br>
                </div>
              </div>
              <br>
              <div class=3D"gmail_quote">
                <div dir=3D"ltr" class=3D"gmail_attr">On Tue, Jul 30, 2024
                  at 10:54=E2=80=AFPM Valentin Abrutski &lt;<a href=3D"mail=
to:[email protected]" rel=3D"noreferrer" target=3D"_blank">[email protected]</a>&=
gt;
                  wrote:<br>
                </div>
                <blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0=
px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                  <div dir=3D"ltr">Hi Mark
                    <div><br>
                    </div>
                    <div>Appreciate for fast response. I will look into
                      it. Thank you.=C2=A0</div>
                    <div><br>
                    </div>
                  </div>
                  <br>
                  <div class=3D"gmail_quote">
                    <div dir=3D"ltr" class=3D"gmail_attr">On Tue, Jul 30,
                      2024 at 5:56=E2=80=AFPM Mark Hammond &lt;<a href=3D"m=
ailto:[email protected]" rel=3D"noreferrer" target=3D"_blank">mhamm=
[email protected]</a>&gt;
                      wrote:<br>
                    </div>
                    <blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                      <div>
                        <p>IActiveScriptParse is supported - check out
                          the com/win32comext/axscript directory.</p>
                        <p>Cheers,<br>
                        </p>
                        <p>Mark<br>
                        </p>
                        <div>On 2024-07-30 10:14 a.m., Valentin Abrutski
                          wrote:<br>
                        </div>
                        <blockquote type=3D"cite">
                          <div dir=3D"ltr">Hello all,=C2=A0
                            <div><br>
                            </div>
                            <div>Hopefully somebody can help me.</div>
                            <div><br>
                            </div>
                            <div>Microsoft provides implementations for
                              Microsoft Scripting Engine - VbScript and
                              JScript.</div>
                            <div>I need to add Python Script Engine
                              support. I see that pywin32 already has a
                              component for that(COM object). But it
                              exposes only the IActiveScript interface.
                              For my needs I also need=C2=A0
                              IActiveScriptParse interface.=C2=A0<br>
                              <br>
                              please advise me if pywin32 implements it
                              also and I just missed something? or if
                              you have an idea what to do to get.. I
                              will appreciate for your help.</div>
                          </div>
                          <br>
                          <fieldset></fieldset>
                          <pre>____________________________________________=
___
python-win32 mailing list
<a href=3D"mailto:[email protected]" rel=3D"noreferrer" target=3D"_bl=
ank">[email protected]</a>
<a href=3D"https://mail.python.org/mailman/listinfo/python-win32" rel=3D"no=
referrer" target=3D"_blank">https://mail.python.org/mailman/listinfo/python=
-win32</a>
</pre>
                        </blockquote>
                      </div>
                    </blockquote>
                  </div>
                </blockquote>
              </div>
            </blockquote>
          </div>
        </blockquote>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
python-win32 mailing list
<a href=3D"mailto:[email protected]" rel=3D"noreferrer" target=3D"_bl=
ank">[email protected]</a>
<a href=3D"https://mail.python.org/mailman/listinfo/python-win32" rel=3D"no=
referrer" target=3D"_blank">https://mail.python.org/mailman/listinfo/python=
-win32</a>
</pre>
    </blockquote>
  </div>

</blockquote></div>
</blockquote></div>
</blockquote></div>

--0000000000009281aa061ea530a5--

--===============2324119398177611474==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32

--===============2324119398177611474==--