Handling Dependent Processes

Handling Dependent Processes

Question:
I need execute some commands to rename/copy files. What is the best method of performing this type of function.I do not want to fire off a batch file, but have all commands executed one after the other in VB. Is this possible?

Answer:
This was a common problem under VB 3.0 also. The solution there was to use the GetModuleUsage routine. However, under version 4.0, this doesn’t work. The following code will provide the same functionality under version 4.0.

Attribute VB_Name = “Shell” ‘************************************************************************************************************’  PROCESS STUFF’************************************************************************************************************Public Const PROCESS_QUERY_INFORMATION = &H400Public Const PROCESS_TERMINATE = &H1Public Const STILL_ACTIVE = &H103’THE REMAINING CONSTANTS FOUND IN WINNT.H Public Declare Function OpenProcess Lib “kernel32” (ByVal dwDesiredAccess&, ByVal bInheritHandle&, ByVal dwProcessId&) As LongPublic Declare Function GetExitCodeProcess Lib “kernel32” (ByVal hProcess As Long, lpExitCode As Long) As LongDeclare Function TerminateProcess Lib “kernel32″ (ByVal hProcess As Long, ByVal uExitCode As Long) As Long  Sub ShellAndWait(strApp As String)’***********************************************************************************************’ PURPOSE:      to shell to an app, wait for it to finish and then come back’ only a 32 bit app.  Do not use TerminateProcess for app that loads .dlls but works’ great for virtual dos sessons.” EFFECTS:      the app shelled to and program execution here’ INPUTS:       the path and file name to the shelled app’ RETURNS:      Nothing’ CALLED FROM:’ AUTHOR DATE:  BruceJackson 10/95’***********************************************************************************************On Error GoTo ShellAndWait_ErrDim lngShellReturn As LongDim lngOpenProcess As LongDim lngExit As LongDim lngTimer As LongDim msg As StringConst NOWINDOW = 0Const WINDOWED = 1Dim r’***********************************************************************************************    lngShellReturn = Shell(strApp, WINDOW)                 ‘ OPENS WITH WINDOW, USE NOWINDOW FOR HIDDEND    lngTimer = Timer    lngOpenProcess = OpenProcess(PROCESS_QUERY_INFORMATION + PROCESS_TERMINATE, False, lngShellReturn)    Do    Call GetExitCodeProcess(lngOpenProcess, lngExit)    If lngExit = STILL_ACTIVE Then        If Timer – lngTimer > 120 Then                                         ‘ only wait for two minutes            msg = “An application has timed out!” & vbCrLf            msg = msg & “The path and file name to the batch file is: ” & strApp            ‘ can also use ExitProcess            r = TerminateProcess(lngOpenProcess, lngExit)                      ‘ FOR DOS APPS THAT DON’T CALL DLLS ONLY            MsgBox msg, 64, “Time Out Error”            Exit Sub        End If        If lngTimer > Timer Then lngTimer = Timer                              ‘ adjust after midnight        DoEvents    Else        Exit Sub    End If    Loop’***********************************************************************************************ShellAndWait_bye:    Exit SubShellAndWait_Err:    MsgBox “ERROR: ” & Error$ & Chr$(13) & Chr$(10) & “ERR#:  ” & Err, 64, “ShellAndWait”    GoTo ShellAndWait_byeEnd Sub

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as