Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wait until a step is complete

Status
Not open for further replies.

GRonken

Programmer
Oct 30, 2003
26
0
0
US
I want the script to check to see if the shared drive exist .. I can do that with a dive.isready BUT if it is not than I want to create a batch file with a one line command THAN run that batch file to connect. PROBLEM: it appears that the batch file is trying to run before it has a chance to create it ... TIMER? HELP Thanks

Set FileObject = CreateObject("Scripting.FileSystemObject")

'Create the DOS batch file which connects to a shared drive
Set objTextFile = FileObject.CreateTextFile("C:\ConnectBillingShare.bat")
objTextFile.WriteLine "net use T: \\someserver\Billing_Files"
objTextFile.Close

' Run the batch file to connect to a shared drive to the billing files located on IDXRADrpt share name Billing_files
Set Shell = CreateObject("WScript.Shell")

Shell.Run "C:\ConnectBillingShare.bat"

 
Unfortunately, the Shell function will not wait until the external process has completed. However, the following API should do what you're looking to accomplish:

-----
Code:
' Declarations
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
    ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, _
    lpExitCode As Long) As Long

' Constants
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103

'==============================================================================
'   1, 5, 9 Normal with focus.
'   2   Minimized with focus.
'   3   Maximized with focus.
'   4, 8 Normal without focus.
'   6, 7 Minimized without focus.
'==============================================================================
Function ShellAndWait(ByVal Pathname As String, Optional WindowState) As Double

    Dim hProg As Long
    Dim hProcess As Long, ExitCode As Long

    'fill in the missing parameter and execute the program
    If IsMissing(WindowState) Then WindowState = 1
    hProg = Shell(Pathname, WindowState)
    'hProg is a process ID under Win32. To get the process handle:
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
    Do
      'populate Exitcode variable
      GetExitCodeProcess hProcess, ExitCode
      DoEvents
    Loop While ExitCode = STILL_ACTIVE
    
    ShellAndWait = ExitCode

End Sub
-----

Hope this helps.

Glen Appleton

VB.Net student.
 
The Run method of the WshShell object may wait until command is complete and even grab the return code:
Set Shell = CreateObject("WScript.Shell")
RetCode=Shell.Run("C:\ConnectBillingShare.bat", , True)


Hope This Help
PH.
 
Hi PH,

Actually, the Shell.Run does not always wait for the external program to complete. I think this has to do with which version of Windows on which the application is running. If you search Google, you will see similar solutions to the API I provided.

Hope this helps.

- Glen

Know thy data.
 
I'm trying to do something a little different - I'm calling on an ill-behaved .exe, which insists on putting up a message box upon completion. Not having much luck trying a sendkeys approach to say "yes, please close the window". However, I can tell by the existence of an output file when the application has completed. So what I'd like to do is unconditionally close the application when it is complete. I figure there must be an API call that can do that, given the process ID returned by the shell function?
As always, your help is appreciated.


Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top