i hv written 2 programs. "process.py" and "Reg_write_read.py". I have created the exe of both,"Reg_write_read.py" program writes a value in registry through which the process.exe(which is located in C:/) executes on computer restart. But when i Restart my computer. the "process.exe.log" error log generates that says :

"Traceback (most recent call last):
File "<install zipextimporter>", line 1, in <module>
ImportError: No module named zipextimporter
Traceback (most recent call last):
File "process.py", line 1, in <module>
ImportError: No module named wmi"

. But when i write a value in registry which executes other exe file (which is not written through python) then its working fine.If i run process.exe mannually by double clicking on the process.exe then its working fine but not at the boot time
I dont understand what is wrong..Kindly Suggest..Thanks in advance.

THE CODE IS BELOW
---------------------
#Reg_write_read.py
---------------------------

from _winreg import *

print r"*** Reading from SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***"
aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)

aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
for i in range(1024):
try:
n,v,t = EnumValue(aKey,i)
print i, n, v, t
except EnvironmentError:
print "You have",i," tasks starting at logon..."
break
CloseKey(aKey)

print r"*** Writing to SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***"
aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE)
try:
SetValueEx(aKey,"MyNewKey",0, REG_SZ, r"c:\process.exe")
except EnvironmentError:
print "Encountered problems writing into the Registry..."
CloseKey(aKey)

CloseKey(aReg)

-------------------------------
#process.py
--------------------------
#List all Running Process
import wmi
c = wmi.WMI ()

for process in c.Win32_Process ():
print process.ProcessId, process.Name
pid=str(process.ProcessId)
pn=process.Name
f=open("proc.txt", "a")
f.write("\nProcess ID:")
f.write(pid)
f.write("\nProcess Name:")
f.write(pn)
f.write("\n------------")
f.close()


Thanks :) and please Help :(

Okay, so an import error eh.... well, if it is working once windows has fully loaded then that makes me think that something is not being started quickly.

import wmi

I am going completely off guesswork here as i have never used wmi. But if what you said is true and that it works once windows is fully loaded then that would lead me to think that wmi is not being initialised properly until windows is fully loaded..

So perhaps you could put this just before that to check if i am correct:

import time
time.sleep(20)

So that would sleep the code 20 seconds before importing wmi, just in case. Because i know that wmi is a way for python to communicate with a windows API not a native python one therefore there may be problems there.

Oh well, nothing to lose, might as well have a go and tell me what happens :)

Cheers
:)

ps. if your computer is really slow it may need more than 20 seconds of sleep time.

Okay, so an import error eh.... well, if it is working once windows has fully loaded then that makes me think that something is not being started quickly.

import wmi

I am going completely off guesswork here as i have never used wmi. But if what you said is true and that it works once windows is fully loaded then that would lead me to think that wmi is not being initialised properly until windows is fully loaded..

So perhaps you could put this just before that to check if i am correct:

import time
time.sleep(20)

So that would sleep the code 20 seconds before importing wmi, just in case. Because i know that wmi is a way for python to communicate with a windows API not a native python one therefore there may be problems there.

Oh well, nothing to lose, might as well have a go and tell me what happens :)

Cheers
:)

ps. if your computer is really slow it may need more than 20 seconds of sleep time.

I Tried the code
##########

import time
time.sleep(120)
import wmi
c = wmi.WMI ()

for process in c.Win32_Process ():
print process.ProcessId, process.Name
pid=str(process.ProcessId)
pn=process.Name
f=open("proc.txt", "a")
f.write("\nProcess ID:")
f.write(pid)
f.write("\nProcess Name:")
f.write(pn)
f.write("\n------------")
f.close()
##############

But :'( getting the error again .The error is::
"
Traceback (most recent call last):
File "<install zipextimporter>", line 1, in <module>
ImportError: No module named zipextimporter

"

What shud i do Paul :(

Have you tried running it from the startup folder?

And I don't know the guts of windows too well, but maybe it has something to do with not being logged on. Certain process and programs don't start until logon, the program could be dependent of those processes or programs.

Also try longer time.sleep values maybe?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.