
|
From VB you won't be able to pass extended commandlines with switches to a shell app. That's where you take out your hammer: write a batch and call that. This works even for a pure Windows program, since Win will know how to handle it.
To watch these functions at work, download the LiDuS-code here.
MakeBatch takes the program to call and the switches as parameters. It writes the batch, but does not call it.
Private Sub MakeBatch(ProgName as String, _ Switches as String) Dim
f As Integer 'let's find a name for the output-file OutName = Left$(Progname, Instr(Progname, "."))
'does the batch exist? kill it anyway to _ 'avoid misconceptions.
'does the output-file exist? we don't need _ 'it
- yet
'begin.tmp is a dummy. its deletion is the _ 'last thing the batch does, telling us it's _ done. "
> " & OutName & ".txt" & vbCrLf &
_
This function takes the program-name we provided MakeBatch with and returns the output the batch generated. Have a look at how we wait for the deletion of begin.tmp.
Private
Function ReadOutput(ProgName As String) As String
If the program you want to call is a DOS-programm (like ping) you will find your desktop cluttered with killed dosboxes. Don't throw an atom-bomb at them, just have a close look at COMSPEC.
Call Shell(Environ("COMSPEC") & " /C " & App.Path _ & "\doscall.bat", vbMinimizedNoFocus)
So how would we use these to ping a machine from VB without the user ever noticing? Mind, this works only for Windows 9x, not for Windows NT. The latter is somewhat picky when it comes to hiding activity from the user.
Public
Function Ping(IP As String) As String App.Path & "\doscall.bat", _ vbMinimizedNoFocus)
Neat, hu?
Another thing is passing windows the hot potato of handling a certain extension. Just call Shell.Execute with the file in question. Windows will know what to do with it and start the application that is associated. But be careful to handle any occuring errors: your user might not have the application installed :) |