|
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
Ruey
註冊時間: 2003-03-12 文章: 1698 來自: tunglo
第 1 樓
|
發表於: 星期五 五月 16, 2003 10:54 pm 文章主題: 取得網路卡IP(轉貼) |
|
|
You can use the MSWinsock ActiveX control to retrieve your local IP addressmost of the time, but not always.
Description
I've spent a fair amount (too much) time on this and wanted to share my findings.
If you are using an interactive application with a form that you can drop the winsock control onto, you can use that with the LocalIP property. Licensing restrictions prevent you from using this control in all situations however. Without a developer's license Winsck.OCX can not be used other than when dropped onto a form.
If you are working with a .DLL, it seems parsing the return from IPCONFIG is the best answer:
local lcTempFile, loWSH, lcLocalIP
lcTempFile="LocalIP.txt"
if file(lcTempfile) &&erase leftovers from old run
erase (lcTempFile)
endif
loWSH=CreateObject("Wscript.Shell")
loWSH.run("command /c ipconfig > "+lcTempfile,0,1)
if file(lcTempFile) &&read the file and parse it
lcLocalIP=upper(filetostr(lcTempFile))
lcLocalIP=substr(lcLocalIP, at('IP ADDRESS',lcLocalIP))
lcLocalIP=substr(lcLocalIP, at(':',lcLocalIP)+2)
lcLocalIP=substr(lcLocalIP, 1, at(chr(13),lcLocalIP)-1)
messagebox(lcLocalIP)
endif
This example uses windows scripting host. The second parameter tells it to not display the window, the last parameter tells it to not return until the program is finished.
It's a very cool way to run DOS commands without them flashing on the screen. _________________ #############################
快樂媽咪系列幸福宅配,喝十全雞湯~原來幸福那麼簡單!!
學會VFP使用者社區的搜尋,Code才會更有趣~
############################# |
|
回頂端 |
|
|
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|