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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I have a small exe that does 1

Status
Not open for further replies.

pgk

Programmer
Jul 19, 2002
262
US
Hi,
I have a small exe that does the following (atleast, it is what I want it to do):

1)Use the Shell command to run the Setup.exe of another program
2)After this setup is finished, replace a file installed by the Setup program with one that I have created.

The problem is before the Setup finishes its task, the rest of the code is executed and an error message stating the file could not be found is displayed.

How can I make the program wait until Setup has finished its installation process?

Thanks in advance.
Hope it helps. Let me know what happens.
With regards,
PGK
 
do a keyword search for Shell and Wait

second item in results is thread222-126053
 
Hi,
I will do a search as suggested. Thank you for puttin me onto something. A star for you. Hope it helps. Let me know what happens.
With regards,
PGK
 
You're welcome!

I suggest you look at Thread222-126053 first.

I use the API method myself but I guess the other method will also work.
 
Hi,
One more question: Can the Scripting Runtime be used on machines that don't have VB installed? I saw that the file in question was scrrun.dll . As I said before, my program is just an exe and will not be packaged for deployed.

Thnaks in advance. Hope it helps. Let me know what happens.
With regards,
PGK
 
You don't necessarily need VB installed on a computer to run an exe created by it. Otherwise we would all need Java, C++ and others installed to play games.

All that you need is the correct version of any DLL's that you make reference to.

So...to ansywer your question, if the SCRRUN.DLL that is on the computer that you put your .exe file on is the same version or newer then the one included as a reference in your .exe then it will work. If it is an older version then then one in your reference then it may or may not work.
 
>All that you need is the correct version of any DLL's that you make reference to

This is not quite accurate
 
Hi,
I still am not clear. Will scrrun.dll be installed on all machines that use a Windows platform? If so, I don't see any problems.

Thanks in advance. Hope it helps. Let me know what happens.
With regards,
PGK
 
If you are worried about the version of the SCRRUN.DLL then do not give reference to Micosoft Scripting runtime and then you can use

CreateObject("Scripting.FileSystemObject")

to create FSO object. But you can not be sure if scrrun.dll will be present or not. So to be on safe side you should use windows API's directly like CopyFile, DeleteFile etc.

For checking whether your setup program is finished or not you can run the setup program using CreateProcess which will give you the handle to the new process and then you can use WaitforSingleObject for making sure program is finished or not.

Regards,

Manoj
 
Hi,
I have use d the code in Thread222-126053 and come up with the followig program, which has been compiled into an exe.

Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function WaitForInputIdle Lib "user32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long


Private Const INFINITE = &HFFFF
Private Const SYNCHRONIZE = &H100000



Public Sub ShellAndWait(sAppPath As String, Optional iWindowStyle As VbAppWinStyle = vbMaximizedFocus, Optional lmsTimeOut As Long = INFINITE)
Dim lPid As Long
Dim hProc As Long
Dim lTimeOut As Long
lPid = Shell(sAppPath, iWindowStyle)
hProc = OpenProcess(SYNCHRONIZE, 0&, lPid)
If hProc <> 0& Then
WaitForInputIdle hProc, INFINITE
WaitForSingleObject hProc, lmsTimeOut
CloseHandle hProc
End If
End Sub

Public Sub Main()
Dim ret As Long
ShellAndWait (&quot;D:\EBIN\Setup.exe&quot;)
Dim fso1 As FileSystemObject
Dim fil2 as File
Set fso1 = New FileSystemObject
If fso1.FileExists(&quot;C:\Desktop\SC\XYZ.mdb&quot;) Then
Set fil2 = fso2.GetFile(&quot;E:\SC\XYZ.mdb&quot;)
fil2.Copy &quot;C:\Desktop\SC\xyz.mdb&quot;, True
MsgBox &quot;XYZ.mdb copied successfully&quot;
Else
MsgBox &quot;Error.&quot;
GoTo unloadForm
End If
unloadForm:
Set fil2 = Nothing
Set fso1 = Nothing
End Sub

The Startup form is Main. The Setup.exe that is shelled at the start requires a few user inputs like choosing the version (stand alone, network etc), agreeing to the license terms etc. After the files are copied, the user need to click on the Finish button to complete the setup.

After this the file copy needs to be carried out.

The problem is: It does not work when I just run the exe. It opens the initial Setup screen and hangs. But if I step thru the code, the program works properly.

Please help me with this problem.
Thanks in advance and sorry for the long post.
Hope it helps. Let me know what happens.
With regards,
PGK
 
Hi Folks,
Tjis issue of mine has not yet been closed. So please take another look at it and help me.

Thanks.
Hope it helps. Let me know what happens.
With regards,
PGK
 
Try to put a few doEvents in your ShellandWait Sub... put it before and after

hProc = OpenProcess(SYNCHRONIZE, 0&, lPid)

also, put a label on your form to trace what's happening here...

after every line of code put :lblStatus.caption = &quot;Opening Process&quot; or something like that. This way when you run your code, you can get some visual output to tell you where you are. Come to think of it, put a doevents between every line of code in the ShellandWait Subroutine.

I think your code is getting executed before the OS has time to complete the actual file copy.

When you step through the code it works, so you know it does work if it's going much, much slower, right!

By placing a simple label on your form and having that label report to you in real time, you will be able to find the fault.

Good luck!

Tuna
 
Hi Tuna,
Thanks for your comments. The problem is that I shell and wait for a Setup program to complete, after which I want the file copy process to take place. The user has to enter a couple of details during the Setup process and this may take more time. So we cannot assume a fixed time interval for the Setup program to finish.

Is there some to wait until the Setup.exe has finished and the window is closed?

Thanks in advance. Hope it helps. Let me know what happens.
With regards,
PGK
 
Yes, actually there is... I've corrupted my WIN32 API viewer and I can't look it up! :(

Ummm, lets see:

There are many ways to find the handle of a window, one way is to get the handle of the window with the current focus (do this while your setup program has focus and you know it). Use GetFocus

Private Declare Function GetFocus& Lib &quot;user32&quot; ()

Start polling that handle with IsWindow :

Private Declare Function IsWindow& Lib &quot;user32&quot; (ByVal hwnd as long)

When isWindow returns a zero, that window is no longer a valid window and you know said window and your setup is done.

Let me know if this gets you there. I had to do this on more that one occasion during dreaded application deployments to some 2000+ PC's. What a pain.

Tuna - It's fat free until you add the Mayo!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top