Skip to content

Instantly share code, notes, and snippets.

@krisf
Created October 27, 2011 15:57
Show Gist options
  • Save krisf/1319972 to your computer and use it in GitHub Desktop.
Save krisf/1319972 to your computer and use it in GitHub Desktop.
registry fun in ruby
def create_registry_keys(data)
require 'win32/registry'
data.each do |key, value|
path = key.split("\\").delete_at(-1).delete_at(0).join("\\")
root = key.split("\\").first
key = key.split("\\").last
if root == "HKEY_CURRENT_USER"
hive = Win32::Registry::HKEY_CURRENT_USER.new
else
hive = Win32::Registry::HKEY_LOCAL_MACHINE.new
end
hive.open(path) do |reg|
reg.write(key, reg_type(value), value)
end
end
end
def create_and_autologin_user(name, password, autologin)
system("net user /add '#{name}' '#{password}'")
system("net localgroup administrators '#{name}' /add")
if autologin
create_registry_keys({
'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\winlogon\AutoAdminLogon' => '1',
'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\winlogon\DefaultUserName' => name,
'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\winlogon\DefaultPassword' => password
})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment