I got the following code from this forum and it works when I run it from either a button on a form or from a button in an email. But when I send the email to anyone else, it doesn’t work. The error messages differ from one machine to another.
Cannot open file
Cannot open automation object
File not found
All I need to do is get the IP address of the Notes Client PC. This is not a web application.
Here’s the code that works for me. Any suggestions would be appreciated:
Function Get_IP
’ create a scripting object, find out the environ, then
'either run winipcfg Or ipconfig
’ put result in a text file, read it, delete it
On Error Goto eh
Dim ws As Variant
Dim fso As Variant
Dim tmpFile As String
Dim thisLine As String
Dim ip As String
Set ws = CreateObject(“WScript.Shell”)
Set fso = CreateObject(“Scripting.FileSystemObject”)
Dim folderStr As String
TmpFile = “C:\Temp\ip.txt”
If ws.Environment(“SYSTEM”)(“OS”) = “” Then
’ attempt to establish whether win9x or nt based o/s
ws.run "winipcfg /batch " & TmpFile, 0, True
Else
ws.run "%comspec% /c ipconfig > " & TmpFile, 0, True
End If
Dim fileNum As Integer
fileNum = Freefile()
Open TmpFile For Input As fileNum
Do While Not Eof(fileNum)
Line Input #fileNum, ThisLine
If Instr(ThisLine, “Address”) <> 0 Then
IP = Mid(ThisLine, Instr(ThisLine, “:”) + 2)
Exit Do
End If
Loop
Msgbox (IP)
Close fileNum
Kill TmpFile
'WinXP (NT? 2K?) leaves a carriage return at the end of line
If IP <> “” Then
If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
End If
Get_IP = IP
Exit Function
eh:
’ if there was a problem here it’s best to bail out completely
End
End Function
Sub Click(Source As Button)
Get_IP
End Sub