本文整理汇总了Python中_winreg.SetValueEx方法的典型用法代码示例。如果您正苦于以下问题:Python _winreg.SetValueEx方法的具体用法?Python _winreg.SetValueEx怎么用?Python _winreg.SetValueEx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_winreg
的用法示例。
在下文中一共展示了_winreg.SetValueEx方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: modify
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def modify():
pythonpath = os.path.dirname(os.path.normpath(sys.executable))
scripts = os.path.join(pythonpath, "Scripts")
appdata = os.environ["APPDATA"]
if hasattr(site, "USER_SITE"):
userpath = site.USER_SITE.replace(appdata, "%APPDATA%")
userscripts = os.path.join(userpath, "Scripts")
else:
userscripts = None
with _winreg.CreateKey(HKCU, ENV) as key:
try:
envpath = _winreg.QueryValueEx(key, PATH)[0]
except WindowsError:
envpath = DEFAULT
paths = [envpath]
for path in (pythonpath, scripts, userscripts):
if path and path not in envpath and os.path.isdir(path):
paths.append(path)
envpath = os.pathsep.join(paths)
_winreg.SetValueEx(key, PATH, 0, _winreg.REG_EXPAND_SZ, envpath)
return paths, envpath
示例2: set_windows_path_var
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def set_windows_path_var(self, value):
import ctypes
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, value)
# Tell other processes to update their environment
HWND_BROADCAST = 0xFFFF
WM_SETTINGCHANGE = 0x1A
SMTO_ABORTIFHUNG = 0x0002
result = ctypes.c_long()
SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
SendMessageTimeoutW(
HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
u"Environment",
SMTO_ABORTIFHUNG,
5000,
ctypes.byref(result),
)
示例3: DllRegisterServer
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def DllRegisterServer():
import _winreg
key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \
"Explorer\\Desktop\\Namespace\\" + \
ShellFolderRoot._reg_clsid_)
_winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellFolderRoot._reg_desc_)
# And special shell keys under our CLSID
key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
"CLSID\\" + ShellFolderRoot._reg_clsid_ + "\\ShellFolder")
# 'Attributes' is an int stored as a binary! use struct
attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \
shellcon.SFGAO_BROWSABLE
import struct
s = struct.pack("i", attr)
_winreg.SetValueEx(key, "Attributes", 0, _winreg.REG_BINARY, s)
print ShellFolderRoot._reg_desc_, "registration complete."
示例4: register
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def register(classobj):
import _winreg
subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_
try:
hKey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID )
subKey = _winreg.SetValueEx( hKey, "ButtonText", 0, _winreg.REG_SZ, classobj._button_text_ )
_winreg.SetValueEx( hKey, "ClsidExtension", 0, _winreg.REG_SZ, classobj._reg_clsid_ ) # reg value for calling COM object
_winreg.SetValueEx( hKey, "CLSID", 0, _winreg.REG_SZ, "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}" ) # CLSID for button that sends command to COM object
_winreg.SetValueEx( hKey, "Default Visible", 0, _winreg.REG_SZ, "Yes" )
_winreg.SetValueEx( hKey, "ToolTip", 0, _winreg.REG_SZ, classobj._tool_tip_ )
_winreg.SetValueEx( hKey, "Icon", 0, _winreg.REG_SZ, classobj._icon_)
_winreg.SetValueEx( hKey, "HotIcon", 0, _winreg.REG_SZ, classobj._hot_icon_)
except WindowsError:
print "Couldn't set standard toolbar reg keys."
else:
print "Set standard toolbar reg keys."
示例5: save
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def save(self):
if USE_WINDOWS:
import _winreg
try:
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, self.keyname,
sam=_winreg.KEY_SET_VALUE | _winreg.KEY_WRITE)
except:
key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, self.keyname)
try:
for k, v in self.values.iteritems():
_winreg.SetValueEx(key, str(k), 0, _winreg.REG_SZ, str(v))
finally:
key.Close()
else:
d = os.path.dirname(self.filename)
if not os.path.isdir(d):
os.makedirs(d)
f = open(self.filename, 'w')
try:
data = '\n'.join(["%s=%s" % (k,v)
for k,v in self.values.iteritems()])
f.write(data)
finally:
f.close()
示例6: listRegKeyValues
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def listRegKeyValues(registry, key, architecture=None):
""" Returns a list of child keys and their values as tuples.
Each tuple contains 3 items.
- A string that identifies the value name
- An object that holds the value data, and whose type depends on the underlying registry type
- An integer that identifies the type of the value data (see table in docs for _winreg.SetValueEx)
Args:
registry (str): The registry to look in. 'HKEY_LOCAL_MACHINE' for example
key (str): The key to open. r'Software\Autodesk\Softimage\InstallPaths' for example
architecture (int | None): 32 or 64 bit. If None use system default. Defaults to None
Returns:
List of tuples
"""
import _winreg
regKey = getRegKey(registry, key, architecture=architecture)
ret = []
if regKey:
subKeys, valueCount, modified = _winreg.QueryInfoKey(regKey)
for index in range(valueCount):
ret.append(_winreg.EnumValue(regKey, index))
return ret
示例7: registry_key
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def registry_key(key, subkey, value):
"""
Create a new Windows Registry Key in HKEY_CURRENT_USER
`Required`
:param str key: primary registry key name
:param str subkey: registry key sub-key name
:param str value: registry key sub-key value
Returns True if successful, otherwise False
"""
try:
import _winreg
reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key, 0, _winreg.KEY_WRITE)
_winreg.SetValueEx(reg_key, subkey, 0, _winreg.REG_SZ, value)
_winreg.CloseKey(reg_key)
return True
except Exception as e:
log(e)
return False
示例8: enforce_shortcut
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def enforce_shortcut(config, log_func):
if os.name != 'nt':
return
path = win32api.GetModuleFileName(0)
if 'python' in path.lower():
# oops, running the .py too lazy to make that work
path = r"C:\Program Files\BitTorrent\bittorrent.exe"
root_key = _winreg.HKEY_CURRENT_USER
subkey = r'Software\Microsoft\Windows\CurrentVersion\run'
key = _winreg.CreateKey(root_key, subkey)
if config['launch_on_startup']:
_winreg.SetValueEx(key, app_name, 0, _winreg.REG_SZ,
'"%s" --force_start_minimized' % path)
else:
try:
_winreg.DeleteValue(key, app_name)
except WindowsError, e:
# value doesn't exist
pass
示例9: write_block
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def write_block(self, bucket_id, value_id, data=""):
"""Described in parent class"""
try:
value_name = self._get_value_name(
bucket_id, value_id)
except BucketValueMissingException:
logger.debug(
"value with id does not exist in specified bucket." +
" generating a new value name for bucket id %s" % bucket_id)
value_name = self._generate_value_name(bucket_id)
logger.debug("generated a new value name in bucket id %s: %s" % (
bucket_id, value_name))
with self._get_bucket_key(bucket_id, _winreg.KEY_WRITE) as key:
_winreg.SetValueEx(key, value_name, 0,
_winreg.REG_BINARY, data)
return RegistryStorageProvider.value_name_to_value_id(value_name)
示例10: Install
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def Install():
AddOrRemoveHIDKeys(True)
osExtension = "x86"
if Is64BitOS():
osExtension = "x64"
pluginDir = dirname(__file__.decode(sys.getfilesystemencoding()))
tmpExe = join(pluginDir, "AlternateMceIrService_%s.exe"%osExtension)
myExe = join(pluginDir, "AlternateMceIrService.exe")
try:
os.remove(myExe)
except:
pass
shutil.copyfile(tmpExe,myExe)
key = reg.CreateKey(reg.HKEY_LOCAL_MACHINE, ServiceKey+"\\AlternateMceIrService")
reg.SetValueEx(key, "EventMessageFile", 0, reg.REG_SZ, myExe)
reg.SetValueEx(key, "TypesSupported", 0, reg.REG_DWORD, 7)
service = Service(u"AlternateMceIrService")
service.Install(myExe)
service.Start()
print "Service successfully installed"
示例11: set_envvar_in_registry
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def set_envvar_in_registry(envvar, value):
try:
import winreg
except ImportError:
import _winreg as winreg
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
with winreg.OpenKey(reg, KEY, 0, winreg.KEY_ALL_ACCESS) as regkey:
winreg.SetValueEx(regkey, envvar, 0, winreg.REG_EXPAND_SZ, value)
示例12: __setitem__
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def __setitem__(self,name,value):
"""Item assignment sets key values."""
self.sam |= KEY_SET_VALUE
if not isinstance(value,Value):
value = Value(value,name)
_winreg.SetValueEx(self.hkey,name,0,value.type,value.data)
示例13: DllRegisterServer
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def DllRegisterServer():
import _winreg
key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
"directory\\shellex\\CopyHookHandlers\\" +
ShellExtension._reg_desc_)
_winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_)
key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
"*\\shellex\\CopyHookHandlers\\" +
ShellExtension._reg_desc_)
_winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_)
print ShellExtension._reg_desc_, "registration complete."
示例14: DllRegisterServer
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def DllRegisterServer():
import _winreg
# Special ColumnProvider key
key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT,
"Folder\\ShellEx\\ColumnHandlers\\" + \
str(ColumnProvider._reg_clsid_ ))
_winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ColumnProvider._reg_desc_)
print ColumnProvider._reg_desc_, "registration complete."
示例15: DllRegisterServer
# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import SetValueEx [as 别名]
def DllRegisterServer():
# Also need to register specially in:
# HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches
# See link at top of file.
import _winreg
kn = r"Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%s" \
% (EmptyVolumeCache._reg_desc_,)
key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, kn)
_winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, EmptyVolumeCache._reg_clsid_)