P
Pat Blair
Sorry to anyone who read this post, but in case it's useful to anyone:
Further experiments reveal that while a tuple comes back if you read a
multi-line string, you set the value using a list (not a tuple). That's
sensible and I don't know why this didn't occur to me before I posted.
Thanks
-----Original Message-----
From: Pat Blair [mailto[email protected]]
Sent: Friday, February 06, 2004 10:10 AM
To: (e-mail address removed)
Subject: Writing to REG_MULTI_SZ windows registry keys
Hello. I'm looking for any information I can get about writing values to
keys in the Windows registry when the value type is a multi-string (ie.
REG_MULTI_SZ). When I get the value of a multi-string value using winreg
functions, I get a tuple with tuple[0] being a list, and tuple[1] a number.
If I try to write such a tuple back into a multi-string value, I get the
following exception:
ValueError: Could not convert the data to the specified type.
I haven't been able to find any documents, postings, etc. that deal with
this specifically. My test code is listed below. If any tips can be
offered, they will be much appreciated!
from _winreg import *
import sys
#get the current value of the PendingFileRenameOperations key
def getCurrentValue():
aReg = ConnectRegistry(
None,
HKEY_LOCAL_MACHINE)
aKey = OpenKey(aReg, r"SYSTEM\CurrentControlSet\Control\Session
Manager")
value = QueryValueEx(aKey, "PendingFileRenameOperations")
CloseKey(aKey)
return value
#set the value of a test REG_MULTI_SZ key (this key already exists")
def setNewValue(value):
aReg = ConnectRegistry(
None,
HKEY_LOCAL_MACHINE)
aKey = OpenKey(aReg, r"SOFTWARE\PRN_TEST", 0, KEY_WRITE)
SetValueEx(
aKey,
"PendingFileRenameOperations",
0,
REG_MULTI_SZ,
value
)
CloseKey(aKey)
#the name of some file I want to add to the list
renamedTarget = r"C:\some_file_i_want_to_delete.txt"
tuple = getCurrentValue()
print tuple
list = tuple[0]
list.append(unicode(renamedTarget))
newtuple = (list, tuple[1])
setNewValue(tuple)
Further experiments reveal that while a tuple comes back if you read a
multi-line string, you set the value using a list (not a tuple). That's
sensible and I don't know why this didn't occur to me before I posted.
Thanks
-----Original Message-----
From: Pat Blair [mailto[email protected]]
Sent: Friday, February 06, 2004 10:10 AM
To: (e-mail address removed)
Subject: Writing to REG_MULTI_SZ windows registry keys
Hello. I'm looking for any information I can get about writing values to
keys in the Windows registry when the value type is a multi-string (ie.
REG_MULTI_SZ). When I get the value of a multi-string value using winreg
functions, I get a tuple with tuple[0] being a list, and tuple[1] a number.
If I try to write such a tuple back into a multi-string value, I get the
following exception:
ValueError: Could not convert the data to the specified type.
I haven't been able to find any documents, postings, etc. that deal with
this specifically. My test code is listed below. If any tips can be
offered, they will be much appreciated!
from _winreg import *
import sys
#get the current value of the PendingFileRenameOperations key
def getCurrentValue():
aReg = ConnectRegistry(
None,
HKEY_LOCAL_MACHINE)
aKey = OpenKey(aReg, r"SYSTEM\CurrentControlSet\Control\Session
Manager")
value = QueryValueEx(aKey, "PendingFileRenameOperations")
CloseKey(aKey)
return value
#set the value of a test REG_MULTI_SZ key (this key already exists")
def setNewValue(value):
aReg = ConnectRegistry(
None,
HKEY_LOCAL_MACHINE)
aKey = OpenKey(aReg, r"SOFTWARE\PRN_TEST", 0, KEY_WRITE)
SetValueEx(
aKey,
"PendingFileRenameOperations",
0,
REG_MULTI_SZ,
value
)
CloseKey(aKey)
#the name of some file I want to add to the list
renamedTarget = r"C:\some_file_i_want_to_delete.txt"
tuple = getCurrentValue()
print tuple
list = tuple[0]
list.append(unicode(renamedTarget))
newtuple = (list, tuple[1])
setNewValue(tuple)