what are your requirements for the text file? where will it be located?
what information do you want to write to the text file? do you mind having the extra bits that an ipconfig at a command prompt will give you?
Set WshSock = WScript.CreateObject("MSWinsock.Winsock")
strIPAddress = WshSock.LocalIP
Msgbox strIPAddress
Set WshSock = Nothing
'or
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.IPAddress) Then
msgIP = msgIP & vbCrLf & "IP address of " & Trim(objAdapter.Description) & " is "
For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
msgIP = msgIP & objAdapter.IPAddress(i) & " "
Next
End If
Next
'have a search for OpenTextFile in the key word search try and put something together then post back with how far youve got and someone can give you a hand
i want to simply write the ip address of my computer to a hardcode text file (already existing on my PC) on my computer when i click a .vbs file located somewhere on my PC.
Thanks
i wrote the following but the file gets created but no ip address is written to it..
any suggestions??
thanks
-----------------------------------
set fil = wscript.CreateObject("scripting.filesystemobject")
set txt = fil.opentextfile("c:\xxx\ip_address.txt", 8, true)
Working from mrmovie's script I added a line to output the IP address. If you don't want the description of the network card, then comment out this line:
msgIP = msgIP & vbCrLf & "IP address of " & Trim(objAdapter.Description) & " is "
Here is the script, just copy into a text file and name it .vbs and you're ready to go.
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\xxx\ip_address.txt", 8, True)
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.IPAddress) Then
msgIP = msgIP & vbCrLf & "IP address of " & Trim(objAdapter.Description) & " is "
For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
msgIP = msgIP & objAdapter.IPAddress(i) & " "
objTextFile.WriteLine(msgIP)
[1] >>txt =Request.ServerVariables("LOCAL_ADDR")
Request object is for asp application. (I then suppose it is?)
[2] You assign txt one to textfile object and then to a string. Hence, error?!... Change the name one way or the other.
[tt]
set [red]o[/red]txt = fil.opentextfile("c:\xxx\ip_address.txt", 8, true)
txt =Request.ServerVariables("LOCAL_ADDR")
[red]o[/red]txt.writeline(txt)
[red]o[/red]txt.close
[/tt]
regards - tsuji
Let me know what you think of Wise. We are looking at the complete package to handle our IT Relaease Management Process including packaging of course. I have used Wise extensively to create and modify MSIs, but I haven't used any of the process management pieces.
[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.