Jump to content

Recommended Posts

Posted

Hi, I'm using vpn connection to a remote computer with a login user (idk if that's any important).

I want to loop a process until it's closed completely. I'm just looping until the process is closed (for or while doesn't matter):

Local $aProcessList = ProcessList("cmd.exe")
For $i = 1 To $aProcessList[0][0]
    ConsoleWrite("PID: " & $aProcessList[$i][1] & @CRLF)
    ProcessClose($aProcessList[$i][0])
    ;WinKill($aProcessList[$i][0])
    If @error Then
        ConsoleWrite("Error is: " & @error & @CRLF)
    EndIf
Next

This is my output: 

PID: 5548
Error is: 2
PID: 29488
Error is: 2
PID: 47248
Error is: 2

When I check in the task manager, I can only see one cmd --> 47248:

1. But my script doesn't close this process. I checked the error code 2 (AdjustTokenPrivileges Failed), but couldn't go any further.

2. I cannot see other two cmd.exe (5548 + 29488) in the task manager either even if I click "show process from all users".

3. If I select 47248 manually click on "end process", it works, the process is closed.

I put #RequireAdmin in the beginning (hoping), but that didn't work either.

image.png.e1fcb405c159f485bcf09c36cdc36105.png

 

If there are other processes from other users, I don't want to terminate them. I only want to terminate the process that is under my user. 

If I just type ProcessClose(47248) in my script, then it closes. But I couldn't close it inside the loop. What am I missing? 

TY.

Posted

try

ProcessClose($aProcessList[$i][1])

 

The two basic principles of Windows system administration:
For minor problems, reboot -- For major problems, reinstall
"Sarkasm is the lowest form of humor, but the highest form of intelligenz"
Val McDermid
 
no advertising:
If you want to translate your texts into another language,
I can only recommend deepl.com. I am very satisfied with the translations.
Posted

Try this.  In the past, it was killing any resilient process :

Local $iPID = Run(@ComSpec & " /K")  ; this line is just for test
ProcessWait($iPID)
Local $aProcessList = ProcessList("cmd.exe"), $iRes
For $i = 1 To $aProcessList[0][0]
  ConsoleWrite("PID: " & $aProcessList[$i][1] & @CRLF)
  $iRes = RunWait("TaskKill /PID " & $aProcessList[$i][1] & " /F", "", @SW_HIDE)
  If @error Or $iRes Then ConsoleWrite(@error & "/" & $iRes & @CRLF)
Next

 

Posted

This is my output: 

PID: 4692
0/1
PID: 32896
0/1
PID: 54672
PID: 12076

54672 (the third one) = This is the cmd that I manually opened and it's terminated after the script ends.

12076 (the last one) = This is created with your script. It's terminated after the script ends. 

The first two = I don't know them. I can't see in the task manager either. They still exist after the script ends. How do I know? Because when the script again, I got the same PID again. But it doesn't matter. Thanks guys.

PID: 4692
0/1
PID: 32896
0/1
PID: 20912
PID: 2336

 

TY.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...