Wednesday, 15 June 2011

windows - Can Powershell put counter values in the system tray? -



windows - Can Powershell put counter values in the system tray? -

i trying monitor wifi adapter's throughput numerically on scheme tray; so.

i figured out static powershell query

((get-counter '\\mullick1\network interface(intel[r] centrino[r] advanced-n 6205)\bytes total/sec').countersamples).cookedvalue*8/102400000*100

but how can continuous feed , how set on scheme tray ? found alternate solution in diskled software. doesn't show actual value.

this script render(update) text @ notify icon.

customize "get-notifyicontext" function like.

#requires -version 3.0 function get-notifyicontext { [datetime]::now.second.tostring() # ((get-counter '\\mypc\network interface(intel[r] 82579v gigabit network connection)\bytes total/sec').countersamples).cookedvalue*8/102400000*100 } add-type -referencedassemblies @("system.windows.forms"; "system.drawing") -typedefinition @" using system; using system.drawing; using system.windows.forms; public static class textnotifyicon { // it's hard phone call destroyicon() powershell only... [system.runtime.interopservices.dllimport("user32")] private static extern bool destroyicon(intptr hicon); public static notifyicon createtrayicon() { var notifyicon = new notifyicon(); notifyicon.visible = true; homecoming notifyicon; } public static void updateicon(notifyicon notifyicon, string text) { using (var b = new bitmap(16, 16)) using (var g = graphics.fromimage(b)) using (var font = new font(fontfamily.genericmonospace, 8)) { g.drawstring(text, font, brushes.black, 0, 0); var icon = b.gethicon(); seek { notifyicon.icon = icon.fromhandle(icon); } { destroyicon(icon); } } } } "@ $icon = [textnotifyicon]::createtrayicon() while ($true) { $text = get-notifyicontext [textnotifyicon]::updateicon($icon, $text) [threading.thread]::sleep(1000) }

windows powershell performancecounter system-tray

No comments:

Post a Comment