Jump to content

JohnLM

Members
  • Content Count

    222
  • Joined

  • Last visited

Community Reputation

11 Good

Technical Information

  • Delphi-Version
    Delphi 11 Alexandria

Recent Profile Visitors

22857 profile views
  1. JohnLM

    Trying to end a process but failing

    Success!! It is working. Serv LN Time in/out PID Action ------------- -- ----------- ---- ------ rundll32.exe 45 12:00:02 AM 6460 killed Now it is time to make some enhancements and add a custom running db list of items to keep track of that come up during the day and review for potential Action.
  2. JohnLM

    Trying to end a process but failing

    Thanks for the responses. Okay, I believe I have found out why my app was failing at closing the "rundll32.exe" (and other running processes). I did not run the app as Admin. I know a few processes that show up in Task Manager and come back again after ending those tasks. For instance, the "HeciServer.exe - Intel(R) Capability Licensing Service Interface" will not close. I know because it has the same ProcesID (PID) but if I run the app as Admin, it closes and relaunches again but with a new PID. In my app I have it so that it shows the PID for each app listed and slated for shutting down via one of the end process funtions I listed in my first post. But I have not tested it on the rundll32.exe yet. I have to wait until it decides to start. I'll know then if the app works for this particular file and report back about it later.
  3. Specs: Delphi XE7, Windows 7 64bit laptop. There is a "rundll32.exe" that keeps running every day. Now, I know that this is used in various ways during regular Windows operations, like for instance, when you open the sound volumn applet (via taskbar icon) and select the speaker icon, the "rundll32" activates and runs services. The service is running a HDD file collection activity because my HDD light is on continuously. And after searching around the web for answers, I found many Delphi routines that end or kill a process by program name and process_id. I am using the PID to be more accurate. Then, I wrote an app to detect when this file or service runs and End or Kill its process via its PID, but the process does not end. I think I've tried all the methods that I found and still, this "rundll32.exe" file will not stop running. I am pretty sure that this is a backgroud (scheduled) task that can be turned off somewhere in "services.msc" but that method is not what I want to use in this case. This endeviour has stumped me and I want to figure it out in the route I am in now. Any advice or suggestions or code corrections on how to proceed would be greatly appreciated. function KillProcessTree(const PID: Cardinal): boolean; var hProc, hSnap, hChildProc : THandle; pe : TProcessEntry32; bCont : BOOL; begin Result := true; FillChar(pe, SizeOf(pe), #0); pe.dwSize := SizeOf(pe); hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnap <> INVALID_HANDLE_VALUE) then begin if (Process32First(hSnap, pe)) then begin hProc := OpenProcess(PROCESS_TERMINATE{PROCESS_ALL_ACCESS}, false, PID); if (hProc <> 0) then begin Result := Result and TerminateProcess(hProc, 1); WaitForSingleObject(hProc, INFINITE); CloseHandle(hProc); end; bCont := true; while bCont do begin if (pe.th32ParentProcessID = PID) then begin KillProcessTree(pe.th32ProcessID); hChildProc := OpenProcess(PROCESS_TERMINATE{PROCESS_ALL_ACCESS}, FALSE, pe.th32ProcessID); if (hChildProc <> 0) then begin Result := Result and TerminateProcess(hChildProc, 1); WaitForSingleObject(hChildProc, INFINITE); CloseHandle(hChildProc); end; end; bCont := Process32Next(hSnap, pe); end; end; CloseHandle(hSnap); end; end; and. . . function Killtask2(exefilename: string): integer; Const process_terminate = $0001; Var Continueloop: Bool; Fsnapshothandle: THandle; fprocessentry32: TProcessentry32; Begin Result := 0; Fsnapshothandle := CreateToolhelp32Snapshot (Th32cs_snapprocess, 0); FProcessEntry32.dwsize := Sizeof(FPROCESSENTRY32); Continueloop := Process32First (Fsnapshothandle, FPROCESSENTRY32); while integer (continueloop) <> 0 do begin if (Uppercase(Extractfilename (FProcessEntry32. szexefile)) = Uppercase(Exefilename)) or (Uppercase(FProcessEntry32. Szexefile) = Uppercase(Exefilename)) then Result := Integer(TerminateProcess(OpenProcess(Process_terminate, BOOL (0), FProcessEntry32. Th32processid), 0)); Continueloop := Process32Next(Fsnapshothandle, FPROCESSENTRY32); end; CloseHandle(Fsnapshothandle); End; and this one. . . function KillTask(ExeFileName: string): Integer; const PROCESS_TERMINATE = $0001; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin Result := 0; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessEntry32.dwSize := SizeOf(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32); while Integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then Result := Integer(TerminateProcess( OpenProcess(PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0)); ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32); end; CloseHandle(FSnapshotHandle); end;
  4. I played around with the routine from James Campbell's (Feb 6, 2020) answer from @Lars Fosdal's posted link, and posted again, below. https://stackoverflow.com/questions/2212823/how-to-detect-inactive-user Note: To make testing/debugging easier, I made this change: FormStyle=fsStayOnTop in the Object Inspector area so that I could better observe the app's behavior. And, while the app does work as expected, when I minimize the app and go into another running app or use keyboard/mouse activity outside the said app, it would continue to work--that is, in the timer section it would continue. I modified the code to: detect the app's active status and check if it is minimized. procedure TForm1.Timer1Timer(Sender: TObject); begin if (application.Active=true) and (WindowState = wsMinimized) then else if application.Active=true then begin Caption := Format('System IDLE last %d seconds', [SecondsIdle]) ; end; end; And now it seems to work as expected when it is minimized the counting in the timer event is ignored, and if the app is active in the foreground, the counting continues.
  5. @Anders Melander and @Remy Lebeau - Thank you for the tips.
  6. This works for me in XE7. type FileSig = record Offset: Integer; text: string; arrSig: array of byte; arrStr: array of char; end; const sig1: FileSig = ( offset:10; text:'test'; arrsig:[65,66,67]; arrStr:['a','b','c'] ); var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin memo1.Lines.Add(sig1.Offset.ToString()); memo1.Lines.Add(sig1.text); memo1.Lines.Add( inttostr(sig1.arrSig[0]) ); memo1.Lines.Add('[' + ansistring(sig1.arrSig) + ']'); memo1.Lines.Add('[' + string(sig1.arrStr) +']'); end; Output Results: 10 test 65 [ABC] [abc]
  7. I have this routine that lists all running processes in a listbox under Windows 7. However, it is not a complete list as I thought, because when I load up the Task Manager, it has more entries (when I select '[y] show processes from all users'). Here is a complete project listing showing two working methods to obtain the running processes into a listbox. The only limitations with these are that they show less entries than what the Task Manager shows. Question: How do I obtain that same listing in delphi that the Task Manager shows? TIA. unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls; type TForm1 = class(TForm) Panel1: TPanel; PageControl1: TPageControl; TabSheet1: TTabSheet; TabSheet2: TTabSheet; m1: TMemo; lb1: TListBox; btnGetProcesses1: TButton; Splitter1: TSplitter; btnPause: TButton; st1: TStaticText; btnGetProcesses2: TButton; procedure btnPauseClick(Sender: TObject); procedure btnGetProcesses2Click(Sender: TObject); procedure btnGetProcesses1Click(Sender: TObject); private { Private declarations } public { Public declarations } procedure GetProcesses_1; procedure GetProcesses_2; end; var Form1: TForm1; ts: tstrings; n: integer=0; // out counter for the listbox of items. implementation {$R *.dfm} uses tlHelp32; procedure tform1.GetProcesses_1; // #1 var handler: THandle; data: TProcessEntry32; PID: cardinal; function GetName: string; var i:byte; begin Result := ''; i := 0; while data.szExeFile[i] <> '' do begin Result := Result + data.szExeFile[i]; //PID := data.th32ProcessID; Inc(i); end; end; begin n:=0; ts:=tstringlist.Create; Data.dwSize := SizeOf(Data); form1.DoubleBuffered:=true; lb1.DoubleBuffered := true; lb1.Items.BeginUpdate; lb1.Items.Clear; lb1.Sorted:=true; handler := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); if Process32First(handler, data) then begin ts.Add(GetName()); //lb1.Items.Add({inttostr(data.th32ProcessID) + ': '+}GetName()); while Process32Next(handler, data) do begin ts.Add(GetName()); inc(n); //lb1.Items.Add({inttostr(data.th32ProcessID) + ': '+}GetName()); end; end else ShowMessage('Error'); lb1.Items.EndUpdate; lb1.Items.Assign(ts); st1.Caption := inttostr(n); ts.Free; end; procedure TForm1.btnGetProcesses1Click(Sender: TObject); begin GetProcesses_1; end; procedure tform1.getprocesses_2; // method #2, from https://www.vbforums.com/showthread.php?350779-Delphi-Getting-Running-processes-into-a-List-Box-and-Kill-Selected var MyHandle: THandle; Struct: TProcessEntry32; begin n:=0; try MyHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0); Struct.dwSize:=Sizeof(TProcessEntry32); if Process32First(MyHandle, Struct) then form1.lb1.Items.Add(Struct.szExeFile); while Process32Next(MyHandle, Struct) do begin form1.lb1.Items.Add(Struct.szExeFile); inc(n); end; except on exception do ShowMessage('Error showing process list'); end end; procedure TForm1.btnGetProcesses2Click(Sender: TObject); // method #2 begin n:=0; getprocesses_2; st1.Caption := inttostr(n); end; end.
  8. I did not know that. I had downloaded an old Delphi project and was reading the readme.txt it came with and saw a link to the usernet newsgroup "https://groups.google.com/g/comp.lang.pascal.delphi.misc" The topic of the post in the newgroup was from Tim Robert's, from April 17, 1997, related to an Delphi project by efg (Early F. Glynn) and I was trying to see what he wrote about. When I entered that address in Chrome, I could only scroll via "<" and ">" icons and it took me about 4 hours to get to the date range of 4/1997, but I did not find the April 17, 1997 post mentioned in the readme.txt file. And, after retiring for the day, I left the tab open there and shut down the laptop in sleep mode, and the next day, the date had gone back up to 2023. Although I was looking in the newsgroup for that particular topic, I want to continue searching other newsgroup topics, so I would like a newsreader that works. Many topics will probably be from the days of old, for stuff you can't find on the internet anymore these days because those sites closed down for instance.
  9. Hi, I am trying to find my (NNTP) server name so that I use setup and use with XanaNews. My provider is Optimum Internet here in the States. It has been years since I used a newsreader. My last reader was with Netscape in Windows 98. It was pretty easy to use back then. When you phone Optimum they mainly have automated choices, so that is not an option. I've tried CMD and entered "hostname" but that gives me my computer name. Also tried ipconfig /all but that returns a bunch of details that I do not understand. Is there another way to obtain it through software or else the internet? TIA.
  10. JohnLM

    Delphi 12.1 is available

    EMB has just put out a video discussing 12.1
  11. JohnLM

    Check if selected row in DBGrid

    @Lainkes - this is probably what you are after. Put the if/then code snippet (below) into the OnColEnter event of the DBGrid. And every time you enter that field that you set .FieldName='myfieldname' to, will highlight your button bold or non-bold. procedure TForm1.dbgrid1ColEnter(Sender: TObject); begin if db1.SelectedField.FieldName='myfieldname' then button1.Font.Style := [fsBold] else button1.Font.Style := []; end;
  12. JohnLM

    My new project : WebView4Delphi

    Resolved - regarding the .dcu files. Under the: options -> Environment Options -> Delphi Options -> Library -> Library Path: I added the "\WebView4Delphi-main\source\" folder After this update, the SimpleBrowser compiled and ran.
  13. JohnLM

    My new project : WebView4Delphi

    Your suggestion to change the 'Package output directory' worked. The components have been added successfully. Thanks. However, when I try to compile a few of your demos, they fail. It seems none of the .dcu files are being created and Delphi can't find them at compile time. below are from your SimpleBroswer demo. They are in the Uses section with red underlines. uWVBrowser, uWVWinControl, uWVWindowParent, uWVTypes, uWVConstants, uWVTypeLibrary, uWVLibFunctions, uWVLoader, uWVInterfaces, uWVCoreWebView2Args, uWVBrowserBase
  14. JohnLM

    My new project : WebView4Delphi

    Unfortunately, I am still getting the same error message stated in my first post above. I've also downloaded the latest version, which are dated 3/9/2024. Please note, each file that I Build, I am first double-clicking on it to select it. WebView4DelphiVCLRTL.bpl, when I right-click it, I select Build, when it finishes, I get Done. WebView4DelphiFMXRTL.bpl, when I right-click it, I select Build, when it finishes, I get Warnings. WebView4DelphiVCL_designtime.bpl when I right-click it, I select Build, when it finishes, I get Done. ** this is the file that will not complete when I right-click and select Install. I get the error message stated earlier. ** WebView4DelphiFMX_designtime.bpl when I right-click, I select Build, when it finishes, I get Warnings. ** this file also will not complete when I right-click and select Install. I get the error message stated earlier. **
  15. JohnLM

    My new project : WebView4Delphi

    Hi, I'm having trouble installing webview4delphi under Delphi XE7. I am receiving the following error: "The program can't start because WebView4DelphiVCLRTL.bpl is missing from your computer. Try reinstalling the program to fix this problem." But the file is showing in the listing below:
×