轉 我修改的註冊表,但是程式運行起來,還是記著以前的

來源:互聯網
上載者:User

標籤:version   create   roo   off   資料   proxy   pen   讀取   sub   

我修改的註冊表,但是程式運行起來,還是記著以前的,
我查看了相關資料,說是修改只是暫時儲存在memory,並沒有儲存到harddisk中,請高手指點一下,我用python寫的,代碼如下
import win32api
import win32con

def RegSubkeySet(dbName, dbVersion):
    
    key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,‘Software\\DSA\\PRODIS Office\\Settings‘,0,win32con.KEY_ALL_ACCESS)
    win32api.RegQueryValueEx(key,‘Data Source‘)
    win32api.RegSetValueEx(key,‘Data Source‘,0,win32con.REG_SZ,dbName)
    win32api.RegSetValueEx(key,‘ExpVersion‘,0,win32con.REG_SZ,dbVersion)
    win32api.RegCloseKey(key)
    
# Test ------------------------------------------------------------------

if __name__ == "__main__":
    pass

 

用 _winreg 試試
我當初用的是這個
相關例子:
註冊表設定:
建key
>>> import _winreg
>>> root = _winreg.HKEY_LOCAL_MACHINE
>>> proxy_path = r"SOFTWARE\py"
>>> hkey = _winreg.CreateKey(root,proxy_path) #註冊表裡如果已經存在proxy_path則建一個,如果有則開啟
>>> _winreg.SetValueEx(hkey,"py",0,_winreg.REG_SZ,"py is the best.") #建立一個字串值
註冊表裡:
名稱    類型    資料
py      REG_SZ  py is the best.
 
讀取註冊表裡已經存在的key的資訊:
>>> x = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
>>> y = _winreg.OpenKey(x,r"SOFTWARE\py")
>>> value = _winreg.QueryValueEx(y,‘py‘)[0] #如果沒有
>>> print value
py is the best.
尋找是否有某個key存在:
>>> hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,r"SOFTWARE\py")
>>> keyinfo = _winreg.QueryInfoKey(hkey)
>>> keyinfo[1]
1
>>> _winreg.EnumValue(hkey,0)
(‘Install_Dir‘, u‘d:\\py‘, 1)
>>> n,v,t = _
>>> n
‘Install_Dir‘
>>> n == ‘install_dir‘
False
>>> n == ‘Install_Dir‘
True
>>> v
u‘d:\\py‘

希望能幫到你

轉 我修改的註冊表,但是程式運行起來,還是記著以前的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.