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!

shell function 1

Status
Not open for further replies.

hkung

Programmer
Jan 9, 2001
19
0
0
MY
hi all,

I have a function that will execute a shell function. To avoid the following statement being executed before the shell command completed, i've used WaitForSingleObject function. The codes are working fine. However, i need to close the command prompt window after the shell function completed in order to execute the following command. My question is, how can i automatically close the command window once the shell function is executed completely?

Below are my codes :

Function Uploadfile(file As String)

source = DataFilePath & file
destination = DupFilePath & "text1.txt"

Set fso = CreateObject("Scripting.FileSystemObject")

fso.copyfile source, destination

'codes added in to make sure shell command finish
'executing before the following command being called.

lngExecOK = Shell(BatFilePath & "text1.bat")

'handle to process
lProcessHandle = OpenProcess(&H100000, True, lngExecOK)

'Wait
lReturnValue = WaitForSingleObject
(lProcessHandle,INFINITE)

Uploadfile = lReturnValue

' i need to close the Dos prompt window in order
' to execute the following line of codes.

fso.deletefile (destination)

End Function
 
Just a guess, but you coul dtry sending a shell command of "exit", as this is what you can type at the prompt to close it down. it may work and would be easier than getting the window handle and using the API to close it.

Matt
 
On second thoughts, that wont work because it hasn't been sent to the same cmd window!

Sorry!

You will need to get the window handle and close it with the API.
 
To close automatically a dos program when ended, you can put "command.com /C " before of the command line used to execute the program in the shell command. (use "cmd.exe /C " if you works on windows NT).

Leandro

 
shell "start " & BatFilePath & "\" & Text1.text, vbHide

runs it as if you were running it fromt he start box but uses a dos command... the vbHide hides the dos box but the program will run.. also good way to execute links in the program :). in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top