大的圖景是,我是把下面的代碼,這會產生像在Windows任務列表。但我想過濾掉用戶系統,本地服務和網絡服務。然後過濾列拱,會話和路徑。如何從Ruby中的數組中刪除散列?
print_line
processes = @client.sys.process.get_processes
process_list = processes.to_table('Header' => "%bld %dmag Target Process Info:\n", 'Indent' => 4)
到目前爲止,我得到了用戶,但我堅持刪除哈希與鍵拱會話和路徑。 這裏是原始格式的輸出。
[
{"pid"=>0, "ppid"=>0, "name"=>"[System Process]", "path"=>"", "session"=>4294967295, "user"=>"", "arch"=>""},
{"pid"=>456, "ppid"=>320, "name"=>"explorer.exe", "path"=>"C:\\WINDOWS\\Explorer.EXE", "session"=>0, "user"=>"CLINE\\Administrator", "arch"=>"x86"},
{"pid"=>544, "ppid"=>204, "name"=>"TPAutoConnect.exe", "path"=>"C:\\Program Files\\VMware\\VMware Tools\\TPAutoConnect.exe", "session"=>0, "user"=>"CLINE\\Administrator", "arch"=>"x86"},
{"pid"=>1096, "ppid"=>456, "name"=>"vmtoolsd.exe", "path"=>"C:\\Program Files\\VMware\\VMware Tools\\vmtoolsd.exe", "session"=>0, "user"=>"CLINE\\Administrator", "arch"=>"x86"},
{"pid"=>180, "ppid"=>456, "name"=>"rundll32.exe", "path"=>"C:\\WINDOWS\\system32\\rundll32.exe", "session"=>0, "user"=>"CLINE\\Administrator", "arch"=>"x86"},
{"pid"=>1208, "ppid"=>724, "name"=>"logon.scr", "path"=>"C:\\WINDOWS\\System32\\logon.scr", "session"=>0, "user"=>"CLINE\\Administrator", "arch"=>"x86"}
]
這是我的代碼到目前爲止。
print_line
processes = @client.sys.process.get_processes
blacklist = ["NT AUTHORITY\\SYSTEM", "NT AUTHORITY\\LOCAL SERVICE", "NT AUTHORITY\\NETWORK SERVICE"]
filtered = processes.reject {|h| blacklist.include? h['user']}
print_status (filtered)
原來也有使用to_table的輸出,但我似乎已經打破了?
您的代碼不容易閱讀的格式顯示。你能澄清這一點嗎?刪除在哈希元素的一種方式 - 這似乎是你是什麼asking--是寫:myhash.delete(「my_element」) –