First time playing with Shell...comments welcome
VB Code:
' Returns Gateway IP and more ' ' VbForums.com User: SESSI4ML ' Sub Command1_Click() Dim fname As String ' fname = "c:\GateWay.txt" ' Shell will not accept a long string. Max of ? ' Must have spaces between command and options (flags) ' Shell "c:\windows\system32\cmd.exe /c ipconfig/all > " + fname, vbMinimizedNoFocus Wait 1 ' OS will process the next lines of code before it finishes the Shell request Call LoadFile(fname) Label1.Caption = fIpConFig("Gateway") + vbCrLf + fIpConFig("IP Address") + fIpConFig("Physical") End Sub Private Sub LoadFile(strFile As String) Dim fb As Integer: Dim strIn As String If Len(strFile) = 0 Then Debug.Print "E1": Exit Sub fb = FreeFile If Dir(strFile) = "" Then Debug.Print "E2": Exit Sub ' File was not created, Exit Open strFile For Input As #fb Do While EOF(fb) = False Line Input #fb, strIn ' Load line Text1.Text = Text1.Text + strIn + vbCrLf ' Load Text box Loop End Sub Function fIpConFig(strSearch As String) As String ' Scan Text box Dim int1 As Integer ' First parameter Dim int2 As Integer ' Second parameter Dim int3 As Integer ' End of line ' int1 = InStr(1, Text1.Text, strSearch) ' Find Line int2 = InStr(int1, Text1.Text, ":") ' Find colon int3 = InStr(int2, Text1.Text, vbCr) fIpConFig = strSearch + " " + Mid(Text1.Text, int2 + 1, int3 - int2) End Function ' Public Sub Wait(seconds As Integer) ' Thanks RhinoBull...[url]http://www.vbforums.com/showpost.php?p=2732926&postcount=5[/url] Dim dTimer As Double dTimer = Timer Do While Timer < dTimer + seconds DoEvents Loop End Sub




Reply With Quote