[Distutils] VBScript puzzle

Bill Janssen janssen at parc.com
Mon Apr 26 21:33:30 CEST 2010


Jess Austin <jess.austin at gmail.com> wrote:

> On Mon, 22 Mar 2010 at 21:25:55,  "Martin v. L?wis" <martin at v.loewis.de> wrote:
> > As this might be an interesting puzzle to solve, I'd like to pose it to
> > the entire distutils-sig readership. So here is the problem again:
> >
> > As a batch file, my attempt at having a batch file that is also a
> > Python script was to write it as
> >
> > rem="""
> > %1 %0
> > exit
> > """
> > <python code here>
> >
> > This should have been run with argv[1] being the path to the Python
> > interpreter. As a batch file, the first line is a comment, the second
> > line runs Python, anbd the third line terminates the script (so it
> > doesn't consider the following lines). As a Python script, the first
> > block is a variable assignment, followed by the regular Python script.
> >
> > Now (as Installer won't run batch files) we need the same as VBScript
> > (or, failing that, as JScript). The script would be computed at the time
> > of MSI generation.
> 
> I couldn't get this to work as VBScript (that requires too many line
> continuation characters), but I think the following JScript should
> work.  The call to WShell.Run() pops another window, so I included a
> time.sleep() call to make that slow enough to notice.  Fortunately
> JScript and python both will happily ignore integer and string
> literals at the beginning of the file, and JScript comments look like
> python floor division.  I ran this at the command line like so:
> 
> 
> C:\>cscript bdist.js "Python26\python.exe"
> 
> 
> Here's the script:
> 
> 
> 4 // 3; '''
> ;
> if (WScript.Arguments.Count() < 1)
>   WScript.Echo("usage: " + WScript.ScriptName + " <path to python>");
> else
>   WScript.CreateObject("WScript.Shell").Run(WScript.Arguments.Item(0) + " " +
>                                             WScript.ScriptFullName, 1, true); /*
> '''
> # start of python script
> from time import sleep
> print("hello from python")
> sleep(5)
> # end of python script */

Note that JScript run under the MSI context (custom action type 5)
doesn't have access to the WScript object.  It's restricted to
the set of objects accessible under the installer.

http://msdn.microsoft.com/en-us/library/aa367810(VS.85).aspx

Might be able to invoke "wscript.exe" to run the script, making it a
type 50 custom action.  But apparently that ability is frequently
disabled by a group policy.

Bill


More information about the Distutils-SIG mailing list