gordon
8/15/2006 5:11:00 PM
You can use WMI via win32ole:
require 'win32ole'
def append_to_system_path(path)
wmi = WIN32OLE.connect("winmgmts:\\\\.\\root\\cimv2")
wql = "Select * from Win32_Environment Where Name = 'PATH' and UserName = '<SYSTEM>'"
system_path = wmi.ExecQuery(wql)
system_path.each do |i|
i.VariableValue += ";#{path}"
i.Put_
end
end
def create_environment_variable(var_name, value)
wmi = WIN32OLE.connect("winmgmts:\\\\.\\root\\cimv2")
env_var = wmi.Get('Win32_Environment').SpawnInstance_
env_var.Name = var_name
env_var.UserName = "<SYSTEM>"
env_var.VariableValue = value
env_var.Put_
end
path = "C:\\something_you_want_appended"
append_to_system_path(path)
var_name = 'test'
value = 'SOME_VALUE'
create_environment_variable(var_name, value)