Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
running commands from hte shell
i would like to create a simple spreadsheet, that has, say, a button for
PING, a button for NSLOOKUP, and one for NBTSTAT. Along with those, a text box for inputting an ip address or computer name. When the button is presses the command is run against the info in the textbox and output into say cell f6. I have not been able to figure this out. I can get as far as seeing the sheel open quickly with the programs' /? command run. It then closes very quickly. Thanks in advance for any clues. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
running commands from hte shell
Try the following for Ping
Private Sub CommandButton1_Click() Dim sAddress$ 'Input box to capture the address sAddress = InputBox("Enter the IP Address") Sheet1.Cells(1, 1).Value = Shell("C:\Winnt\System32\ping " & sAddress) End Sub I tried this. Similarly probably for the others but I am not sure. Alok Joshi "Ruthless Dog" wrote: i would like to create a simple spreadsheet, that has, say, a button for PING, a button for NSLOOKUP, and one for NBTSTAT. Along with those, a text box for inputting an ip address or computer name. When the button is presses the command is run against the info in the textbox and output into say cell f6. I have not been able to figure this out. I can get as far as seeing the sheel open quickly with the programs' /? command run. It then closes very quickly. Thanks in advance for any clues. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
running commands from hte shell
I apologize my reply above is not correct. This only returns the program
return code and not the actual values. Alok "Alok" wrote: Try the following for Ping Private Sub CommandButton1_Click() Dim sAddress$ 'Input box to capture the address sAddress = InputBox("Enter the IP Address") Sheet1.Cells(1, 1).Value = Shell("C:\Winnt\System32\ping " & sAddress) End Sub I tried this. Similarly probably for the others but I am not sure. Alok Joshi "Ruthless Dog" wrote: i would like to create a simple spreadsheet, that has, say, a button for PING, a button for NSLOOKUP, and one for NBTSTAT. Along with those, a text box for inputting an ip address or computer name. When the button is presses the command is run against the info in the textbox and output into say cell f6. I have not been able to figure this out. I can get as far as seeing the sheel open quickly with the programs' /? command run. It then closes very quickly. Thanks in advance for any clues. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
running commands from hte shell
Here is an API call for your ping function...
Option Explicit Private Const IP_SUCCESS As Long = 0 Private Const PING_TIMEOUT As Long = 500 Private Const WS_VERSION_REQD As Long = &H101 Private Const INADDR_NONE As Long = &HFFFFFFFF Private Const MAX_WSADescription As Long = 256 Private Const MAX_WSASYSStatus As Long = 128 Private Type ICMP_OPTIONS Ttl As Byte Tos As Byte Flags As Byte OptionsSize As Byte OptionsData As Long End Type Private Type ICMP_ECHO_REPLY Address As Long status As Long RoundTripTime As Long DataSize As Long 'formerly integer 'Reserved As Integer DataPointer As Long Options As ICMP_OPTIONS Data As String * 250 End Type Private Type WSADATA wVersion As Integer wHighVersion As Integer szDescription(0 To MAX_WSADescription) As Byte szSystemStatus(0 To MAX_WSASYSStatus) As Byte wMaxSockets As Long wMaxUDPDG As Long dwVendorInfo As Long End Type Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long Private Declare Function IcmpCloseHandle Lib "icmp.dll" _ (ByVal IcmpHandle As Long) As Long Private Declare Function IcmpSendEcho Lib "icmp.dll" _ (ByVal IcmpHandle As Long, _ ByVal DestinationAddress As Long, _ ByVal RequestData As String, _ ByVal RequestSize As Long, _ ByVal RequestOptions As Long, _ ReplyBuffer As ICMP_ECHO_REPLY, _ ByVal ReplySize As Long, _ ByVal Timeout As Long) As Long Private Declare Function WSAGetLastError Lib "wsock32" () As Long Private Declare Function WSAStartup Lib "wsock32" _ (ByVal wVersionRequired As Long, _ lpWSADATA As WSADATA) As Long Private Declare Function WSACleanup Lib "wsock32" () As Long Private Declare Function gethostname Lib "wsock32" _ (ByVal szHost As String, _ ByVal dwHostLen As Long) As Long Private Declare Function gethostbyname Lib "wsock32" _ (ByVal szHost As String) As Long Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" _ (xDest As Any, _ xSource As Any, _ ByVal nbytes As Long) Private Declare Function inet_addr Lib "wsock32" _ (ByVal s As String) As Long Function PingComputer(ByVal strIPAddress As String) As Long Dim ECHO As ICMP_ECHO_REPLY Dim pos As Long Dim lResult As Long Dim str2 As String If SocketsInitialize() Then str2 = "test" 'ping the IP by passing the address, 'text to send, and the ECHO structure. lResult = Ping((strIPAddress), (str2), ECHO) If Left$(ECHO.Data, 1) < Chr$(0) Then pos = InStr(ECHO.Data, Chr$(0)) End If SocketsCleanup Else 'MsgBox "Windows Sockets for 32 bit Windows " & _ "environments is not successfully responding." End If PingComputer = lResult End Function Private Function Ping(sAddress As String, _ sDataToSend As String, _ ECHO As ICMP_ECHO_REPLY) As Long 'If Ping succeeds : '.RoundTripTime = time in ms for the ping to complete, '.Data is the data returned (NULL terminated) '.Address is the Ip address that actually replied '.DataSize is the size of the string in .Data '.Status will be 0 'If Ping fails .Status will be the error code Dim hPort As Long Dim dwAddress As Long 'convert the address into a long representation dwAddress = inet_addr(sAddress) 'if a valid address.. If dwAddress < INADDR_NONE Then 'open a port hPort = IcmpCreateFile() 'and if successful, If hPort Then 'ping it. Call IcmpSendEcho(hPort, _ dwAddress, _ sDataToSend, _ Len(sDataToSend), _ 0, _ ECHO, _ Len(ECHO), _ PING_TIMEOUT) 'return the status as ping succes and close Ping = ECHO.status Call IcmpCloseHandle(hPort) End If Else 'the address format was probably invalid Ping = INADDR_NONE End If End Function Private Sub SocketsCleanup() If WSACleanup() < 0 Then MsgBox "Windows Sockets error occurred in Cleanup.", vbExclamation End If End Sub Private Function SocketsInitialize() As Boolean Dim WSAD As WSADATA SocketsInitialize = WSAStartup(WS_VERSION_REQD, WSAD) = IP_SUCCESS End Function 'Run this Like this: ' 'ActiveCell.Value = PingComputer(Cells(ActiveCell.Row, 1).Value) This code is from Bob Phillips. I have not tried it but I am sure it will work. HTH "Ruthless Dog" wrote: i would like to create a simple spreadsheet, that has, say, a button for PING, a button for NSLOOKUP, and one for NBTSTAT. Along with those, a text box for inputting an ip address or computer name. When the button is presses the command is run against the info in the textbox and output into say cell f6. I have not been able to figure this out. I can get as far as seeing the sheel open quickly with the programs' /? command run. It then closes very quickly. Thanks in advance for any clues. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
running commands from hte shell
I cant get it to work. Result is zero. I think I may have missed some of the garbage the newsreader leaves in when I copy and pasted. "Jim Thomlinson" wrote: Here is an API call for your ping function... Option Explicit Private Const IP_SUCCESS As Long = 0 Private Const PING_TIMEOUT As Long = 500 Private Const WS_VERSION_REQD As Long = &H101 Private Const INADDR_NONE As Long = &HFFFFFFFF Private Const MAX_WSADescription As Long = 256 Private Const MAX_WSASYSStatus As Long = 128 Private Type ICMP_OPTIONS Ttl As Byte Tos As Byte Flags As Byte OptionsSize As Byte OptionsData As Long End Type Private Type ICMP_ECHO_REPLY Address As Long status As Long RoundTripTime As Long DataSize As Long 'formerly integer 'Reserved As Integer DataPointer As Long Options As ICMP_OPTIONS Data As String * 250 End Type Private Type WSADATA wVersion As Integer wHighVersion As Integer szDescription(0 To MAX_WSADescription) As Byte szSystemStatus(0 To MAX_WSASYSStatus) As Byte wMaxSockets As Long wMaxUDPDG As Long dwVendorInfo As Long End Type Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long Private Declare Function IcmpCloseHandle Lib "icmp.dll" _ (ByVal IcmpHandle As Long) As Long Private Declare Function IcmpSendEcho Lib "icmp.dll" _ (ByVal IcmpHandle As Long, _ ByVal DestinationAddress As Long, _ ByVal RequestData As String, _ ByVal RequestSize As Long, _ ByVal RequestOptions As Long, _ ReplyBuffer As ICMP_ECHO_REPLY, _ ByVal ReplySize As Long, _ ByVal Timeout As Long) As Long Private Declare Function WSAGetLastError Lib "wsock32" () As Long Private Declare Function WSAStartup Lib "wsock32" _ (ByVal wVersionRequired As Long, _ lpWSADATA As WSADATA) As Long Private Declare Function WSACleanup Lib "wsock32" () As Long Private Declare Function gethostname Lib "wsock32" _ (ByVal szHost As String, _ ByVal dwHostLen As Long) As Long Private Declare Function gethostbyname Lib "wsock32" _ (ByVal szHost As String) As Long Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" _ (xDest As Any, _ xSource As Any, _ ByVal nbytes As Long) Private Declare Function inet_addr Lib "wsock32" _ (ByVal s As String) As Long Function PingComputer(ByVal strIPAddress As String) As Long Dim ECHO As ICMP_ECHO_REPLY Dim pos As Long Dim lResult As Long Dim str2 As String If SocketsInitialize() Then str2 = "test" 'ping the IP by passing the address, 'text to send, and the ECHO structure. lResult = Ping((strIPAddress), (str2), ECHO) If Left$(ECHO.Data, 1) < Chr$(0) Then pos = InStr(ECHO.Data, Chr$(0)) End If SocketsCleanup Else 'MsgBox "Windows Sockets for 32 bit Windows " & _ "environments is not successfully responding." End If PingComputer = lResult End Function Private Function Ping(sAddress As String, _ sDataToSend As String, _ ECHO As ICMP_ECHO_REPLY) As Long 'If Ping succeeds : '.RoundTripTime = time in ms for the ping to complete, '.Data is the data returned (NULL terminated) '.Address is the Ip address that actually replied '.DataSize is the size of the string in .Data '.Status will be 0 'If Ping fails .Status will be the error code Dim hPort As Long Dim dwAddress As Long 'convert the address into a long representation dwAddress = inet_addr(sAddress) 'if a valid address.. If dwAddress < INADDR_NONE Then 'open a port hPort = IcmpCreateFile() 'and if successful, If hPort Then 'ping it. Call IcmpSendEcho(hPort, _ dwAddress, _ sDataToSend, _ Len(sDataToSend), _ 0, _ ECHO, _ Len(ECHO), _ PING_TIMEOUT) 'return the status as ping succes and close Ping = ECHO.status Call IcmpCloseHandle(hPort) End If Else 'the address format was probably invalid Ping = INADDR_NONE End If End Function Private Sub SocketsCleanup() If WSACleanup() < 0 Then MsgBox "Windows Sockets error occurred in Cleanup.", vbExclamation End If End Sub Private Function SocketsInitialize() As Boolean Dim WSAD As WSADATA SocketsInitialize = WSAStartup(WS_VERSION_REQD, WSAD) = IP_SUCCESS End Function 'Run this Like this: ' 'ActiveCell.Value = PingComputer(Cells(ActiveCell.Row, 1).Value) This code is from Bob Phillips. I have not tried it but I am sure it will work. HTH "Ruthless Dog" wrote: i would like to create a simple spreadsheet, that has, say, a button for PING, a button for NSLOOKUP, and one for NBTSTAT. Along with those, a text box for inputting an ip address or computer name. When the button is presses the command is run against the info in the textbox and output into say cell f6. I have not been able to figure this out. I can get as far as seeing the sheel open quickly with the programs' /? command run. It then closes very quickly. Thanks in advance for any clues. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Running Shell | Excel Discussion (Misc queries) | |||
List of commands that work with shell? | Excel Programming | |||
shell commands | Excel Programming | |||
Simple Shell Commands | Excel Programming | |||
Commands at the line prompt using Shell | Excel Programming |