Παρασκευή 3 Απριλίου 2026

Cleaning TEMP folder plus killing M2000 hanging programs

When we do some difficult things we end with a hang process.

This is the right program which is not hang the M2000 Envirnoment:

Declare global GetMem2 lib "msvbvm60.GetMem2" {Long addr, Long retValue}
Variant A=1000&
Integer B=0
Call Void GetMem2(varptr(A), varptr(B))
Print B

So now we think that maybe can work using different signature:

// this is the wrong function/signature
declare global GetMem2_Bad lib "msvbvm60.GetMem2" {Long addr, &retValue}
Variant A=1000&
Integer B=0
Call void GetMem2_Bad(varptr(A), &B)
? B

This hang the Interpreter/Environment

So we run another M2000.exe and put the following code on a module, say A (Edit A then Copy this, press Esc and write A and press enter)

This program finds files with M2000 extension in TEMP folder. Every time we start M2000.exe a new PID (process ID) assigned from operating system and M2000 write an empty file with the name then number of PID and M2000 as extension. So We get the current PID using the GetCurrentProcessID of Kernel32.dll and then we get all *,M2000 files, enumerate them, excluding our PID and sending Taskkill by PID. Also we delete the associate M2000 file. Last we have to delete the TMP type file which VB6 (not the M2000.dll) make it. We can't delete these TMP file if they are locked. TMP files are not of the same type for every program. Operating system produce the names which guarantee that are not used. So we don't now from the M2000.dll which name the tmp file procuced. For this reason we delete all not locked TMP files.  Ypu can ask googles AI "can we delete TMP files in TEMP directory if they ar not locked?" and you get YES, plus the story about that.

The simulated hang program before can closed from the taskbar, which we terminate the M2000.exe which use the M2000.dll as a com object. The TMP file also erased but the M2000 not erased. So the program here will delete only the file (the program are not exist as a process at this point)

The DOS statement using a semi colon at the end executed in a hidden window.

Use Win m2000 to start another M2000.exe (M2000 Interpreter)

or use

USE alfa, "paremeter", 2000

to open another M2000.exe, run alfa.gsb and put these two parameters in the stack of the that interpreter. We can send only strings and numbers from that call. We can use named PIPES, so we can send a pipe name, and we can make alfa the client, and the program which "use" it as server. Also the pipename can be as something specific and all clients known the name from the start (hardcoded).

Named pipes can be used to provide communication between processes on the same computer or between processes on different computers across a network. If the server service is running, all named pipes are accessible remotely

Write HELP USE in command line in M2000 Environment to see about the use of pipes.

This program can't kill process from another computer from the LAN.

ourPID now is string. The new upgrade of M2000 not convert a numeric variable to string unless is a + sign (so maybe it is part of a string expression)


Declare GetCurrentProcessId Lib "kernel32.GetCurrentProcessId" As Long
// this is our ProcessId
string ourPID=GetCurrentProcessId() // convert to string`
// get current directrory
m$=dir$
// set TEMP folder as current folder
dir temporary$
// empty menu array
menu
// using + we send filenames to menu$() array
files + "m2000"
if menuitems>0 else menu: exit
// We get a copy (menu$() is not an array is a function)
// when we use it without parameter return a an array
a=menu$()
menu
k=each(a)
while k
if array(k)<>ourPID then
Print "Erase "+array$(k)
// now we kill the PID and erase the (pid).M2000
dos "taskkill /F /PID "+array$(k);
wait 100
dos "del "+quote$(dir$+array$(k)+".m2000");
end if
end while
// delete all tmp files which are not locked
// because one tmp file produced by the VB6 dll, and we didn't now which are
dos "del  /A:-R "+quote$(temporary$+"*.tmp");
dir m$



Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.