[python]Bug incompréhensible pour moi

Fermé
Stéphane - 12 sept. 2007 à 16:13
 Stéphane - 12 sept. 2007 à 16:33
Bonjour à tous,

je viens vers vous car j'ai un bug dans un programme python déstiné à optimiser la base de registre windows sans comprendre ce qui cloche.

Voici le code de depart :

from Tkinter import *
import _winreg

def dll():
	"Vide les DLL du cache à la fermeture Windows"
	key = 

_winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer

')
	_winreg.SetValueEx(key, 'AlwaysUnloadDLL',1, _winreg.REG_DWORD,1)
	_winreg.CloseKey(key)

def dll0():
	"Replace la valeur normal de la base de registre"
	key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 

'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer')
	_winreg.SetValueEx(key, 'AlwaysUnloadDLL',0, _winreg.REG_DWORD,0)
	_winreg.CloseKey(key)

def doc():
	"Vide le menu document à la fermeture de Windows"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 

'SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer')
	_winreg.SetValueEx(key, 'ClearRecentDocsOnExit',1, _winreg.REG_DWORD,1)
	_winreg.CloseKey(key)

def doc0():
	"Replace la valeur normal dansle registre"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 

'SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer')
	_winreg.SetValueEx(key, 'ClearRecentDocsOnExit',0, _winreg.REG_DWORD,0)
	_winreg.CloseKey(key)

def demarrer():
	"Accelerer le menu demarrer"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Control Panel\Desktop')
	_winreg.SetValueEx(key, 'MenuShowDelay',0, _winreg.REG_SZ,'0')
	_winreg.CloseKey(key)

def demarrer0():
	"Replace la valeur normal dansle registre"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Control Panel\Desktop')
	_winreg.SetValueEx(key,'MenuShowDelay',0, _winreg.REG_SZ,'400')
	_winreg.CloseKey(key)

def autoendtasks():
	"Fermeture forcée des programmes à la fermeture de windows"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Control Panel\Desktop')
	_winreg.SetValueEx(key,'AutoEndTasks',1, _winreg.REG_SZ,'1')
	_winreg.CloseKey(key)

def autoendtasks0():
	"Replace la valeur normal dansle registre"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Control Panel\Desktop')
	_winreg.SetValueEx(key,'AutoEndTasks',0, _winreg.REG_SZ,'0')
	_winreg.CloseKey(key)

def waittokill():
	"Optimise le temps de blocage de programme"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Control Panel\Desktop')
	_winreg.SetValueEx(key,'WaitToKillAppTimeout',1, _winreg.REG_SZ,'4000')
	_winreg.CloseKey(key)

def waittokill0():
	"Replace la valeur par defaut"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Control Panel\Desktop')
	_winreg.SetValueEx(key,'WaitToKillAppTimeout',1, _winreg.REG_SZ,'20000')
	_winreg.CloseKey(key)
	
def completion():
	"Active la completion dos"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Software\Microsoft\Command 

Processor')
	_winreg.SetValueEx(key,'CompletionChar',1, _winreg.REG_DWORD,9)
	_winreg.CloseKey(key)

def completion0():
	"Replace la valeur par defaut"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Software\Microsoft\Command 

Processor')
	_winreg.SetValueEx(key,'CompletionChar',1, _winreg.REG_DWORD,0)
	_winreg.CloseKey(key)

def bloc():
	"Active le retour à la ligne dansle bloc note"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Software\Microsoft\Notepad')
	_winreg.SetValueEx(key,'fwrap',1, _winreg.REG_DWORD,1)
	_winreg.CloseKey(key)

def bloc0():
	"Replace les valeurs d'origines"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Software\Microsoft\Notepad')
	_winreg.SetValueEx(key,'fwrap',1, _winreg.REG_DWORD,0)
	_winreg.CloseKey(key)

def verrou():
	"Active le verrouillage numérique au demarrage"
	key = _winreg.CreateKey(_winreg.HKEY_USERS, '.DEFAULT\Control Panel\Keyboard')
	_winreg.SetValueEx(key,'InitialKeyboardIndicators',1, _winreg.REG_SZ,'2')
	_winreg.CloseKey(key)

def verrou0():
	"Replace les valeurs d'origine"
	key = _winreg.CreateKey(_winreg.HKEY_USERS, '.DEFAULT\Control Panel\Keyboard')
	_winreg.SetValueEx(key,'InitialKeyboardIndicators',1, _winreg.REG_SZ,'0')
	_winreg.CloseKey(key)

def memoire():
	"Optimise la mémoire"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Control Panel\Desktop')
	_winreg.SetValueEx(key,'HungAppTimeout',0, _winreg.REG_SZ,'2000')
	_winreg.CloseKey(key)

def memoire0():
	"Replace les valeurs d'origine"
	key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 'Control Panel\Desktop')
	_winreg.SetValueEx(key,'HungAppTimeout',1, _winreg.REG_SZ,'4000')
	_winreg.CloseKey(key)

def optimemoire():
	"Optimise l'utilisation de la mémoire"
	key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 

'SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management')
	_winreg.SetValueEx(key,'DisablePagingExecutive',1, _winreg.REG_DWORD,1)
	_winreg.CloseKey(key)

def optimemoire0():
	"Retablit les valeurs par defaut"
	key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 

'SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management')
	_winreg.SetValueEx(key,'DisablePagingExecutive',1, _winreg.REG_DWORD,0)
	_winreg.CloseKey(key)

def cd():
	"Augmenter la vitesse de gravure"
	 key = 

_winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\FileSystem\CDFS')
	_winreg.SetValueEx(key,'CacheSize',1, _winreg.REG_BINARY,'ff ff 00 00')
	_winreg.CloseKey(key)
	key = 

_winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\FileSystem\CDFS')
	_winreg.SetValueEx(key,'Prefetch',1, _winreg.REG_DWORD,4000)
	_winreg.CloseKey(key)
	key = 

_winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\FileSystem\CDFS')
	_winreg.SetValueEx(key,'PrefetchTail',1, _winreg.REG_DWORD,4000)
	_winreg.CloseKey(key)

#Programme principal

fen1=Tk()
fen1.title('Optimisation Windows XP')
ent1=Label(fen1,text='Videz les dll du cache a l\'arrêt')
ent1.grid(row=0,column=0)
bou1=Button(fen1,text='Active',command=(lambda:dll()))
bou1.grid(row=0,column=1)
bou2=Button(fen1,text='Desactive',command=(lambda:dll0()))
bou2.grid(row=0,column=2)
ent2=Label(fen1,text='Videz la liste des documents récents a l\'arrêt')
ent2.grid(row=1,column=0)
bou3=Button(fen1,text='Active',command=(lambda:doc()))
bou3.grid(row=1,column=1)
bou4=Button(fen1,text='Desactive',command=(lambda:doc0()))
bou4.grid(row=1,column=2)
ent3=Label(fen1,text='Accelerer le menu Demarrer')
ent3.grid(row=2,column=0)
bou5=Button(fen1,text='Active',command=(lambda:demarrer()))
bou5.grid(row=2,column=1)
bou6=Button(fen1,text='Desactive',command=(lambda:demarrer0()))
bou6.grid(row=2,column=2)
ent4=Label(fen1,text='Force la fermeture des programmes a l\'arrêt')
ent4.grid(row=3,column=0)
bou7=Button(fen1,text='Active',command=(lambda:autoendtasks()))
bou7.grid(row=3,column=1)
bou8=Button(fen1,text='Desactive',command=(lambda:autoendtasks0()))
bou8.grid(row=3,column=2)
ent5=Label(fen1,text='Optimise la fermeture des programmes bloqués')
ent5.grid(row=4,column=0)
bou9=Button(fen1,text='Active',command=(lambda:waittokill()))
bou9.grid(row=4,column=1)
bou10=Button(fen1,text='Desactive', command=(lambda:waittokill0()))
bou10.grid(row=4,column=2)
ent6=Label(fen1,text='Active la complétion dos')
ent6.grid(row=5,column=0)
bou11=Button(fen1,text='Active',command=(lambda:completion()))
bou11.grid(row=5,column=1)
bou12=Button(fen1,text='Desactive',command=(lambda:completion0()))
bou12.grid(row=5,column=2)
ent7=Label(fen1,text='Retour a la ligne dans le bloc note')
ent7.grid(row=6,column=0)
bou13=Button(fen1,text='Active',command=(lambda:bloc()))
bou13.grid(row=6,column=1)
bou14=Button(fen1,text='Desactive',command=(lambda:bloc0()))
bou14.grid(row=6,column=2)
ent8=Label(fen1,text='Active le clavier numérique au demarrage')
ent8.grid(row=7,column=0)
bou15=Button(fen1,text='Active',command=(lambda:verrou()))
bou15.grid(row=7,column=1)
bou15=Button(fen1,text='Desactive',command=(lambda:verrou0()))
bou15.grid(row=7,column=2)
ent9=Label(fen1,text='Libère la mémoire non utilisée')
ent9.grid(row=8,column=0)
bou16=Button(fen1,text='Active',command=(lambda:memoire()))
bou16.grid(row=8,column=1)
bou17=Button(fen1,text='Desactive',command=(lambda:memoire0()))
bou17.grid(row=8,column=2)
ent10=Label(fen1,text='Optimise la mémoire(réservé + de 128 mo)')
ent10.grid(row=9,column=0)
bou18=Button(fen1,text='Active',command=(lambda:optimemoire()))
bou18.grid(row=9,column=1)
bou19=Button(fen1,text='Desactive',command=(lambda:optimemoire0()))
bou19.grid(row=9,column=2)
ent11=Label(fen1,text='Optimise acces lecteur CD-DVD')
ent11.grid(row=10,column=0)
bou20=Button(fen1,text='Active',command=(lambda:cd()))
bou20.grid(row=10,column=1) 
fen1.mainloop()


Celui ci ne veut pas demarrer sauf lorsque j'enlève le def suivant :

def cd():
	"Augmenter la vitesse de gravure"
	 key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 

'SYSTEM\CurrentControlSet\Control\FileSystem\CDFS')
	_winreg.SetValueEx(key,'CacheSize',1, _winreg.REG_BINARY,'ff ff 00 00')
	_winreg.CloseKey(key)
	key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 

'SYSTEM\CurrentControlSet\Control\FileSystem\CDFS')
	_winreg.SetValueEx(key,'Prefetch',1, _winreg.REG_DWORD,4000)
	_winreg.CloseKey(key)
	key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, 

'SYSTEM\CurrentControlSet\Control\FileSystem\CDFS')
	_winreg.SetValueEx(key,'PrefetchTail',1, _winreg.REG_DWORD,4000)
	_winreg.CloseKey(key)


Mais bizarrement si j'utilise le GUI python, il ne renvoie aucun code d'erreur.

Donc je suis paumé et je vous demande humblement de l'aide

Merci par avance

lonewolf

1 réponse

Et bien merci a tous,

après 1 bonneheure de recherche, j'ai résolu le problème.

Le terme "key" etait décalé d'un caractère, ce qui suffisait a faire bugger mon appli.

Ne cherchez plus.

Merci quand meme

Amitiés

Stéphane
0