mhammond / pywin32

Python for Windows (pywin32) Extensions
5.05k stars 796 forks source link

windows script host behaviour changes after pywin32 install #529

Open ghost opened 13 years ago

ghost commented 13 years ago

Hi,

This problem has been reported on http://pythonforum.org/topic62-pywin32-and-windows-script-host-problem.html.

I'm experiencing the same problem.

The bug is reproductible (validated with http://surfnet.dl.sourceforge.net/sourceforge/pywin32/pywin32-214.win32-py2.5.exe):

1- take a computer where pywin32 is not installed 2- open a cmd prompt and type "wscript //h:wscript" => you get a prompt telling you that the default script host has been changed 3- install http://surfnet.dl.sourceforge.net/sourceforge/pywin32/pywin32-214.win32-py2.5.exe 4- open a new cmd prompt and type "wscript //h:wscript" => you get "can't change the default script host"

This problem might seem minor but in my company we use this "wscript //h:wscript" command to silently install softwares on client computers. And, when this problem occurs, our silent installation fails.

I will gladly help but I don't have visual studio.

Best regards,

Cyrille

Reported by: cyrillebollu

Original Ticket: pywin32/bugs/529

ghost commented 13 years ago

I can't see how python could manage to do this. Some googling shows other people are having a similar issue without Python being installed - I wonder if the installation of *any* WSH-compatible scripting language is causing the problem?

> I will gladly help but I don't have visual studio.

You don't need visual studio - running wscript.exe like that shouldn't be loading Python at all (and certainly can't once it is uninstalled but the problem remains). I expect something we write to the registry isn't being cleaned up or something...

Original comment by: mhammond

ghost commented 13 years ago

Try rename or delete HKEY_CLASSES_ROOT\pysFile

Original comment by: cjgohlke

ghost commented 13 years ago

In my (limited) testing, I unregistered the AXScript engine (python ...\axscript.py --unregister), which deletes that key and a number of others, and the problem remains. I can't verify it ever did work for me though...

Original comment by: mhammond

ghost commented 13 years ago

Seems that [HKEY_CLASSES_ROOT\pysFile\Shell\Open] and [HKEY_CLASSES_ROOT\pysFile\Shell\Open2] keys need to be set in the pywin32\com\win32comext\axscript\client\pyscript.py DllRegisterServer() function. The following registry file works for me on Windows 7:

REGEDIT4

[HKEY_CLASSES_ROOT\pysFile] @="Python Script File"

[HKEY_CLASSES_ROOT\pysFile\ScriptEngine] @="Python"

[HKEY_CLASSES_ROOT\pysFile\ShellEx]

[HKEY_CLASSES_ROOT\pysFile\ShellEx\DropHandler] @="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_CLASSES_ROOT\pysFile\ShellEx\PropertySheetHandlers]

[HKEY_CLASSES_ROOT\pysFile\ShellEx\PropertySheetHandlers\WSHProps] @="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

[HKEY_CLASSES_ROOT\pysFile\Shell\Open]

[HKEY_CLASSES_ROOT\pysFile\Shell\Open\Command] @=hex(2):22,25,53,79,73,74,65,6d,52,6f,6f,74,25,5c,53,79,73,74,65,6d,33,32,5c,\ 57,53,63,72,69,70,74,2e,65,78,65,22,20,22,25,31,22,20,25,2a,00

[HKEY_CLASSES_ROOT\pysFile\Shell\Open2] @=hex(2):4f,70,65,6e,20,26,77,69,74,68,20,43,6f,6d,6d,61,6e,64,20,50,72,6f,6d,\ 70,74,00 "MUIVerb"=hex(2):40,25,53,79,73,74,65,6d,52,6f,6f,74,25,5c,53,79,73,74,65,6d,\ 33,32,5c,77,73,68,65,78,74,2e,64,6c,6c,2c,2d,34,35,31,31,00

[HKEY_CLASSES_ROOT\pysFile\Shell\Open2\Command] @=hex(2):22,25,53,79,73,74,65,6d,52,6f,6f,74,25,5c,53,79,73,74,65,6d,33,32,5c,\ 43,53,63,72,69,70,74,2e,65,78,65,22,20,22,25,31,22,20,25,2a,00

Original comment by: cjgohlke

ghost commented 13 years ago

Just to be sure: "wscript //h:wscript" must be run as administrator to succeed.

Original comment by: cjgohlke

ghost commented 13 years ago

>Just to be sure: "wscript //h:wscript" must be run as administrator to succeed. yes sure. I run it as local administrator

Now, I've removed pywin32-214.win32-py25 from my computer and I can't manage to re-install it.

I'll now reboot my computer to see if my python 2.6 & co. installation worked. If yes, I'll try your regedit trick.

BR,

Cyrille

Original comment by: cyrillebollu

ghost commented 13 years ago

Hi,

Great!

The registry changes did the trick.

Many thanks!

Cyrille

PS: I let you close the bug

========================

What I did: -------------

Installed python-2.6 Installed http://downloads.sourceforge.net/project/pywin32/pywin32/Build%20214/pywin32-214.win32-py2.6.exe wscript //h:wscript => doesn't work (usual error) regedit wscript //h:wscript => works

Note: ------

In my case I only add to create the [HKEY_CLASSES_ROOT\pysFile\Shell] hive; The rest of [HKEY_CLASSES_ROOT\pysFile] was correct.

Original comment by: cyrillebollu

ghost commented 13 years ago

I still can't find a solution to this. FWIW, the note below about changing the registry is simply a workaround to the problem - it manually sets wscript as the default for .pys files but does not allow for the //h command to succeed in the future.

Original comment by: mhammond

ghost commented 13 years ago

That's strange. wscript //h: and cscript //h: commands do succeed for me after manually merging the registry file (Windows 7 Pro 64 bit). Maybe another registry key is incomplete on your system?

Original comment by: cjgohlke

guzhifeng commented 6 years ago

Is there any fix plan for this bug?