views:

358

answers:

1

How can I associate an extension of a file to an program in Windows CE? It's so boring to run my Python programs using cmd. If I associate Python with my *.py files I'm going to run my program faster. Thanks!

A: 

Hello,

I was searching in the Python files under my Windows CE and i found a simple code to do this, and i tweaked it to be better:

#
#   Setup the registry to allow us to double click on python scripts
#

from _winreg import *

print "Setting up registry to allow\ndouble clicking of Python files to work"

#
#   Create the registry entries for ".py" and ".pyc" extensions
#

for Name in (".py", ".pyc"):
    Key = CreateKey(HKEY_CLASSES_ROOT, Name)
    SetValue(Key, None, REG_SZ, "Python.File")
    CloseKey(Key)

#
#   Create HKEY_CLASSES_ROOT\Python.File\Shell\Open\Command = "\Program Files\Python\Lib\Python.exe" "%1"
#

Key = CreateKey(HKEY_CLASSES_ROOT, "Python.File")
for Name in ("Shell","Open","Command"):
  New_Key= CreateKey(Key, Name)
  CloseKey(Key)
  Key = New_Key
SetValue(Key, None, REG_SZ, "\"\\Program Files\\Python\\Lib\\Python.exe\" \"%1\"")
CloseKey(Key)

import time
time.sleep(5)

This is the code, if you want you can use it to associate to other programs and other extensions.

Nathan Campos
how did you tweak it to make it "better"? it's just setting a registry key...
Cogsy
If you copy code verbatim from another source it is customary to give credit. This was copied from: http://mail.python.org/pipermail/pythonce/2006-January/001286.html
Andre Miller