Kinook Software Forum

Kinook Software Forum (https://www.kinook.com/Forum/index.php)
-   [VBP] User Tips, Tricks and Samples (https://www.kinook.com/Forum/forumdisplay.php?f=19)
-   -   Wait on Process ID? (https://www.kinook.com/Forum/showthread.php?t=2517)

JC1455 04-12-2007 08:30 AM

Wait on Process ID?
 
I see there is a new feature that I'd like to use. Wait now supports waiting on a running process. However you have to specify the process ID. My question is how can I determine the process ID for a process?

Our build machines start up, run the builds and then shut back down. Our IT runs full virus scans once a week. So after the appointed scan time passes the next time our build machine starts up it begins running the scan. I'd like to change our build script so that after it's done building it waits for the scan to complete before shutting down, but I don't know how to get the process ID so I can use the new wait feature.

Thanks for any suggestions.

kevina 04-12-2007 12:50 PM

1 Attachment(s)
Attached is a small bld file that demonstrates what you are requesting.

This build demonstrates retrieving the process ID for a process not started by Visual Build Professional using WMI (see the FindProcesses Project script function).

Note that this function isn't needed for processes started by Visual Build Professional with a Run Program step since that action puts the ProcessID for the process in the RUNPROGRAM_PROCESSID temporary macro.

JC1455 04-12-2007 12:56 PM

Thanks! That's exactly what I was looking for!

deramor 04-03-2019 03:33 PM

I know this is a really old thread but I was trying to use this wait on a custom exe. The wait step never finds a PID of the exe I provide to it.

At first I thought it was a 32-bit/64-bit thing since I am using the 32-bit version of VBP and a 64-bit exe. I rebuilt the custom exe as a 32-bit binary and it didn't change the behavior.

The output:

Waiting for process(es) '[FindProcesses("COMPUTER", "BuildDoc.exe")]' to exit...
All process(es) already done
4/3/2019 4:27:59 PM: Build successfully completed (elapsed = 00:00:01).

However the process is listed in the Task Manager.
Running the process with application window hidden or not makes no difference.

Any thoughts?
I am running VBP 9.7

Visual Build Professional 9.7
Copyright © 1999-2019 Kinook Software, Inc.
***Redacted***
Windows Version: Windows 7 Professional
Install path: C:\Program Files (x86)\VisBuildPro9
HideConsole.exe version 1.0.0.0
SftPrintPreview_IX86_U_20.dll version 2.04
VisBuildCmd.exe version 9.7.0.4
VisBuildPro.exe version 9.7.0.5
VisBuildAct.dll version 9.7.0.5
VisBuildCore.dll version 9.7.0.4
VisBuildDotNET.dll version 9.7.0.0
VisBuildExt.dll version 9.7.0.4
VisBuildInf.exe version 9.7.0.4
VisBuildMisc.dll version 9.7.0.4
VisBuildMS.dll version 9.7.0.4
VisBuildMS2.dll version 9.7.0.2
VisBuildNet.dll version 9.7.0.4
VisBuildSvr.dll version 9.7.0.5
VisBuildVCS.dll version 9.7.0.4

kinook 04-03-2019 04:40 PM

It's not really a Visual Build question. Paste the following into a text file.

Code:

Function FindProcesses(computer, processName)

        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computer & "\root\cimv2")

        sql = "SELECT * FROM Win32_Process WHERE Name LIKE '" & processName & "'"
        Set colProcesses = objWMIService.ExecQuery(sql)

        If colProcesses.Count = 0 Then
                FindProcess = "0"
        Else
                For Each objProcess in colProcesses
                    FindProcesses = FindProcesses & vbCrLf & objProcess.ProcessID
                Next
        End If
       
End Function

WScript.Echo(FindProcesses("COMPUTER", "builddoc.exe"))

Save as wait.vbs.

Open a Command Prompt to the path where you saved the .vbs file and run

cscript wait.vbs

I did this with cmd.exe instead of builddoc.exe and got a list of process IDs for each running cmd.exe instance.


All times are GMT -5. The time now is 05:51 PM.


Copyright © 1999-2023 Kinook Software, Inc.