一、前言
Python操作注冊(cè)表有兩種方法,一種是使用pywin32模塊,還有一種是使用winreg模塊,今天我們要講的是winreg模塊,winreg有一些我們需要知道的常識(shí),如下:
1.HKEY_ 常量
<pre spellcheck="false" lang="" cid="n330" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal; visibility: visible;">winreg.HKEY_CLASSES_ROOT
本注冊(cè)表鍵下的注冊(cè)表項(xiàng)定義了文件的類型(或類別)及相關(guān)屬性。Shell 和 COM 應(yīng)用程序?qū)⑹褂迷撟?cè)表鍵下保存的信息。
winreg.HKEY_CURRENT_USER
屬于該注冊(cè)表鍵的表項(xiàng)定義了當(dāng)前用戶的偏好。這些偏好值包括環(huán)境變量設(shè)置、程序組數(shù)據(jù)、顏色、打印機(jī)、網(wǎng)絡(luò)連接和應(yīng)用程序參數(shù)。
winreg.HKEY_LOCAL_MACHINE
屬于該注冊(cè)表鍵的表項(xiàng)定義了計(jì)算機(jī)的物理狀態(tài),包括總線類型、系統(tǒng)內(nèi)存和已安裝軟硬件等數(shù)據(jù)。
winreg.HKEY_USERS
屬于該注冊(cè)表鍵的表項(xiàng)定義了當(dāng)前計(jì)算機(jī)中新用戶的默認(rèn)配置和當(dāng)前用戶配置。
winreg.HKEY_PERFORMANCE_DATA
屬于該注冊(cè)表鍵的表項(xiàng)可用于讀取性能數(shù)據(jù)。這些數(shù)據(jù)其實(shí)并不存放于注冊(cè)表中;注冊(cè)表提供功能讓系統(tǒng)收集數(shù)據(jù)。
winreg.HKEY_CURRENT_CONFIG
包含有關(guān)本地計(jì)算機(jī)系統(tǒng)當(dāng)前硬件配置的信息。
winreg.HKEY_DYN_DATA
Windows 98 以上版本不使用該注冊(cè)表鍵。</pre>
2.訪問(wèn)權(quán)限
<pre spellcheck="false" lang="python" cid="n332" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.KEY_ALL_ACCESS
組合了 STANDARD_RIGHTS_REQUIRED 、KEY_QUERY_VALUE 、 KEY_SET_VALUE 、 KEY_CREATE_SUB_KEY 、 KEY_ENUMERATE_SUB_KEYS 、 KEY_NOTIFY 和 KEY_CREATE_LINK 訪問(wèn)權(quán)限。
winreg.KEY_WRITE
組合了 STANDARD_RIGHTS_WRITE 、 KEY_SET_VALUE 和 KEY_CREATE_SUB_KEY 訪問(wèn)權(quán)限。
winreg.KEY_READ
組合了 STANDARD_RIGHTS_READ 、 KEY_QUERY_VALUE 、 KEY_ENUMERATE_SUB_KEYS 和 KEY_NOTIFY 。
winreg.KEY_EXECUTE
等價(jià)于 KEY_READ。
winreg.KEY_QUERY_VALUE
查詢注冊(cè)表鍵值時(shí)需要用到。
winreg.KEY_SET_VALUE
創(chuàng)建、刪除或設(shè)置注冊(cè)表值時(shí)需要用到。
winreg.KEY_CREATE_SUB_KEY
創(chuàng)建注冊(cè)表鍵的子鍵時(shí)需要用到。
winreg.KEY_ENUMERATE_SUB_KEYS
枚舉注冊(cè)表鍵的子鍵時(shí)需要用到。
winreg.KEY_NOTIFY
為注冊(cè)表鍵或子鍵請(qǐng)求修改通知時(shí)需要用到。
winreg.KEY_CREATE_LINK
保留給系統(tǒng)使用。
winreg.KEY_WOW64_64KEY
表示一個(gè)應(yīng)用程序在 64 位 Windows 上應(yīng)當(dāng)在 64 位的注冊(cè)表視圖上進(jìn)行操作。 在 32 位 Windows 上,此常量會(huì)被忽略。
winreg.KEY_WOW64_32KEY
表示一個(gè)應(yīng)用程序在 64 位 Windows 上應(yīng)當(dāng)在 32 位的注冊(cè)表視圖上進(jìn)行操作。 在 32 位 Windows 上,此常量會(huì)被忽略。</pre>
3.64位的具體應(yīng)用
<pre spellcheck="false" lang="" cid="n334" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.KEY_WOW64_64KEY #在64位Windows應(yīng)用程序應(yīng)該運(yùn)行在64位注冊(cè)表視圖
winreg.KEY_WOW64_32KEY #在64位Windows應(yīng)用程序應(yīng)該運(yùn)行在32位注冊(cè)表視圖</pre>
4.注冊(cè)表值的類型
<pre spellcheck="false" lang="" cid="n336" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.REG_BINARY
任意格式的二進(jìn)制數(shù)據(jù)。
winreg.REG_DWORD
32 位數(shù)字。
winreg.REG_DWORD_LITTLE_ENDIAN
32 位低字節(jié)序格式的數(shù)字。相當(dāng)于 REG_DWORD。
winreg.REG_DWORD_BIG_ENDIAN
32 位高字節(jié)序格式的數(shù)字。
winreg.REG_EXPAND_SZ
包含環(huán)境變量(%PATH%)的字符串,以空字符結(jié)尾。
winreg.REG_LINK
Unicode 符號(hào)鏈接。
winreg.REG_MULTI_SZ
一串以空字符結(jié)尾的字符串,最后以兩個(gè)空字符結(jié)尾。Python 會(huì)自動(dòng)處理這種結(jié)尾形式。
winreg.REG_NONE
未定義的類型。
winreg.REG_QWORD
64 位數(shù)字。
winreg.REG_QWORD_LITTLE_ENDIAN
64 位低字節(jié)序格式的數(shù)字。相當(dāng)于 REG_QWORD。
winreg.REG_RESOURCE_LIST
設(shè)備驅(qū)動(dòng)程序資源列表。
winreg.REG_FULL_RESOURCE_DESCRIPTOR
硬件設(shè)置。
winreg.REG_RESOURCE_REQUIREMENTS_LIST
硬件資源列表。
winreg.REG_SZ
空字符結(jié)尾的字符串。</pre>
(摘自Python文檔)
5.連接遠(yuǎn)程計(jì)算機(jī)注冊(cè)表
<pre spellcheck="false" lang="" cid="n339" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">reg=winreg.ConnectRegistry('\遠(yuǎn)程計(jì)算機(jī)名',主鍵)#返回主鍵句柄 </pre>
在訪問(wèn)之前得先判斷是否有管理員權(quán)限,如下:
<pre spellcheck="false" lang="" cid="n341" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">import ctypes
import sys
def gly():
ab=ctypes.windll.shell32.IsUserAnAdmin()
return ab
if gly()==1: #如果有管理員權(quán)限便可打開(kāi)遠(yuǎn)程注冊(cè)表
winreg.ConnectRegistry('\遠(yuǎn)程計(jì)算機(jī)名',主鍵)
else:
if sys.version_info[0]==3: #python3
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, file, None, 1)
else: #python2
ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(file), None, 1) </pre>
連接之后不想用了,想要關(guān)閉,也很簡(jiǎn)單,有兩種方法,如下:
<pre spellcheck="false" lang="" cid="n343" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.CloseKey(reg)
reg.Close()</pre>
句柄的值也可以打印出來(lái)。
6.創(chuàng)建注冊(cè)表項(xiàng)
有兩個(gè)函數(shù)都可以實(shí)現(xiàn),如下:
<pre spellcheck="false" lang="" cid="n347" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.CreateKey(key, sub_key)
winreg.CreateKeyEx(key, sub_key, reserved=0, access=KEY_WRITE)
創(chuàng)建或打開(kāi)特定的鍵,返回一個(gè) handle 對(duì)象。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
sub_key 是用于命名該方法所打開(kāi)或創(chuàng)建的鍵的字符串。
reserved 是一個(gè)保留的整數(shù),必須是零。默認(rèn)值為零。
access 為一個(gè)整數(shù),用于給鍵的預(yù)期安全訪問(wèn)指定訪問(wèn)掩碼。默認(rèn)值為 KEY_WRITE。參閱 Access Rights 了解其它允許值。
如果 key 是預(yù)定義鍵之一,sub_key 可能會(huì)是 None。該情況下,返回的句柄就是傳入函數(shù)的句柄。
如果鍵已經(jīng)存在,則該函數(shù)打開(kāi)已經(jīng)存在的該鍵。
返回值是所開(kāi)打鍵的句柄。如果函數(shù)失敗,則引發(fā)一個(gè) OSError 異常。
</pre>
(摘自Python文檔)
因?yàn)閯?chuàng)建注冊(cè)表的第一個(gè)參數(shù)為打開(kāi)的鍵的句柄,因此我們需要先打開(kāi)一個(gè)鍵,這里我們用到如下函數(shù):
<pre spellcheck="false" lang="" cid="n350" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.OpenKey(key, sub_key, reserved=0, access=KEY_READ)
winreg.OpenKeyEx(key, sub_key, reserved=0, access=KEY_READ)
打開(kāi)指定的注冊(cè)表鍵,返回 handle對(duì)象。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
sub_key 是個(gè)字符串,標(biāo)識(shí)了需要打開(kāi)的子鍵。
reserved 是個(gè)保留整數(shù),必須為零。默認(rèn)值為零。
access 是個(gè)指定訪問(wèn)掩碼的整數(shù),掩碼描述了注冊(cè)表鍵所需的安全權(quán)限。默認(rèn)值為 KEY_READ。其他合法值參見(jiàn) 訪問(wèn)權(quán)限。
返回結(jié)果為一個(gè)新句柄,指向指定的注冊(cè)表鍵。
如果調(diào)用失敗,則會(huì)觸發(fā) OSError 。
觸發(fā) 審計(jì)事件 winreg.OpenKey,附帶參數(shù)為 key 、sub_key 、 access。
引發(fā)一個(gè) 審計(jì)事件 winreg.OpenKey/result,附帶參數(shù) key。</pre>
(摘自Python文檔)
下面我們來(lái)創(chuàng)建一個(gè)注冊(cè)表的子項(xiàng),如下:
<pre spellcheck="false" lang="Python" cid="n353" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">#打開(kāi)的鍵的句柄
key= reg.OpenKey(reg.HKEY_CURRENT_USER,"Software",0,reg.KEY_SET_VALUE)
創(chuàng)建一個(gè)子項(xiàng)
reg.CreateKey(key, 'test')</pre>
創(chuàng)建完后,我們還要給他一些值和數(shù)據(jù),如下:
<pre spellcheck="false" lang="Python" cid="n355" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;"># 創(chuàng)建值和數(shù)據(jù)
reg.SetValue(key, 'test',reg.REG_SZ, 'hello world')</pre>
所有的工作做完后,我們只需要關(guān)閉就好了,如下:
<pre spellcheck="false" lang="Python" cid="n357" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">#關(guān)閉打開(kāi)的鍵
reg.CloseKey(key)</pre>
這個(gè)時(shí)候,我們可以通過(guò)打開(kāi)和關(guān)閉的注冊(cè)表的鍵的句柄的值來(lái)判斷是什么情況,如下:[圖片上傳失敗...(image-6e2db3-1697989391152)]
可以看到,值完全不一樣,我們?cè)賮?lái)看看我們創(chuàng)建的注冊(cè)表的項(xiàng),如圖:
[圖片上傳失敗...(image-cfaf0f-1697989391152)]
可以看到,此時(shí)的名稱是默認(rèn),并沒(méi)有設(shè)置,如果想設(shè)置我們想要的名稱,這里需要使用SetValueEx,如下:
<pre spellcheck="false" lang="Python" cid="n363" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">reg.SetValueEx(key1, "user",0,reg.REG_SZ, "hello world 123")</pre>
此時(shí)我們就可以將值和數(shù)據(jù)添加到對(duì)應(yīng)的鍵上了,如圖:
[圖片上傳失敗...(image-43554c-1697989391151)]
創(chuàng)建.rar: https://url18.ctfile.com/f/7715018-960795864-b5cede?p=6511 (訪問(wèn)密碼: 6511)
7.修改注冊(cè)表
<pre spellcheck="false" lang="" cid="n369" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.SetValue(key, sub_key, type, value)
將值與指定的注冊(cè)表鍵關(guān)聯(lián)。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
sub_key 是個(gè)字符串,用于命名與該值相關(guān)的子鍵。
type 是個(gè)整數(shù),用于指定數(shù)據(jù)的類型。目前這必須是 REG_SZ ,意味著只支持字符串。請(qǐng)用 SetValueEx() 函數(shù)支持其他的數(shù)據(jù)類型。
value 是設(shè)置新值的字符串。
如果 sub_key 參數(shù)指定的注冊(cè)表鍵不存在,SetValue 函數(shù)會(huì)創(chuàng)建一個(gè)。
值的長(zhǎng)度受到可用內(nèi)存的限制。較長(zhǎng)的值(超過(guò) 2048 字節(jié))應(yīng)存為文件,并將文件名存入配置注冊(cè)表。這有助于提高注冊(cè)表的使用效率。
由 key 參數(shù)標(biāo)識(shí)的注冊(cè)表鍵,必須已用 KEY_SET_VALUE 方式打開(kāi)。
觸發(fā) 審計(jì)事件 winreg.SetValue,附帶參數(shù) key、 sub_key 、 type 、 value。
winreg.SetValueEx(key, value_name, reserved, type, value)
將數(shù)據(jù)存入已打開(kāi)的注冊(cè)表鍵的值中。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
value_name 是個(gè)字符串,用于命名與值相關(guān)的子鍵。
reserved 可以是任意數(shù)據(jù) —— 傳給 API 的總是 0。
type 是個(gè)整數(shù),用于指定數(shù)據(jù)的類型。請(qǐng)參閱 Value Types 了解可用的類型。
value 是設(shè)置新值的字符串。
本方法也可為指定的注冊(cè)表鍵設(shè)置額外的值和類型信息。注冊(cè)表鍵必須已用 KEY_SET_VALUE 方式打開(kāi)。
請(qǐng)用 CreateKey() 或 OpenKey() 方法打開(kāi)注冊(cè)表鍵。
值的長(zhǎng)度受到可用內(nèi)存的限制。較長(zhǎng)的值(超過(guò) 2048 字節(jié))應(yīng)存為文件,并將文件名存入配置注冊(cè)表。這有助于提高注冊(cè)表的使用效率。
觸發(fā) 審計(jì)事件 winreg.SetValue,附帶參數(shù) key、 sub_key 、 type 、 value。</pre>
修改注冊(cè)表其實(shí)就是相當(dāng)于將我們注冊(cè)表的值對(duì)應(yīng)的數(shù)據(jù)改變了,如圖:
[圖片上傳失敗...(image-47929b-1697989391150)]
修改.rar: https://url18.ctfile.com/f/7715018-960795885-cfea81?p=6511 (訪問(wèn)密碼: 6511)
8.查詢注冊(cè)表
1).查詢指定的鍵
<pre spellcheck="false" lang="python" cid="n375" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.QueryInfoKey(key)
以元組形式返回某注冊(cè)表鍵的信息。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
結(jié)果為3元素的元組。
索引 含意
0 整數(shù)值,給出了此注冊(cè)表鍵的子鍵數(shù)量。
1 整數(shù)值,給出了此注冊(cè)表鍵的值的數(shù)量。
2 整數(shù)值,給出了此注冊(cè)表鍵的最后修改時(shí)間,單位為自 1601 年 1 月 1 日以來(lái)的 100 納秒。
觸發(fā) 審計(jì)事件 winreg.QueryInfoKey,附帶參數(shù)為 key。</pre>
[圖片上傳失敗...(image-11808d-1697989391149)]
查詢鍵.rar: https://url18.ctfile.com/f/7715018-960795858-a946eb?p=6511 (訪問(wèn)密碼: 6511)
2).查詢指定的值
<pre spellcheck="false" lang="" cid="n378" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.QueryValue(key, sub_key)
讀取某鍵的未命名值,形式為字符串。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
sub_key 是個(gè)字符串,用于保存與某個(gè)值相關(guān)的子鍵名稱。如果本參數(shù)為 None 或空,函數(shù)將讀取由 SetValue() 方法為 key 鍵設(shè)置的值。
注冊(cè)表中的值包含名稱、類型和數(shù)據(jù)。本方法將讀取注冊(cè)表鍵值的第一個(gè)名稱為 NULL 的數(shù)據(jù)??墒堑讓拥?API 調(diào)用不會(huì)返回類型,所以只要有可能就一定要使用 QueryValueEx()。
觸發(fā) 審計(jì)事件 winreg.QueryValue,附帶參數(shù)為 key、 sub_key 、 value_name。
winreg.QueryValueEx(key, value_name)
讀取已打開(kāi)注冊(cè)表鍵指定值名稱的類型和數(shù)據(jù)。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
value_name 是字符串,表示要查詢的值。
結(jié)果為二元組:
索引 含意
0 注冊(cè)表項(xiàng)的值。
1 整數(shù)值,給出該值的注冊(cè)表類型(請(qǐng)查看文檔中的表格了解 SetValueEx() )。
觸發(fā) 審計(jì)事件 winreg.QueryValue,附帶參數(shù)為 key、 sub_key 、 value_name。</pre>
[圖片上傳失敗...(image-d691e1-1697989391148)]
查詢值.rar: https://url18.ctfile.com/f/7715018-960795861-e3f473?p=6511 (訪問(wèn)密碼: 6511)
9.刪除注冊(cè)表
1).刪除指定的鍵
<pre spellcheck="false" lang="" cid="n382" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.DeleteKey(key, sub_key)
winreg.DeleteKeyEx(key, sub_key, access=KEY_WOW64_64KEY, reserved=0)
刪除指定的鍵。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
sub_key 這個(gè)字符串必須是由 key 參數(shù)所指定鍵的一個(gè)子項(xiàng)。該值項(xiàng)不可以是 None,同時(shí)鍵也不可以有子項(xiàng)。
reserved 是一個(gè)保留的整數(shù),必須是零。默認(rèn)值為零。
access 是一個(gè)指定描述注冊(cè)表鍵所需的安全權(quán)限的訪問(wèn)掩碼的整數(shù)。默認(rèn)值為 KEY_WOW64_64KEY。在 32-bit Windows 上,WOW64 常量會(huì)被忽略。請(qǐng)參閱 訪問(wèn)權(quán)限 了解其他可用的值。
該方法不能刪除帶有子項(xiàng)的鍵。
如果方法成功,則整個(gè)鍵,包括其所有值項(xiàng)都會(huì)被移除。如果方法失敗,則引發(fā)一個(gè) OSError 異常。
在不支持的 Windows 版本之上,將會(huì)引發(fā) NotImplementedError 異常。
引發(fā)一個(gè) 審計(jì)事件 winreg.DeleteKey,附帶參數(shù) key, sub_key, access。</pre>
這里有個(gè)小坑,就是我的子鍵下若是有其它子鍵,那么刪除就會(huì)報(bào)錯(cuò),如圖:
[圖片上傳失敗...(image-db714-1697989391148)]
[圖片上傳失敗...(image-3732c8-1697989391148)]
所以這個(gè)時(shí)候我們可以選擇遞歸刪除,但是這種刪除方法最后會(huì)導(dǎo)致所有的東西都刪除了,就連子鍵本身都會(huì)被刪除。
刪除鍵.rar: https://url18.ctfile.com/f/7715018-960795876-8b36ae?p=6511 (訪問(wèn)密碼: 6511)
2).刪除指定的值
<pre spellcheck="false" lang="" cid="n391" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.DeleteValue(key, value)
從某個(gè)注冊(cè)鍵中刪除一個(gè)命名值項(xiàng)。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
value 為標(biāo)識(shí)所要?jiǎng)h除值項(xiàng)的字符串。</pre>
這個(gè)很容易實(shí)現(xiàn),如圖:
[圖片上傳失敗...(image-5a224c-1697989391147)]
刪除值.rar: https://url18.ctfile.com/f/7715018-960795879-91325e?p=6511 (訪問(wèn)密碼: 6511)
10.枚舉注冊(cè)表
1).枚舉指定的鍵
<pre spellcheck="false" lang="" cid="n396" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.EnumKey(key, index)
列舉某個(gè)已經(jīng)打開(kāi)注冊(cè)表鍵的子項(xiàng),并返回一個(gè)字符串。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
index 為一個(gè)整數(shù),用于標(biāo)識(shí)所獲取鍵的索引。
每次調(diào)用該函數(shù)都會(huì)獲取一個(gè)子項(xiàng)的名字。通常它會(huì)被反復(fù)調(diào)用,直到引發(fā) OSError 異常,這說(shuō)明已經(jīng)沒(méi)有更多的可用值了。
引發(fā)一個(gè) 審計(jì)事件 winreg.EnumKey,附帶參數(shù) key, index。</pre>
[圖片上傳失敗...(image-5d679b-1697989391147)]
枚舉鍵.rar: https://url18.ctfile.com/f/7715018-960795870-44077e?p=6511 (訪問(wèn)密碼: 6511)
2).枚舉指定的值
<pre spellcheck="false" lang="" cid="n399" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.EnumValue(key, index)
列舉某個(gè)已經(jīng)打開(kāi)注冊(cè)表鍵的值項(xiàng),并返回一個(gè)元組。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
index 為一個(gè)整數(shù),用于標(biāo)識(shí)要獲取值項(xiàng)的索引。
每次調(diào)用該函數(shù)都會(huì)獲取一個(gè)子項(xiàng)的名字。通常它會(huì)被反復(fù)調(diào)用,直到引發(fā) OSError 異常,這說(shuō)明已經(jīng)沒(méi)有更多的可用值了。
結(jié)果為3元素的元組。
索引 含意
0 用于標(biāo)識(shí)值項(xiàng)名稱的字符串。
1 保存值項(xiàng)數(shù)據(jù)的對(duì)象,其類型取決于背后的注冊(cè)表類型。
2 標(biāo)識(shí)值項(xiàng)數(shù)據(jù)類型的整數(shù)。(請(qǐng)查閱 SetValueEx() 文檔中的表格)
引發(fā)一個(gè) 審計(jì)事件 winreg.EnumValue,附帶參數(shù) key, index。</pre>
[圖片上傳失敗...(image-705be0-1697989391146)]
枚舉值.rar: https://url18.ctfile.com/f/7715018-960795873-5d8e9d?p=6511 (訪問(wèn)密碼: 6511)
11.讀取保存注冊(cè)表
<pre spellcheck="false" lang="" cid="n401" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.LoadKey(key, sub_key, file_name)
在指定鍵之下創(chuàng)建一個(gè)子鍵,并將指定文件中的注冊(cè)表信息存入該子鍵中。
key 是由 ConnectRegistry() 返回的句柄,或者是常量 HKEY_USERS 或 HKEY_LOCAL_MACHINE。
sub_key 是個(gè)字符串,用于標(biāo)識(shí)需要載入的子鍵。
file_name 是要加載注冊(cè)表數(shù)據(jù)的文件名。該文件必須是用 SaveKey() 函數(shù)創(chuàng)建的。在文件分配表(FAT)文件系統(tǒng)中,文件名可能不帶擴(kuò)展名。
如果調(diào)用 LoadKey() 的進(jìn)程沒(méi)有 SE_RESTORE_PRIVILEGE 特權(quán)則調(diào)用將失敗。請(qǐng)注意特權(quán)與權(quán)限是不同的 -- 更多細(xì)節(jié)請(qǐng)參閱 RegLoadKey 文檔。
如果 key 是由 ConnectRegistry() 返回的句柄,那么 file_name 指定的路徑是相對(duì)于遠(yuǎn)程計(jì)算機(jī)而言的。
引發(fā)一個(gè) 審計(jì)事件 winreg.LoadKey,附帶參數(shù) key, sub_key, file_name。
winreg.SaveKey(key, file_name)
將指定注冊(cè)表鍵及其所有子鍵存入指定的文件。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
file_name 是要保存注冊(cè)表數(shù)據(jù)的文件名。該文件不能已存在。如果文件名包括擴(kuò)展名,也不能在文件分配表(FAT)文件系統(tǒng)中用于 LoadKey() 方法。
如果 key 是代表遠(yuǎn)程計(jì)算機(jī)上的注冊(cè)表鍵,那么 file_name 所描述的路徑就是相對(duì)于遠(yuǎn)程計(jì)算機(jī)的。本方法的調(diào)用方必須擁有 SeBackupPrivilege 安全特權(quán)。請(qǐng)注意特權(quán)與權(quán)限是不同的 -- 更多細(xì)節(jié)請(qǐng)參閱 Conflicts Between User Rights and Permissions 文檔。
本函數(shù)將 NULL 傳給 API 的 security_attributes。
引發(fā)一個(gè) 審計(jì)事件 winreg.SaveKey,附帶參數(shù) key, file_name。</pre>
12.刷新注冊(cè)表鍵
<pre spellcheck="false" lang="" cid="n410" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.FlushKey(key)
將某個(gè)鍵的所有屬性寫(xiě)入注冊(cè)表。
key 為某個(gè)已經(jīng)打開(kāi)的鍵,或者預(yù)定義的 HKEY_* 常量 之一。
沒(méi)有必要調(diào)用 FlushKey() 去改動(dòng)注冊(cè)表鍵。注冊(cè)表的變動(dòng)是由其延遲刷新機(jī)制更新到磁盤(pán)的。在系統(tǒng)關(guān)機(jī)時(shí),也會(huì)將注冊(cè)表的變動(dòng)寫(xiě)入磁盤(pán)。與 CloseKey() 不同, FlushKey() 方法只有等到所有數(shù)據(jù)都寫(xiě)入注冊(cè)表后才會(huì)返回。只有需要絕對(duì)確認(rèn)注冊(cè)表變動(dòng)已寫(xiě)入磁盤(pán)時(shí),應(yīng)用程序才應(yīng)去調(diào)用 FlushKey()。
備注 如果不知道是否要調(diào)用 FlushKey() ,可能就是不需要。</pre>
13.啟用禁用注冊(cè)表
<pre spellcheck="false" lang="" cid="n416" mdtype="fences" style="margin: 15px 0px; padding: 8px 4px 6px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow: visible; font-family: var(--monospace); font-size: 0.9em; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border-width: 1px; border-style: solid; border-color: rgb(231, 234, 237); border-radius: 3px; width: inherit; color: rgb(51, 51, 51); letter-spacing: normal;">winreg.DisableReflectionKey(key) #禁用
winreg.EnableReflectionKey(key) #啟用</pre>
另外還有兩個(gè)關(guān)于開(kāi)啟和關(guān)閉網(wǎng)絡(luò)代理以及關(guān)聯(lián)右鍵菜單的注冊(cè)表鍵操作,如下:
winreg開(kāi)啟關(guān)閉系統(tǒng)網(wǎng)絡(luò)代理模式案例.rar: https://url18.ctfile.com/f/7715018-960852603-8b368b?p=6511 (訪問(wèn)密碼: 6511)
關(guān)聯(lián)到右鍵菜單.rar: https://url18.ctfile.com/f/7715018-960852606-03fb0c?p=6511 (訪問(wèn)密碼: 6511)
上面就是一些關(guān)于Python操作注冊(cè)表的知識(shí)了,大家對(duì)什么技術(shù)感興趣,可以在下方發(fā)消息給我,感謝大家的支持。