Languages :: Java :: how to write an agent to monitor a server |
|||
| By: Dineth |
Date: 03/10/2003 00:00:00 |
Points: 300 | Status: Answered Quality : Excellent |
|
Hi, I want a write an agent to monitor the status of a particular service in the win environment..It would be better if an icon could be displayed in the system tray. Prefered language is VB. could u pls guide me . bye Dineth |
|||
| By: cvsherri | Date: 03/10/2003 03:55:00 | Type : Answer |
|
| http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20320650.html?query=is+service+running&searchType=topic perhaps this will help |
|||
| By: cookre | Date: 03/10/2003 13:18:00 | Type : Assist |
|
| That's certainly the proper way to go about it, however, a rather more prosaic way would be to shell out to an sc.exe with a redirected stdout. E.g.: Shell("cmd /c ""sc query svcname >c:\sc.txt""") |
|||
| By: VGR | Date: 03/10/2003 16:02:00 | Type : Assist |
|
| for the systray part : here's the one for Delphi : Please note that I also handle a small popup menu having options "close" (exit app) and "restore" (show again) managing the SysTray icon in main Form's unit : Uses [...], Menus; // for TNotifyIconData Const UM_NOTIFYICON = WM_USER +1; type TForm1 = class(TForm) // [...] public TrayIcon: TNotifyIconData; procedure UMNotifyIcon(var Msg : TMessage); message UM_NOTIFYICON; procedure MinimizeToTray(Sender: TObject); procedure NormalMinimize(Sender: TObject); procedure RestoreMainForm; procedure ShowThePopup; in implementation : procedure TForm1.MinimizeToTray(Sender: TObject); begin //ShowWindow(Application.Handle,SW_HIDE); Shell_notifyIcon(NIM_ADD, @TrayIcon); Form1.WindowState:=wsMinimized; Form1.Visible := False; Application.Minimize; end; procedure TForm1.RestoreMainForm; begin //ShowWindow(Application.Handle,SW_SHOW); Form1.Visible := True; Form1.WindowState:=wsNormal; SetForegroundWindow(Form1.Handle); Application.BringToFront; Application.Restore; SetFocus; Shell_notifyIcon(NIM_DELETE, @TrayIcon); end; procedure TForm1.ShowThePopup; var CurPos: TPoint; begin GetCursorPos(CurPos); PopupMenu1.Popup(CurPos.x, CurPos.y); PostMessage(Self.Handle, WM_NULL, 0, 0); end; procedure TForm1.UMNotifyIcon; // (var Msg : TMessage); message UM_NOTIFYICON; Var uID : integer; uMouseMsg : integer; Begin uID:=Msg.wParam; uMouseMsg:=Msg.lParam; If uID=0 Then // première icône créée Case uMouseMsg Of WM_LBUTTONDOWN : ; // rien WM_LBUTTONDBLCLK : RestoreMainForm; WM_RBUTTONDOWN : ShowThePopup; End // Case End; -------------- in the form where I change the settings between "yes, hide in SysTray when minimized" and "no, don't" : // this is in a procedure "change settings" or "apply changes" // optTray is the Boolean controlling whether or not you want to "hide application" in SysTray. I switch between TRUE/FALSE from a secondary "configuration" form. If optTray Then With Form1 Do Begin // activation // going to SysTray when Minimized TrayIcon.cbSize := SizeOf(TrayIcon); TrayIcon.Wnd := Form1.Handle; TrayIcon.uID := 0; TrayIcon.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; TrayIcon.uCallbackMessage := UM_NOTIFYICON; TrayIcon.hIcon := Application.Icon.Handle; TrayIcon.szTip := globApp+' - Running'; // globApp is my application's fancy name Application.OnMinimize := MinimizeToTray; End // if optTray Else With Form1 Do Begin Application.OnMinimize := NormalMinimize; TrayIcon.cbSize := SizeOf(TrayIcon); TrayIcon.Wnd := Form1.Handle; TrayIcon.uID := 0; Shell_notifyIcon(NIM_DELETE, @TrayIcon); End; // deactivate |
|||
| By: Dineth | Date: 04/10/2003 16:29:00 | Type : Comment |
|
| Hi Thank you all, I am new to delphi, could anybody know how to do that in VB. Dineth |
|||
| By: VGR | Date: 05/10/2003 05:03:00 | Type : Comment |
|
| well, à part from some minor syntaxic differences, it's the same as far as the API calls are concerned... |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








