home *** CD-ROM | disk | FTP | other *** search
Wrap
{$INCLUDE MITEC_DEF.INC} unit Main; interface uses {$IFDEF D6PLUS} Variants, {$ENDIF} Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Menus, ImgList, StdCtrls, MiTeC_PerfLibNT, MiTeC_PerfLib9x, PropsDlg, MSI_GUI, MSI_Overview, MiTeC_EventLogNT, MiTeC_Shares, MiTeC_AccountsNT, ComCtrls, ExtCtrls, MiTeC_JobsNT, MiTeC_WkstaNT, MiTeC_ServerNT; type TListViewClass = TListView; TfrmMain = class(TForm) sb: TStatusBar; Splitter1: TSplitter; Notebook: TNotebook; lv: TListView; TopicPanel: TPanel; Tree: TTreeView; Splitter2: TSplitter; Splitter3: TSplitter; ValPanel: TPanel; Panel2: TPanel; InstPanel: TPanel; Panel4: TPanel; lbInst: TListBox; lbVal: TListBox; InfoPanel: TPanel; TreePanel: TPanel; TreeTitle: TPanel; tv: TTreeView; imgList: TImageList; imgTree: TImageList; SystemInfo: TMSystemInfo; TreeMenu: TPopupMenu; pmRefresh: TMenuItem; N2: TMenuItem; pmSaveRep: TMenuItem; PopupMenu: TPopupMenu; pmSave: TMenuItem; N4: TMenuItem; pmProps: TMenuItem; pmClose: TMenuItem; MainMenu: TMainMenu; File1: TMenuItem; mmClose: TMenuItem; mmAbout: TMenuItem; pmRefs: TMenuItem; pmDelete: TMenuItem; imgDevices: TImageList; N3: TMenuItem; N1: TMenuItem; ControlPanels1: TMenuItem; All1: TMenuItem; N5: TMenuItem; AddRemovePrograms1: TMenuItem; DateTime1: TMenuItem; Display1: TMenuItem; Multimedia1: TMenuItem; mmNet: TMenuItem; RegionalSettings1: TMenuItem; System1: TMenuItem; mmAction: TMenuItem; Refresh1: TMenuItem; N6: TMenuItem; mmSave: TMenuItem; N7: TMenuItem; mmCloseItem: TMenuItem; mmDelete: TMenuItem; mmRefs: TMenuItem; mmProps: TMenuItem; mmSI: TMenuItem; N8: TMenuItem; procedure cmClose(Sender: TObject); procedure FormCreate(Sender: TObject); procedure TreeChange(Sender: TObject; Node: TTreeNode); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure tvChange(Sender: TObject; Node: TTreeNode); procedure lvDblClick(Sender: TObject); procedure tvDblClick(Sender: TObject); procedure TreeMenuPopup(Sender: TObject); procedure TreeViewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure cmAbout(Sender: TObject); procedure cmRefresh(Sender: TObject); procedure PopupMenuPopup(Sender: TObject); procedure cmProps(Sender: TObject); procedure cmCloseItem(Sender: TObject); procedure cmSave(Sender: TObject); procedure cmRefs(Sender: TObject); procedure cmDelete(Sender: TObject); procedure cmCP(Sender: TObject); procedure cmAction(Sender: TObject); procedure lvChange(Sender: TObject; Item: TListItem; Change: TItemChange); procedure mmSIClick(Sender: TObject); private { Private declarations } PLNT: TPerfLibNT; PL9x: TPerfLib9x; EventLog: TEventLog; ShareNT: TNTShares; Share9x: T9xShares; Accounts: TAccounts; JobNT: TNTJobs; Wksta: TNTWksta; Server: TNTServer; RefList, WinList, ProcessList, ServiceList, DriverList, ServerList: TStringList; FComputer: string; FSingleMachine: Boolean; procedure FreeWindowList(AList: TStringList); public { Public declarations } procedure RefreshProcesses(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshModules(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshServices(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshEnvironment(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshDrivers(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshPerformance(ATreeView: TTreeView); procedure RefreshWindows(ATreeView: TTreeView); procedure RefreshEvents(AListView: TListViewClass; AImageIndex: Integer; AType: TEventLogType); procedure RefreshSysInfo(AListView: TListViewClass); procedure RefreshShares(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshSessions(AListView: TListViewClass; AImageIndex: integer); procedure RefreshOpenFiles(AListView: TListViewClass; AImageIndex: integer); procedure RefreshUsers(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshGroups(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshGlobalGroups(AListView: TListViewClass; AImageIndex: Integer); procedure RefreshErrors(AListView: TListViewClass; AImageIndex: integer); procedure RefreshJobs(AListView: TListViewClass; AImageIndex: integer); procedure RefreshWkstaInfo(AListView: TListViewClass; AImageIndex: integer); procedure RefreshWkstaTrans(AListView: TListViewClass; AImageIndex: integer); procedure RefreshWkstaUsers(AListView: TListViewClass; AImageIndex: integer); procedure RefreshServerTrans(AListView: TListViewClass; AImageIndex: integer); procedure RefreshServers; procedure RefreshDevices(ATreeView: TTreeView); procedure Refresh; procedure ShowProps(AType: TPropertyType; AParameter: Variant); procedure ShowSIProps(AType: TPages); procedure CloseSession(AName, AUsername: string); procedure CloseOpenFile(AID: DWORD); procedure DeleteJob(AID: DWORD); property Computer: string read FComputer write FComputer; property SingleMachine: Boolean read FSingleMachine; end; var frmMain: TfrmMain; implementation uses MiTeC_EnumsNT, MiTeC_Enums9x, MiTeC_Routines, MiTeC_NetAPI32, ShellAPI, RefsDlg, MSI_Devices, MiTeC_CtrlRtns; {$R *.DFM} const iiCompInfo = 0; iiSystemInfo = 5; iiSoftware = 6; iiEnvVar = 7; iiRunningTasks = 8; iiModules = 9; iiServices = 10; iiDrivers = 11; iiPerformance = 12; iiWindows = 13; iiEventViewer = 1; iiApplication = 2; iiSecurity = 3; iiSystem = 4; iiError = 14; iiWarning = 15; iiInfo = 16; iiAuditSucc = 17; iiAuditFail = 18; iiSharedFolders = 19; iiShares = 20; iiSessions = 21; iiOpenFiles = 22; iiAccounts = 23; iiUsers = 24; iiGroups = 25; iiScheduler = 26; iiTask = 27; iiWkstaNT = 28; iiWkstaTrans = 29; iiWkstaUsers = 30; iiWkstaInfo = 32; iiGlobalGroups = 31; iiDevices = 33; iiWksta = 50; iiCPU = 51; iiMemory = 52; iiOS = 53; iiDrives = 54; iiNetwork = 55; iiMultimedia = 56; iiDisplay = 57; iiUSB = 58; iiInput = 59; iiPorts = 60; iiSysDev = 61; iiObject = 2; iiCounter = 3; ControlPanelRun: array[0..8] of string= ('shell32.dll,Control_RunDLL', 'shell32.dll,Control_RunDLL appwiz.cpl', 'shell32.dll,Control_RunDLL timedate.cpl', 'shell32.dll,Control_RunDLL desk.cpl', 'shell32.dll,Control_RunDLL mmsys.cpl', 'shell32.dll,Control_RunDLL netcpl.cpl', 'shell32.dll,Control_RunDLL ncpa.cpl', 'shell32.dll,Control_RunDLL intl.cpl', 'shell32.dll,Control_RunDLL sysdm.cpl'); type THeaderType = (htTopic, htProc, htSrv, htDrv, htEvent, htItem, htShare, htSession, htMods, htErrors, htUsers, htGroups, htOpenFiles, htJobs, htWkstaTrans,htSrvTrans,htWkstaUsers); TDetailType = (dtDefault, dtList, dtTree); procedure SetDetail(ANotebook: TNotebook; AType: TDetailType); begin with ANotebook do begin PageIndex:=Integer(AType); if Assigned(OnPageChanged) then OnPageChanged(ANotebook); end; end; procedure SetTopics(ATreeView: TTreeView; ALocalInfo: Boolean); var Root, SubRoot, Node: TTreeNode; begin with ATreeView, Items do begin FullCollapse; BeginUpdate; Clear; Root:=Add(nil,'Computer Information'); Root.ImageIndex:=iiCompInfo; Root.SelectedIndex:=Root.ImageIndex; if IsNT then begin SubRoot:=AddChild(Root,'Event Viewer'); SubRoot.ImageIndex:=iiEventViewer; SubRoot.SelectedIndex:=SubRoot.ImageIndex; Node:=AddChild(SubRoot,'Application'); Node.ImageIndex:=iiApplication; Node.SelectedIndex:=Node.ImageIndex; Node:=AddChild(SubRoot,'Security'); Node.ImageIndex:=iiSecurity; Node.SelectedIndex:=Node.ImageIndex; Node:=AddChild(SubRoot,'System'); Node.ImageIndex:=iiSystem; Node.SelectedIndex:=Node.ImageIndex; end; if ALocalInfo then begin SubRoot:=AddChild(Root,'System Information'); SubRoot.ImageIndex:=iiSystemInfo; SubRoot.SelectedIndex:=SubRoot.ImageIndex; SubRoot:=AddChild(Root,'Device Manager'); SubRoot.ImageIndex:=iiDevices; SubRoot.SelectedIndex:=SubRoot.ImageIndex; end; SubRoot:=AddChild(Root,'Software Environment'); SubRoot.ImageIndex:=iiSoftware; SubRoot.SelectedIndex:=SubRoot.ImageIndex; if ALocalInfo then begin Node:=AddChild(SubRoot,'Environment Variables'); Node.ImageIndex:=iiEnvVar; Node.SelectedIndex:=Node.ImageIndex; Node:=AddChild(SubRoot,'Running Tasks'); Node.ImageIndex:=iiRunningTasks; Node.SelectedIndex:=Node.ImageIndex; Node:=AddChild(SubRoot,'Loaded Modules'); Node.ImageIndex:=iiModules; Node.SelectedIndex:=Node.ImageIndex; end; if IsNT then begin Node:=AddChild(SubRoot,'Services'); Node.ImageIndex:=iiServices; Node.SelectedIndex:=Node.ImageIndex; end; if ALocalInfo then begin if IsNT then begin Node:=AddChild(SubRoot,'Drivers'); Node.ImageIndex:=iiDrivers; Node.SelectedIndex:=Node.ImageIndex; end; Node:=AddChild(SubRoot,'Windows'); Node.ImageIndex:=iiWindows; Node.SelectedIndex:=Node.ImageIndex; end; if ALocalInfo and (IsNT or Is98 or IsME or (Is95 and IsOSR2)) then begin SubRoot:=AddChild(Root,'Performance'); SubRoot.ImageIndex:=iiPerformance; SubRoot.SelectedIndex:=SubRoot.ImageIndex; end; SubRoot:=AddChild(Root,'Shared Folders'); SubRoot.ImageIndex:=iiSharedFolders; SubRoot.SelectedIndex:=SubRoot.ImageIndex; Node:=AddChild(SubRoot,'Shares'); Node.ImageIndex:=iiShares; Node.SelectedIndex:=Node.ImageIndex; Node:=AddChild(SubRoot,'Sessions'); Node.ImageIndex:=iiSessions; Node.SelectedIndex:=Node.ImageIndex; if IsNT then begin Node:=AddChild(SubRoot,'Open Files'); Node.ImageIndex:=iiOpenFiles; Node.SelectedIndex:=Node.ImageIndex; end; if IsNT then begin SubRoot:=AddChild(Root,'Local Users and Groups'); SubRoot.ImageIndex:=iiAccounts; SubRoot.SelectedIndex:=SubRoot.ImageIndex; Node:=AddChild(SubRoot,'Users'); Node.ImageIndex:=iiUsers; Node.SelectedIndex:=Node.ImageIndex; Node:=AddChild(SubRoot,'Groups'); Node.ImageIndex:=iiGroups; Node.SelectedIndex:=Node.ImageIndex; SubRoot:=AddChild(Root,'Scheduled Tasks'); SubRoot.ImageIndex:=iiScheduler; SubRoot.SelectedIndex:=SubRoot.ImageIndex; if not frmMain.SingleMachine then begin SubRoot:=AddChild(Root,'Global Groups'); SubRoot.ImageIndex:=iiGlobalGroups; SubRoot.SelectedIndex:=SubRoot.ImageIndex; SubRoot:=AddChild(Root,'Machine'); SubRoot.ImageIndex:=iiWkstaNT; SubRoot.SelectedIndex:=SubRoot.ImageIndex; Node:=AddChild(SubRoot,'Information'); Node.ImageIndex:=iiWkstaInfo; Node.SelectedIndex:=Node.ImageIndex; Node:=AddChild(SubRoot,'Transport Protocols'); Node.ImageIndex:=iiWkstaTrans; Node.SelectedIndex:=Node.ImageIndex; Node:=AddChild(SubRoot,'Users'); Node.ImageIndex:=iiWkstaUsers; Node.SelectedIndex:=Node.ImageIndex; end; end; EndUpdate; Root.Expand(False); end; end; procedure SetHeader(AListView: TListViewClass; AType: THeaderType); begin with AListView, Columns do begin ViewStyle:=vsReport; AListView.Items.BeginUpdate; AListView.Items.Clear; AListView.Items.EndUpdate; BeginUpdate; Clear; case AType of htTopic: with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=200; end; htProc: begin if IsNT then begin with Add do begin Caption:='Image name'; Alignment:=taLeftJustify; Width:=150; end; with Add do begin caption:='PID'; alignment:=taRightJustify; width:=50; end; with Add do begin Caption:='CPU Time'; Alignment:=taRightJustify; Width:=70; end; with Add do begin Caption:='Mem usage'; Alignment:=taRightJustify; Width:=70; end; with Add do begin Caption:='Priority'; Alignment:=taRightJustify; Width:=50; end; end else begin with Add do begin Caption:='Image name'; Alignment:=taLeftJustify; Width:=150; end; with Add do begin Caption:='PID'; Alignment:=taRightJustify; Width:=80; end; with Add do begin Caption:='Priority'; Alignment:=taRightJustify; Width:=75; end; with Add do begin Caption:='Usage'; Alignment:=taRightJustify; Width:=50; end; end; end; htSrv: begin with Add do begin Caption:='Display Name'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=150; end; with Add do begin caption:='Status'; alignment:=taLeftJustify; width:=75; end; with Add do begin Caption:='Startup Type'; Alignment:=taLeftJustify; Width:=75; end; with Add do begin Caption:='Log On As'; Alignment:=taLeftJustify; Width:=75; end; end; htDrv: begin with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin caption:='Description'; alignment:=taLeftJustify; width:=200; end; with Add do begin Caption:='Group'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='File'; Alignment:=taLeftJustify; Width:=150; end; with Add do begin Caption:='Type'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Start Mode'; Alignment:=taLeftJustify; Width:=75; end; with Add do begin Caption:='State'; Alignment:=taLeftJustify; Width:=60; end; with Add do begin Caption:='Error Control'; Alignment:=taLeftJustify; Width:=75; end; {with Add do begin Caption:='Accept Pause'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Accept Stop'; Alignment:=taLeftJustify; Width:=100; end;} end; htEvent: begin with Add do begin Caption:='Type'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Datetime'; Alignment:=taLeftJustify; Width:=120; end; with Add do begin Caption:='Source'; Alignment:=taLeftJustify; Width:=150; end; with Add do begin Caption:='Category'; Alignment:=taLeftJustify; Width:=75; end; with Add do begin Caption:='Event'; Alignment:=taRightJustify; Width:=50; end; with Add do begin Caption:='User'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Computer'; Alignment:=taLeftJustify; Width:=100; end; end; htItem: begin with Add do begin Caption:='Item'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Value'; Alignment:=taLeftJustify; Width:=300; end; end; htShare: begin with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Path'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Type'; Alignment:=taLeftJustify; Width:=70; end; with Add do begin Caption:='Descriptor'; Alignment:=taLeftJustify; Width:=70; end; with Add do begin Caption:='Max Users'; Alignment:=taRightJustify; Width:=65; end; with Add do begin Caption:='Cur Users'; Alignment:=taRightJustify; Width:=60; end; with Add do begin Caption:='Permissions'; Alignment:=taLeftJustify; Width:=70; end; with Add do begin Caption:='Comment'; Alignment:=taLeftJustify; Width:=100; end; end; htSession: begin with Add do begin Caption:='User'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Computer'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Type'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Open Files'; Alignment:=taRightJustify; Width:=75; end; with Add do begin Caption:='Connected Time'; Alignment:=taLeftJustify; Width:=120; end; with Add do begin Caption:='Idle Time'; Alignment:=taLeftJustify; Width:=120; end; with Add do begin Caption:='Guest'; Alignment:=taLeftJustify; Width:=75; end; end; htMods: begin with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Version'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Size'; Alignment:=taRightJustify; Width:=75; end; with Add do begin Caption:='FileDate'; Alignment:=taLeftJustify; Width:=120; end; with Add do begin Caption:='Usage'; Alignment:=taRightJustify; Width:=50; end; with Add do begin Caption:='Manufacturer'; Alignment:=taLeftJustify; Width:=150; end; with Add do begin Caption:='Description'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Path'; Alignment:=taLeftJustify; Width:=200; end; end; htUsers: begin with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=150; end; with Add do begin Caption:='Full Name'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Comment'; Alignment:=taLeftJustify; Width:=400; end; end; htGroups: begin with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=150; end; with Add do begin Caption:='Comment'; Alignment:=taLeftJustify; Width:=500; end; end; htErrors: begin with Add do begin Caption:='Code'; Alignment:=taLeftJustify; Width:=60; end; with Add do begin Caption:='Message'; Alignment:=taLeftJustify; Width:=1000; end; end; htOpenFiles: begin with Add do begin Caption:='Open File'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Accessed By'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='# Locks'; Alignment:=taRightJustify; Width:=75; end; with Add do begin Caption:='Open Mode'; Alignment:=taLeftJustify; Width:=100; end; end; htJobs: begin with Add do begin Caption:='ID'; Alignment:=taLeftJustify; Width:=50; end; with Add do begin Caption:='Time'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Days of Month'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Days of Week'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Flags'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Command'; Alignment:=taLeftJustify; Width:=150; end; end; htWkstaTrans: begin with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Address'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Quality'; Alignment:=taRightJustify; Width:=50; end; with Add do begin Caption:='Number of clients'; Alignment:=taRightJustify; Width:=100; end; with Add do begin Caption:='WAN'; Alignment:=taLeftJustify; Width:=50; end; end; htSrvTrans: begin with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=200; end; with Add do begin Caption:='Domain'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Address'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Number of clients'; Alignment:=taRightJustify; Width:=100; end; end; htWkstaUsers: begin with Add do begin Caption:='Name'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Logon Domain'; Alignment:=taLeftJustify; Width:=100; end; with Add do begin Caption:='Logon Server'; Alignment:=taLeftJustify; Width:=100; end; end; end; EndUpdate; //AListView.LastColumnClicked:=0; end; end; function GetNodeChild(ANode: TTreeNode; AIndex: Integer): TTreeNode; var i: integer; begin i:=0; Result:=ANode.GetFirstChild; while Assigned(Result) and (i<>AIndex) do begin Result:=ANode.GetNextChild(Result); inc(i); end; end; procedure OpenTopic(ATreeView: TTreeView; AIndex: integer); begin with ATreeView do begin Selected:=GetNodeChild(Selected,AIndex); Selected.Expand(False); end; end; procedure TfrmMain.RefreshDrivers; var i: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htDrv); GetNTDriverList(DriverList); with AListView, Items do begin BeginUpdate; for i:=0 to DriverList.Count-1 do with Add do begin Caption:=PNTDriver(DriverList.Objects[i])^.Name; SubItems.Add(PNTDriver(DriverList.Objects[i])^.Description); SubItems.Add(PNTDriver(DriverList.Objects[i])^.Group); SubItems.Add(PNTDriver(DriverList.Objects[i])^.ImageName); SubItems.Add(PNTDriver(DriverList.Objects[i])^.szTyp); SubItems.Add(PNTDriver(DriverList.Objects[i])^.szStartUp); SubItems.Add(PNTDriver(DriverList.Objects[i])^.szStatus); SubItems.Add(PNTDriver(DriverList.Objects[i])^.szErrCtrl); {if PNTDriver(DriverList.Objects[i])^.AcceptPause then SubItems.Add('True') else SubItems.Add('False'); if PNTDriver(DriverList.Objects[i])^.AcceptStop then SubItems.Add('True') else SubItems.Add('False');} ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshPerformance; var i,j,k: integer; Root,Child: TTreeNode; szObj, szCtr: string; begin try Screen.Cursor:=crHourGlass; TreeTitle.Caption:=' Counters'; Splitter2.Visible:=IsNT; InstPanel.Visible:=IsNT; Splitter3.Show; ValPanel.Show; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; with ATreeView, Items do begin Images:=imgTree; OnChange:=tvChange; FullCollapse; BeginUpdate; Clear; if IsNT then begin if not Assigned(PLNT) then begin PLNT:=TPerfLibNT.Create; PLNT.Refresh; end else PLNT.TakeSnapshot; if Count=0 then for i:=0 to PLNT.ObjectCount-1 do begin Root:=Add(nil,PLNT.Objects[i].Name); Root.ImageIndex:=iiObject; Root.SelectedIndex:=Root.ImageIndex; for j:=0 to PLNT.Objects[i].CounterCount-1 do begin Child:=AddChild(Root,PLNT.Objects[i].Counters[j].Name); Child.ImageIndex:=iiCounter; Child.SelectedIndex:=Child.ImageIndex; end; end; end else begin if not Assigned(PL9x) and (Is98 or isME or (Is95 and IsOSR2)) then begin PL9x:=TPerfLib9x.Create; PL9x.Open; if Count=0 then for i:=PL9x.Names.Count-1 downto 0 do begin k:=Pos('\',PL9x.Names[i]); if k>0 then begin szObj:=copy(PL9x.Names[i],1,k-1); szCtr:=copy(PL9x.Names[i],k+1,255); end; Root:=GetFirstNode; while Assigned(Root) do if Root.Text=szObj then break else Root:=Root.GetNextSibling; if not Assigned(Root) then begin Root:=Add(nil,szObj); Root.ImageIndex:=iiObject; Root.SelectedIndex:=Root.ImageIndex; end; if szCtr<>'' then begin Child:=AddChild(Root,szCtr); Child.ImageIndex:=iiCounter; Child.SelectedIndex:=Child.ImageIndex; end; end; end; end; EndUpdate; end; finally SetDetail(Notebook,dtTree); Screen.Cursor:=crDefault; sb.Panels[0].Text:=Format('%d items',[ATreeView.Items.Count]); end; end; procedure TfrmMain.RefreshProcesses; var i: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htProc); if IsNT then begin if not Assigned(PLNT) then begin PLNT:=TPerfLibNT.Create; PLNT.Refresh; end else PLNT.TakeSnapShot; GetNTProcessList(PLNT,ProcessList); with AListView, Items do begin BeginUpdate; for i:=0 to ProcessList.Count-1 do with Add do begin Caption:=PNTProcess(ProcessList.objects[i])^.Name; SubItems.Add(IntToStr(PNTProcess(ProcessList.Objects[i])^.PID)); SubItems.Add(FormatSeconds(PNTProcess(ProcessList.Objects[i])^.CPUTime,true,false,true)); SubItems.Add(FormatFloat('0 K',PNTProcess(ProcessList.Objects[i])^.WorkingSetSize/1024)); SubItems.Add(IntToStr(PNTProcess(ProcessList.Objects[i])^.PriorityBase)); ImageIndex:=AImageIndex; end; EndUpdate; end; end else begin Get95ProcessList(ProcessList); with AListView, Items do begin BeginUpdate; for i:=0 to ProcessList.Count-1 do with Add do begin Caption:=P95Process(ProcessList.objects[i])^.Name; SubItems.Add(IntToHex(P95Process(ProcessList.Objects[i])^.PID,8)); SubItems.Add(Format('%d',[P95Process(ProcessList.Objects[i])^.Priority])); SubItems.Add(IntToStr(P95Process(ProcessList.Objects[i])^.Usage)); ImageIndex:=AImageIndex; end; EndUpdate; end; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshModules; var i,j: integer; n: TListItem; VIR: TVersionInfo; FI: TFileInfo; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htMods); if IsNT then begin if not Assigned(PLNT) then begin PLNT:=TPerfLibNT.Create; PLNT.Refresh; end else PLNT.TakeSnapShot; GetNTProcessList(PLNT,ProcessList); RefList.Clear; with AListView, Items do begin BeginUpdate; for i:=0 to ProcessList.Count-1 do begin GetNTProcessInfo(PNTProcess(ProcessList.objects[i])^,PLNT,PNTProcess(ProcessList.Objects[i])^.PID,True); for j:=0 to PNTProcess(ProcessList.objects[i])^.Modules.Count-1 do begin n:=FindCaption(0,LowerCase(PNTProcess(ProcessList.objects[i])^.Modules[j]),False,True,True); if Assigned(n) then begin n.SubItems[3]:=IntToStr(StrToInt(n.SubItems[3])+1); RefList[n.Index]:=RefList[n.Index]+(PNTProcess(ProcessList.objects[i])^.ImageName)+','; end else with Add, PNTModule(PNTProcess(ProcessList.objects[i])^.Modules.Objects[j])^ do begin RefList.Add(PNTProcess(ProcessList.objects[i])^.ImageName+','); Caption:=LowerCase(Name); GetFileVerInfo(ImageName,VIR); GetFileInfo(ImageName,fi); SubItems.Add(VIR.Version); SubItems.Add(Format('%d B',[fi.Size])); try SubItems.Add(DateTimeToStr(FileDateToDateTime(FileAge(ImageName)))); except end; SubItems.Add('1'); SubItems.Add(VIR.CompanyName); SubItems.Add(VIR.Description); SubItems.Add(LowerCase(ImageName)); ImageIndex:=AImageIndex; end; end; end; EndUpdate; end; end else begin Get95ProcessList(ProcessList); with AListView, Items do begin BeginUpdate; for i:=0 to ProcessList.Count-1 do begin P95Process(ProcessList.objects[i])^:=Get95ProcessInfo(P95Process(ProcessList.Objects[i])^.PID,True); for j:=0 to P95Process(ProcessList.objects[i])^.Modules.Count-1 do begin n:=FindCaption(0,LowerCase(P95Process(ProcessList.objects[i])^.Modules[j]),False,True,True); if Assigned(n) then begin n.SubItems[3]:=IntToStr(StrToInt(n.SubItems[3])+1); RefList[n.Index]:=RefList[n.Index]+(PNTProcess(ProcessList.objects[i])^.ImageName)+','; end else with Add, P95Module(P95Process(ProcessList.objects[i])^.Modules.Objects[j])^ do begin RefList.Add(PNTProcess(ProcessList.objects[i])^.ImageName+','); Caption:=LowerCase(Name); VIR.Filename:=ImageName; GetFileInfo(ImageName,fi); GetFileVerInfo(ImageName,VIR); SubItems.Add(VIR.Version); SubItems.Add(Format('%d B',[fi.Size])); try SubItems.Add(DateTimeToStr(FileDateToDateTime(FileAge(ImageName)))); except end; SubItems.Add('1'); SubItems.Add(VIR.CompanyName); SubItems.Add(VIR.Description); SubItems.Add(LowerCase(ImageName)); ImageIndex:=AImageIndex; end; end; end; EndUpdate; end; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshServices; var i: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htSrv); GetNTServiceList(Computer,ServiceList); with AListView, Items do begin BeginUpdate; for i:=0 to ServiceList.Count-1 do with Add do begin Caption:=PNTService(ServiceList.objects[i])^.DisplayName; SubItems.Add(PNTService(ServiceList.Objects[i])^.Name); SubItems.Add(PNTService(ServiceList.Objects[i])^.szStatus); SubItems.Add(PNTService(ServiceList.Objects[i])^.szStartUp); SubItems.Add(PNTService(ServiceList.Objects[i])^.ObjectName); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshEvents; var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htEvent); if not Assigned(EventLog) then EventLog:=TEventLog.Create; with AListView, Items, EventLog do begin LogType:=AType; Machine:=Computer; Refresh; n:=RecordCount; BeginUpdate; for i:=0 to n-1 do with Add,LogRecords[i]^ do begin Caption:=EventTypes[EventType]; Subitems.Add(DateTimeToStr(DateTime)); Subitems.Add(Source); if Category='' then SubItems.Add('None') else Subitems.Add(Category); Subitems.Add(Format('%d',[EventID])); if UserName='' then SubItems.Add('N/A') else Subitems.Add(Username); Subitems.Add(Computer); case EventType of MiTec_EventLogNT.etError: ImageIndex:=iiError; MiTec_EventLogNT.etWarning: ImageIndex:=iiWarning; MiTec_EventLogNT.etInformation: ImageIndex:=iiInfo; MiTec_EventLogNT.etAuditSuccess: ImageIndex:=iiAuditSucc; MiTec_EventLogNT.etAuditFailure: ImageIndex:=iiAuditFail; end; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshEnvironment; var sl: TStrings; begin sl:=TStringList.Create; try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htItem); GetEnvironment(sl); ListView_LoadStrings(sl,AListView.Items,'=',AImageIndex); finally sl.Free; Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshSysInfo; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htItem); with AListView, Items, SystemInfo do begin //Refresh; BeginUpdate; with Add do begin Caption:='Operating System'; SubItems.Add(Format('%s [%d.%d.%d]',[OSVersion, OS.MajorVersion, OS.MinorVersion, OS.BuildNumber])); ImageIndex:=iiOS; end; with Add do begin Caption:='Machine'; SubItems.Add(Machine.Name); ImageIndex:=iiWksta; end; with Add do begin Caption:='CPU'; SubItems.Add(format('%d x %s - %d MHz',[CPU.Count,CPU.VendorID,CPU.Frequency])); ImageIndex:=iiCPU; end; with Add do begin Caption:='Memory'; SubItems.Add(Format('%d MB (%d KB free)',[Memory.PhysicalTotal div 1024 div 1024,Memory.PhysicalFree div 1024])); ImageIndex:=iiMemory; end; with Add do begin Caption:='Disks'; SubItems.Add(Disk.AvailableDisks); ImageIndex:=iiDrives; end; with Add do begin Caption:='Sound adapter'; if Media.Devices.Count>0 then begin if Media.SoundCardIndex>-1 then SubItems.Add(Media.Devices[Media.SoundCardIndex]) else SubItems.Add(Media.Devices[0]); end else SubItems.Add('?'); ImageIndex:=iiMultiMedia; end; with Add do begin Caption:='Display adapter'; SubItems.Add(Format('%s (%d x %d - %d bit)',[Display.Adapter, Display.HorzRes, Display.VertRes, Display.ColorDepth])); ImageIndex:=iiDisplay; end; with Add do begin Caption:='Network adapter'; if Network.Adapters.Count>0 then begin if Network.CardAdapterIndex>-1 then SubItems.Add(Network.Adapters[Network.CardAdapterIndex]) else SubItems.Add(Network.Adapters[0]); end else SubItems.Add('?'); ImageIndex:=iiNetwork; end; with Add do begin Caption:='IP Address'; SubItems.Add(Format('%s',[Network.IPAddresses[0]])); if Network.MACAddresses.Count>0 then SubItems[0]:=SubItems[0]+Format(' (MAC Address: %s)',[Network.MACAddresses[0]]); ImageIndex:=iiNetwork; end; if Printers.Names.Count>0 then with Add do begin Caption:='Printer'; SubItems.Add(Format('%s on %s',[Printers.Names[Printers.DefaultIndex], Printers.Ports[Printers.DefaultIndex]])); ImageIndex:=iiPrinter; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshWindows; var wh :hwnd; root :ttreenode; pw :PWindow; procedure EnumChildWins(Awh :hwnd; ARoot :ttreenode); var node :ttreenode; begin while awh<>0 do begin pw:=getwindowinfo(awh); node:=ATreeView.items.addchild(aroot,'Window '+inttohex(pw^.handle,8)+' "'+pw^.text+'" :'+pw^.classname); node.imageindex:=integer(pw^.visible); node.SelectedIndex:=node.imageindex; winlist.addobject(inttohex(pw^.Handle,8),@pw^); enumchildwins(getwindow(awh,GW_CHILD),node); awh:=getwindow(awh,GW_HWNDNEXT); end; end; begin try Screen.Cursor:=crHourGlass; TreeTitle.Caption:=' Windows'; Splitter2.Hide; InstPanel.Hide; ValPanel.Hide; Splitter3.Hide; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; with ATreeView, Items do begin Images:=imgTree; OnChange:=nil; FullCollapse; BeginUpdate; Clear; FreeWindowList(WinList); wh:=GetDesktopWindow; pw:=GetWindowInfo(wh); WinList.AddObject(IntToHex(pw^.Handle,8),@pw^); Root:=Add(nil,'Window '+inttohex(pw^.handle,8)+' "'+pw^.text+'" :'+pw^.classname); Root.ImageIndex:=integer(pw^.visible); Root.SelectedIndex:=Root.ImageIndex; EnumChildWins(GetWindow(wh,GW_CHILD),Root); EndUpdate; if Assigned(Items[0]) then Items[0].Expand(False); end; finally SetDetail(Notebook,dtTree); Screen.Cursor:=crDefault; sb.Panels[0].Text:=Format('%d items',[ATreeView.Items.Count]); end; end; procedure TfrmMain.RefreshShares; var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htShare); if IsNT then begin if not Assigned(ShareNT) then ShareNT:=TNTShares.Create; with AListView, Items, ShareNT do begin Machine:=Computer; RefreshShares; n:=ShareCount; BeginUpdate; for i:=0 to n-1 do with Add, Shares[i]^ do begin Caption:=Name; Subitems.Add(Path); Subitems.Add(ShareTypes[ShareType]); Subitems.Add(BoolToStr(SecurityDesc,True)); if MaxUserCount=uint(-1) then SubItems.Add('Unlimited') else Subitems.Add(Format('%d',[MaxUserCount])); Subitems.Add(Format('%d',[CurUserCount])); Subitems.Add(GetPermissionStr(Permissions)); Subitems.Add(Comment); ImageIndex:=AImageIndex; end; EndUpdate; end; end else begin if not Assigned(Share9x) then Share9x:=T9xShares.Create; with AListView, Items, Share9x do begin RefreshShares; n:=ShareCount; BeginUpdate; for i:=0 to n-1 do with Add, Shares[i]^ do begin Caption:=Name; Subitems.Add(Path); Subitems.Add(ShareTypes[ShareType]); Subitems.Add('Not Available'); Subitems.Add('Not Available'); Subitems.Add('Not Available'); Subitems.Add('Not Available'); Subitems.Add(Comment); ImageIndex:=AImageIndex; end; EndUpdate; end; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshSessions; var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htSession); if IsNT then begin if not Assigned(ShareNT) then ShareNT:=TNTShares.Create; with AListView, Items, ShareNT do begin Machine:=Computer; RefreshSessions; n:=SessionCount; BeginUpdate; for i:=0 to n-1 do with Add, Sessions[i]^ do begin Caption:=Name; SubItems.Add(UserName); SubItems.Add(SesiType); SubItems.Add(Format('%d',[OpenFiles])); SubItems.Add(FormatSeconds(ConnectedTime,True,False,True)); SubItems.Add(FormatSeconds(IdleTime,True,False,True)); SubItems.Add(BoolToStr(Guest,True)); ImageIndex:=AImageIndex; end; EndUpdate; end; end else begin if not Assigned(Share9x) then Share9x:=T9xShares.Create; with AListView, Items, Share9x do begin RefreshSessions; n:=SessionCount; BeginUpdate; for i:=0 to n-1 do with Add, Sessions[i]^ do begin Caption:='Not Available'; SubItems.Add(Name); SubItems.Add('Not Available'); SubItems.Add('Not Available'); SubItems.Add('Not Available'); SubItems.Add('Not Available'); SubItems.Add('Not Available'); ImageIndex:=AImageIndex; end; EndUpdate; end; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshOpenFiles; var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htOpenFiles); if IsNT then begin if not Assigned(ShareNT) then ShareNT:=TNTShares.Create; with AListView, Items, ShareNT do begin Machine:=Computer; RefreshOpenFiles; n:=OpenFileCount; BeginUpdate; for i:=0 to n-1 do with Add, OpenFiles[i]^ do begin Caption:=Name; SubItems.Add(UserName); SubItems.Add(Format('%d',[Locks])); case Mode of pmRead: SubItems.Add('Read Only'); pmWrite: SubItems.Add('Write'); pmCreate: SubItems.Add('Create'); end; ImageIndex:=AImageIndex; end; EndUpdate; end; end else begin if not Assigned(Share9x) then Share9x:=T9xShares.Create; with AListView, Items, Share9x do begin RefreshOpenFiles; n:=OpenFileCount; BeginUpdate; for i:=0 to n-1 do with Add, OpenFiles[i]^ do begin Caption:=Name; ImageIndex:=AImageIndex; end; EndUpdate; end; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshGroups; var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htGroups); if not Assigned(Accounts) then Accounts:=TAccounts.Create; Accounts.Machine:=Computer; Accounts.RefreshLocalGroups; n:=Accounts.LocalGroupCount; with AListView, Items do begin BeginUpdate; for i:=0 to n-1 do with Add, Accounts.LocalGroups[i]^ do begin Caption:=Name; SubItems.Add(Comment); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshUsers; var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htUsers); if not Assigned(Accounts) then Accounts:=TAccounts.Create; Accounts.Machine:=Computer; Accounts.RefreshUsers; n:=Accounts.UserCount; with AListView, Items do begin BeginUpdate; for i:=0 to n-1 do with Add, Accounts.Users[i]^ do begin Caption:=Name; SubItems.Add(Fullname); SubItems.Add(Comment); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshErrors; const BUFFER_SIZE = 1024; var lpMsgBuf: Pchar; LangID: DWORD; i: integer; s: string; begin try Screen.Cursor:=crHourGlass; SetHeader(AListView,htErrors); lpMsgBuf:=AllocMem(BUFFER_SIZE); if IsNT then LangID:=$409 else LangID:=GetUserDefaultLangID; s:=''; with AListView, Items do begin BeginUpdate; for i:=0 to 12000 do begin FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_IGNORE_INSERTS, nil,i,LangID,lpMsgBuf,BUFFER_SIZE,nil); if StrPas(lpMsgBuf)<>s then with Add do begin Caption:=Format('%0.5d',[i]); SubItems.Add(StringReplace(StrPas(lpMsgBuf),#13#10,' ',[rfReplaceAll,rfIgnoreCase])); ImageIndex:=AImageIndex; end; s:=StrPas(lpMsgBuf); end; EndUpdate; end; finally if Assigned(lpMsgBuf) then FreeMem(lpMsgBuf); Screen.Cursor:=crDefault; end; end; procedure TfrmMain.FormCreate(Sender: TObject); begin Computer:=MachineName; ServerList:=TStringList.Create; RefList:=TStringList.Create; ProcessList:=TStringList.Create; ServiceList:=TStringList.Create; DriverList:=TStringList.Create; WinList:=TStringList.Create; RefreshServers; SystemInfo.Refresh; if IsNT then mmNet.Tag:=6; end; procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction); begin RefList.Free; FreeNTServiceList(ServiceList); ServiceList.Free; FreeNTDriverList(DriverList); DriverList.Free; WinList.Free; FreeServerList(ServerList); ServerList.Free; if Assigned(PLNT) then begin PLNT.Free; FreeNTProcessList(ProcessList); end; if Assigned(PL9x) then begin PL9x.Close; PL9x.Free; Free95ProcessList(ProcessList); end; ProcessList.Free; end; procedure TfrmMain.TreeChange(Sender: TObject; Node: TTreeNode); var n: TTreeNode; begin cmAction(nil); if Node.Count>0 then begin lv.PopupMenu:=nil; SetDetail(Notebook,dtList); SetHeader(lv,htTopic); with lv, Items do begin n:=Node.GetFirstChild; repeat with Add do begin Caption:=n.Text; ImageIndex:=n.ImageIndex; end; n:=Node.GetNextChild(n); until not Assigned(n); end; sb.Panels[0].Text:=Format('%d topics',[Node.Count]); end else begin lv.PopupMenu:=PopupMenu; case Node.ImageIndex of iiApplication: RefreshEvents(lv,Node.ImageIndex,elApplication); iiSecurity: RefreshEvents(lv,Node.ImageIndex,elSecurity); iiSystem: RefreshEvents(lv,Node.ImageIndex,elSystem); iiSystemInfo: RefreshSysInfo(lv); iiEnvVar: RefreshEnvironment(lv,Node.ImageIndex); iiRunningTasks: RefreshProcesses(lv,Node.ImageIndex); iiModules: RefreshModules(lv,Node.ImageIndex); iiServices: RefreshServices(lv,Node.ImageIndex); iiDrivers: RefreshDrivers(lv,Node.ImageIndex); iiPerformance: RefreshPerformance(tv); iiWindows: RefreshWindows(tv); iiShares: RefreshShares(lv,Node.ImageIndex); iiSessions: RefreshSessions(lv,Node.ImageIndex); iiOpenFiles: RefreshOpenFiles(lv,Node.ImageIndex); iiUsers: RefreshUsers(lv,Node.ImageIndex); iiGroups: RefreshGroups(lv,Node.ImageIndex); iiGlobalGroups: RefreshGlobalGroups(lv,Node.ImageIndex); iiScheduler: RefreshJobs(lv,iiTask); iiWkstaTrans: RefreshWkstaTrans(lv,iiWkstaTrans); iiWkstaUsers: RefreshWkstaUsers(lv,iiWkstaUsers); iiWkstaInfo: RefreshWkstaInfo(lv,iiWkstaInfo); iiDevices: RefreshDevices(tv); end; end; end; procedure TfrmMain.cmClose(Sender: TObject); begin Close; end; procedure TfrmMain.tvChange(Sender: TObject; Node: TTreeNode); var i,oi,ci: integer; begin if Assigned(Node) then begin if Tree.Selected.ImageIndex=iiPerformance then begin lbInst.Items.BeginUpdate; lbInst.Items.Clear; lbVal.Items.BeginUpdate; lbVal.Items.Clear; try try if IsNT then begin if Assigned(Node.Parent) then oi:=PLNT.GetIndexByName(Node.Parent.Text) else oi:=PLNT.GetIndexByName(Node.Text); if PLNT.Objects[oi].InstanceCount>0 then for i:=0 to PLNT.Objects[oi].InstanceCount-1 do lbInst.Items.Add(PLNT.Objects[oi].Instances[i].Name); if Assigned(Node.Parent) then begin ci:=PLNT.Objects[oi].GetCntrIndexByName(Node.Text); i:=0; repeat lbVal.Items.Add(PLNT.Objects[oi].Counters[ci].DataStrEx[i]); Inc(i); until i>PLNT.Objects[oi].InstanceCount-1; end; end else begin if Assigned(Node.Parent) then lbVal.Items.Add(Format('%d',[PL9x.SysData[Node.Parent.Text+'\'+Node.Text]])); end; except end; finally lbVal.Items.EndUpdate; lbInst.Items.EndUpdate; end; end; end; end; procedure TfrmMain.ShowProps(AType: TPropertyType; AParameter: Variant); var po: TPerfObject; pd: PDevice; p: PChar; begin p:=nil; with TdlgProperties.Create(Self) do begin PropertyType:=AType; case AType of ptProcess: Parameter:=ProcessList.Objects[ProcessList.IndexOf(AParameter)]; ptService: Parameter:=ServiceList.Objects[ServiceList.IndexOf(AParameter)]; ptPerf: if IsNT then begin if VarIsArray(AParameter) then begin po:=PLNT.Objects[PLNT.GetIndexByName(AParameter[1])]; Parameter:=po.Counters[po.GetCntrIndexByName(AParameter[0])]; end else begin Parameter:=PLNT.Objects[PLNT.GetIndexByName(AParameter)] end; end else begin p:=AllocMem(255); if VarIsArray(AParameter) then begin strpcopy(p,AParameter[1]+'\'+AParameter[0]); Parameter:=TObject(p); end else begin strpcopy(p,AParameter); Parameter:=TObject(p); end; end; ptWindow: Parameter:=WinList.Objects[AParameter]; ptLog: Parameter:=TObject(EventLog.LogRecords[AParameter]); ptShare: Parameter:=TObject(ShareNT.Shares[AParameter]); ptDevice: begin new(pd); pd^:=SystemInfo.Devices.Devices[AParameter]; Parameter:=TObject(pd); end; ptUser, ptGroup, ptGlobalGroup: begin Parameter:=Accounts; Idx:=AParameter; end; end; PerfLibNT:=PLNT; PerfLib9x:=PL9x; ShowModal; if Assigned(pd) then dispose(pd); if Assigned(p) then FreeMem(p); Free; end; end; procedure TfrmMain.lvDblClick(Sender: TObject); begin if Assigned(lv.Selected) then begin if lv.ViewStyle=vsReport then begin if (Tree.Selected.ImageIndex=lv.Selected.ImageIndex) or (Tree.Selected.ImageIndex=iiSystemInfo) or (lv.Selected.ImageIndex in [iiError..iiAuditFail]) then begin case lv.Selected.ImageIndex of iiEventViewer, iiCompInfo, iiSoftware: OpenTopic(Tree,lv.Selected.Index); iiError, iiWarning, iiInfo, iiAuditSucc, iiAuditFail: ShowProps(ptLog,lv.Selected.Index); iiSystemInfo: RefreshSysInfo(lv); iiWksta: ShowSIProps([pgWksta,pgAPM]); iiOS: ShowSIProps([pgOS,pgEng,pgTZ,pgStartup,pgSoftware]); iiMemory: ShowSIProps([pgMem]); iiDrives: ShowSIProps([pgDisk]); iiNetwork: ShowSIProps([pgNet]); iiMultimedia: ShowSIProps([pgMedia]); iiDisplay: ShowSIProps([pgDisplay]); iiCPU: ShowSIProps([pgCPU]); iiPrinter: ShowSIProps([pgPrn]); iiRunningTasks: ShowProps(ptProcess,lv.Selected.SubItems[0]); iiServices: ShowProps(ptService,lv.Selected.SubItems[0]); iiUsers: ShowProps(ptUser,lv.Selected.index); iiGroups: ShowProps(ptGroup,lv.Selected.index); iiGlobalGroups: ShowProps(ptGlobalGroup,lv.Selected.index); iiShares: if IsNT then ShowProps(ptShare,lv.Selected.Index); iiModules: DisplayPropDialog(Handle,lv.Selected.SubItems[6]); end; end else OpenTopic(Tree,lv.Selected.Index); end else ShellExecute(Application.Handle,'open','rundll32.exe', PChar(ControlPanelRun[lv.Selected.ImageIndex]),nil,SW_NORMAL); end; end; procedure TfrmMain.tvDblClick(Sender: TObject); begin if Assigned(tv.Selected) and assigned(Tree.Selected) then case Tree.Selected.ImageIndex of iiPerformance: if Assigned(tv.Selected.Parent) then ShowProps(ptPerf,VarArrayOf([tv.Selected.Text,tv.Selected.Parent.Text])) else ShowProps(ptPerf,tv.Selected.Text); iiWindows: ShowProps(ptWindow,tv.Selected.AbsoluteIndex); iiDevices: if tv.Selected.Level=2 then ShowProps(ptDevice,PInteger(tv.Selected.Data)^); end; end; procedure TfrmMain.ShowSIProps(AType: TPages); begin with TfrmMSI_Overview.Create(Self) do begin ShowReportButton:=false; SysInfo:=SystemInfo; DisplayedPages:=AType; cmRefresh(nil); ShowModal; Free; end; end; procedure TfrmMain.TreeMenuPopup(Sender: TObject); begin pmRefresh.Enabled:=Assigned(Tree.Selected) and not(Tree.Selected.ImageIndex in [iiEventViewer,iiCompInfo,iiAccounts,iiSharedFolders, iiSoftware]); pmSaveRep.Enabled:=pmRefresh.Enabled; end; procedure TfrmMain.TreeViewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var n :ttreenode; begin n:=ttreeview(sender).getnodeat(x,y); if assigned(n) then ttreeview(sender).selected:=n; end; procedure TfrmMain.cmAbout(Sender: TObject); begin ShellAbout(Handle,PChar(Application.Title),PChar(SystemInfo.About),Application.Icon.Handle); end; procedure TfrmMain.CloseOpenFile(AID: DWORD); var n: DWORD; Buf: array[0..256] of WideChar; begin if MessageDlg('Close file?',mtConfirmation,[mbyes,mbNo],0)=mryes then begin n:=NetFileClose(StringToWideChar(Computer,Buf,256),AID); if n<>ERROR_SUCCESS then raise Exception.Create(GetErrorMessage(n)) else RefreshOpenFiles(lv,iiOpenFiles); end; end; procedure TfrmMain.CloseSession(AName, AUsername: string); var n: DWORD; Buf1, Buf2,Buf3: array[0..256] of WideChar; begin if MessageDlg('Close session?',mtConfirmation,[mbyes,mbNo],0)=mryes then begin n:=NetSessionDel(StringToWideChar(Computer,Buf1,256), StringToWideChar('\\'+AName,Buf2,256), StringToWideChar(AUserName,Buf3,256)); if n<>ERROR_SUCCESS then raise Exception.Create(GetErrorMessage(n)) else RefreshSessions(lv,iiSessions); end; end; procedure TfrmMain.cmRefresh(Sender: TObject); begin TreeChange(Tree,Tree.Selected); end; procedure TfrmMain.PopupMenuPopup(Sender: TObject); begin if ActiveControl=lv then begin pmProps.Enabled:=Assigned(lv.Selected); if IsNT then pmProps.Visible:=Assigned(lv.Selected) and not(lv.Selected.ImageIndex in [iiDrivers,iiEnvVar,iiSessions,iiOpenFiles,iiTask,iiWkstaTrans,iiWkstaUsers,iiWkstaInfo]) else pmProps.Visible:=Assigned(lv.Selected) and not(lv.Selected.ImageIndex in [iiDrivers,iiEnvVar,iiSessions,iiOpenFiles,iiShares,iiTask,iiWkstaTrans,iiWkstaUsers,iiWkstaInfo]); pmRefs.Visible:=Assigned(lv.Selected) and (lv.Selected.ImageIndex in [iiModules]); pmClose.Enabled:=Assigned(lv.Selected); pmClose.Visible:=IsNT and Assigned(lv.Selected) and (lv.Selected.ImageIndex in [iiSessions,iiOpenFiles]); pmDelete.Enabled:=Assigned(lv.Selected); pmDelete.Visible:=IsNT and Assigned(lv.Selected) and (lv.Selected.ImageIndex in [iiTask]); pmSave.Enabled:=Assigned(lv.Selected); pmSave.Visible:=Assigned(lv.Selected) and (lv.ViewStyle<>vsIcon); end else if ActiveControl=tv then begin pmClose.Visible:=False; pmProps.Enabled:=Assigned(tv.Selected); pmProps.Visible:=Assigned(tv.Selected); if pmProps.Visible and (Tree.Selected.ImageIndex=iiDevices) and (tv.selected.Level<>2) then pmProps.Visible:=False; pmSave.Enabled:=Assigned(tv.Selected); pmRefs.Visible:=False; pmDelete.Visible:=False; pmSave.Visible:=True; end; end; procedure TfrmMain.cmProps(Sender: TObject); begin if ActiveControl=lv then begin lvDblClick(nil); end else if ActiveControl=tv then begin tvDblClick(nil); end; end; procedure TfrmMain.cmCloseItem(Sender: TObject); begin case lv.Selected.ImageIndex of iiOpenFiles: CloseOpenFile(ShareNT.OpenFiles[lv.Selected.Index]^.ID); iiSessions: if IsNT then CloseSession(ShareNT.Sessions[lv.Selected.Index]^.Name,ShareNT.Sessions[lv.Selected.Index]^.UserName); end; end; procedure TfrmMain.cmSave(Sender: TObject); begin MessageDlg('Not implemented yet.',mtInformation,[mbOK],0); end; procedure TfrmMain.cmRefs(Sender: TObject); begin ShowRefsDlg(lv.Selected.Caption,RefList[lv.Selected.Index]); end; procedure TfrmMain.RefreshJobs(AListView: TListViewClass; AImageIndex: integer); var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htJobs); if not Assigned(JobNT) then JobNT:=TNTJobs.Create; with AListView, Items, JobNT do begin Machine:=Computer; Refresh; n:=JobCount; BeginUpdate; for i:=0 to n-1 do with Add, Jobs[i]^ do begin Caption:=Format('0x%x',[ID]); SubItems.Add(TimeToStr(JobTime)); SubItems.Add(DaysOfMonth.CommaText); SubItems.Add(DaysOfWeek.CommaText); SubItems.Add(GetJobFlagsStr(Flags)); SubItems.Add(Command); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.cmDelete(Sender: TObject); begin DeleteJob(JobNT.Jobs[lv.Selected.Index]^.ID); end; procedure TfrmMain.DeleteJob(AID: DWORD); var n: DWORD; Buf: array[0..256] of WideChar; begin if MessageDlg('Delete task?',mtConfirmation,[mbyes,mbNo],0)=mryes then begin n:=NetScheduleJobDel(StringToWideChar(Computer,Buf,256),AID,AID); if n<>ERROR_SUCCESS then raise Exception.Create(GetErrorMessage(n)) else RefreshJobs(lv,iiTask); end; end; procedure TfrmMain.cmCP(Sender: TObject); begin ShellExecute(Application.Handle,'open','rundll32.exe', PChar(ControlPanelRun[TComponent(sender).Tag]),nil,SW_NORMAL); end; procedure TfrmMain.FreeWindowList(AList: TStringList); var pw: PWindow; begin while AList.count>0 do begin pw:=PWindow(AList.Objects[AList.Count-1]); Dispose(pw); AList.Delete(AList.Count-1); end; end; procedure TfrmMain.Refresh; begin SetTopics(Tree,(Pos(MachineName,Computer)>0)); SetDetail(Notebook,dtDefault); try Tree.Selected:=Tree.Items[0]; TreeChange(Tree,Tree.Selected); cmAction(nil); except end; end; procedure TfrmMain.RefreshWkstaTrans(AListView: TListViewClass; AImageIndex: integer); var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htWkstaTrans); if not Assigned(Wksta) then Wksta:=TNTWksta.Create; with AListView, Items, Wksta do begin Machine:=Computer; RefreshTrans; n:=TransportCount; BeginUpdate; for i:=0 to n-1 do with Add, Transports[i]^ do begin Caption:=Name; SubItems.Add(Address); SubItems.Add(IntToStr(Quality)); SubItems.Add(IntToStr(VCSCount)); if IsWAN then SubItems.Add('Yes') else SubItems.Add('No'); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshWkstaUsers(AListView: TListViewClass; AImageIndex: integer); var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htWkstaUsers); if not Assigned(Wksta) then Wksta:=TNTWksta.Create; with AListView, Items, Wksta do begin Machine:=Computer; RefreshUsers; n:=UserCount; BeginUpdate; for i:=0 to n-1 do with Add, Users[i]^ do begin Caption:=Name; SubItems.Add(Domain); SubItems.Add(Server); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshGlobalGroups(AListView: TListViewClass; AImageIndex: Integer); var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htGroups); if not Assigned(Accounts) then Accounts:=TAccounts.Create; Accounts.Machine:=Computer; Accounts.RefreshGlobalGroups; n:=Accounts.GlobalGroupCount; with AListView, Items do begin BeginUpdate; for i:=0 to n-1 do with Add, Accounts.GlobalGroups[i]^ do begin Caption:=Name; SubItems.Add(Comment); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshServers; begin {if IsNT then begin GetServerList(SV_TYPE_ALL,'',ServerList); cbMachine.Items.Clear; for i:=0 to ServerList.Count-1 do cbMachine.Items.Add(ServerList[i]);//+' ('+GetServerTypeStr(PServer(ServerList.Objects[i])^.ServerType)+')'); end; cbMachine.ItemIndex:=cbMachine.Items.IndexOf(MachineName);} FSingleMachine:=(ServerList.Count=0); Refresh; end; procedure TfrmMain.RefreshWkstaInfo; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htItem); if not Assigned(Wksta) then Wksta:=TNTWksta.Create; Wksta.Machine:=Computer; Wksta.RefreshInfo; with AListView, Items do begin BeginUpdate; with Add, Wksta do begin Caption:='Name'; SubItems.Add(Computername); ImageIndex:=AImageIndex; end; with Add, Wksta do begin Caption:='Domain'; SubItems.Add(DomainName); ImageIndex:=AImageIndex; end; with Add, Wksta do begin Caption:='PlatformId'; SubItems.Add(IntToStr(PlatformId)); ImageIndex:=AImageIndex; end; with Add, Wksta do begin Caption:='Platform Version'; SubItems.Add(Format('%d.%d',[MajorVersion,MinorVersion])); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshServerTrans(AListView: TListViewClass; AImageIndex: integer); var i,n: integer; begin try Screen.Cursor:=crHourGlass; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; SetHeader(AListView,htSrvTrans); if not Assigned(Server) then Server:=TNTServer.Create; with AListView, Items, Server do begin Machine:=Computer; RefreshTrans; n:=TransportCount; BeginUpdate; for i:=0 to n-1 do with Add, Transports[i]^ do begin Caption:=Name; SubItems.Add(Domain); SubItems.Add(NetAddress+' ('+IntToStr(Address)+')'); SubItems.Add(IntToStr(VCSCount)); ImageIndex:=AImageIndex; end; EndUpdate; end; finally Screen.Cursor:=crDefault; SetDetail(Notebook,dtList); sb.Panels[0].Text:=Format('%d items',[AListView.Items.Count]); end; end; procedure TfrmMain.RefreshDevices(ATreeView: TTreeView); var i,c: integer; r,n: TTreeNode; cn,dn: string; pi: PInteger; ldc: TDeviceClass; begin try Screen.Cursor:=crHourGlass; TreeTitle.Caption:=' Device Manager'; Splitter2.Hide; InstPanel.Hide; ValPanel.Hide; Splitter3.Hide; SetDetail(Notebook,dtDefault); sb.Panels[0].Text:=''; Update; with SystemInfo,Devices, ATreeView,Items do begin GetInfo; Images:=imgDevices; c:=DeviceCount-1; BeginUpdate; Clear; r:=Add(nil,GetMachine); r.ImageIndex:=0; r.SelectedIndex:=r.ImageIndex; n:=nil; for i:=0 to c do begin if Trim(Devices[i].ClassDesc)<>'' then cn:=Devices[i].ClassDesc else cn:=Devices[i].ClassName; if not Assigned(n) or (Devices[i].DeviceClass<>ldc) then begin ldc:=Devices[i].DeviceClass; n:=AddChild(r,cn); n.ImageIndex:=integer(Devices[i].DeviceClass)+1; n.SelectedIndex:=n.ImageIndex; end; if Trim(Devices[i].FriendlyName)='' then dn:=Devices[i].Description else dn:=Devices[i].FriendlyName; with AddChild(n,dn) do begin ImageIndex:=n.ImageIndex; SelectedIndex:=ImageIndex; new(pi); pi^:=i; Data:=pi; end; n.AlphaSort; end; r.AlphaSort; r.Expand(False); EndUpdate; end; finally SetDetail(Notebook,dtTree); Screen.Cursor:=crDefault; sb.Panels[0].Text:=Format('%d items',[ATreeView.Items.Count]); end; end; procedure TfrmMain.cmAction(Sender: TObject); begin mmProps.Enabled:=Assigned(lv.Selected); if IsNT then mmProps.Visible:=Assigned(lv.Selected) and not(lv.Selected.ImageIndex in [iiDrivers,iiEnvVar,iiSessions,iiOpenFiles,iiTask,iiWkstaTrans,iiWkstaUsers,iiWkstaInfo]) else mmProps.Visible:=Assigned(lv.Selected) and not(lv.Selected.ImageIndex in [iiDrivers,iiEnvVar,iiSessions,iiOpenFiles,iiShares,iiTask,iiWkstaTrans,iiWkstaUsers,iiWkstaInfo]); mmRefs.Visible:=Assigned(lv.Selected) and (lv.Selected.ImageIndex in [iiModules]); mmCloseItem.Enabled:=Assigned(lv.Selected); mmCloseItem.Visible:=IsNT and Assigned(lv.Selected) and (lv.Selected.ImageIndex in [iiSessions,iiOpenFiles]); mmDelete.Enabled:=Assigned(lv.Selected); mmDelete.Visible:=IsNT and Assigned(lv.Selected) and (lv.Selected.ImageIndex in [iiTask]); mmSave.Enabled:=Assigned(lv.Selected); mmSave.Visible:=Assigned(lv.Selected) and (lv.ViewStyle<>vsIcon); end; procedure TfrmMain.lvChange(Sender: TObject; Item: TListItem; Change: TItemChange); begin cmAction(nil); end; procedure TfrmMain.mmSIClick(Sender: TObject); begin SystemInfo.ShowModalOverviewWithAbout; end; end.