2014-06-23 2 views
1

시스템 트레이에서 숫자로 Wifi 어댑터의 처리량을 모니터링하려고합니다. 그렇게. enter image description herePowershell은 카운터 값을 시스템 트레이에 넣을 수 있습니까?

나는 정적 파워 쉘 쿼리

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

을 생각하지만 어떻게 내가 지속적인 공급을받을 수 있으며, 어떻게 시스템 트레이에 배치해야합니까? Diskled 소프트웨어에서 대체 솔루션을 찾았습니다. 그러나 실제 가치는 보여주지 않습니다.

+3

당신은 WinFroms GUI를 만들어야합니다 .notifyicon.aspx). 그런 다음 타이머를 사용하여 카운터의 새 값을 가져 와서 아이콘을 업데이트하십시오. – Richard

+0

@ 리차드 .Net 프로그래밍에 정통하지 않습니다. 나는 [this] (http://www.codeproject.com/Articles/74/Adding-Icons-to-the-System-Tray)와 같은 것을 코드화하고 컴파일해야합니까? –

+2

[이 블로그 게시물] (http://www.sapien.com/blog/2012/05/08/spotlight-on-the-notifyicon-control/)을보십시오. –

답변

1

알림 아이콘에 텍스트를 렌더링 (업데이트)하는 스크립트입니다.

"Get-NotifyIconText"기능을 원하는대로 사용자 정의하십시오. 당신이 [`NotifyIcon`]의 인스턴스의 사용 (http://msdn.microsoft.com/en-us/library/system.windows.forms을 할 수 있도록

#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 difficult to call DestroyIcon() with 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; 

      return 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(); 
       try 
       { 
        notifyIcon.Icon = Icon.FromHandle(icon); 
       } finally 
       { 
        DestroyIcon(icon); 
       } 
      } 
     } 
    } 
"@ 

$icon = [TextNotifyIcon]::CreateTrayIcon() 
while ($true) { 
    $text = Get-NotifyIconText 
    [TextNotifyIcon]::UpdateIcon($icon, $text) 
    [Threading.Thread]::Sleep(1000) 
} 
+0

종료시 아이콘이 사라지지 않습니다. –

관련 문제