-
help with shell calls
I am trying to open a dos window using a shell call. I can get the dos prompt to come up but it will only stay open for about a second and then it closes. I am using the following code:
Shell("c:\windows\ping.exe", vbNormalFocus)
Is this correct? I want to pass a ping command to the app and wait for the results.
Thanks for the help
-
I haven't tried this but it should work to use the shell command to open the console window (DOS prompt) then send the ping command to the screen along with a carriage return line feed (for Enter) then get the result from the screen.
Even if you run ping from start run it closes the console window down as quick as the ping returns a result.
-
That is another question. How do I get that up? It tells me that the path is not found when I try and open command.com or just a shortcut to the dos prompt. I can open it with out the VB
Thanks
-
I presume you want to check if you have access to a site etc, or if it is up and running?
Try this.... ( I got it from www.ALLAPI.Net - check them out for everything API)
Code:
Const NETWORK_ALIVE_WAN = &H2
Private Type QOCINFO
dwSize As Long
dwFlags As Long
dwInSpeed As Long 'in bytes/second
dwOutSpeed As Long 'in bytes/second
End Type
Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long
Private Sub Form_Load()
Dim Ret As QOCINFO
Ret.dwSize = Len(Ret)
If IsDestinationReachable("www.microsoft.com", Ret) = 0 Then
MsgBox "The destination cannot be reached!"
Else
MsgBox "Destination found" + vbCrLf + _
"The speed of data coming in from the destination is " + Format$(Ret.dwInSpeed / 1024, "#.0") + " Kb/s," + vbCrLf + _
"and the speed of data sent to the destination is " + Format$(Ret.dwOutSpeed / 1024, "#.0") + " Kb/s."
End If
End Sub
-
Use ShellExecute
Code:
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
String, ByVal lpFile As String, ByVal lpParameters As String, ByVal _
lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Private Sub Form_Load()
ShellExecute Me.hwnd, vbNullString, "COMMAND.EXE", "PING www.vbforums.com", "C:\", SW_SHOWNORMAL
End Sub
Shellexec to CMD.EXE on NT systems.
Also use a .BAT file -- change "PING" to MYPING.BAT"
Code:
REM MYPING.BAT
PING %1