می خواستم چطور می تونم از طریق دستورات vba به IP کامپیوتر در حال اجرای برنامه دسترسی پیدا کرده و در یک سلول آنرا ذخیره کنم
بدست آوردن IP کامپیوتری که در حال اجرای برنامه است از طریق vba
Collapse
این تاپیک قفل است.
X
X
-
-
من از طریق دستور vba می تونم برنامه cmd رو اجرا کنم ولی اینکه دستور ipcnfing رو اجرا و بعد IP سیستم رو استخراج کنم گیر کردم
خواهش می کنم از استاتید راهنمایی کنند -
خدمت شما:
کد:Option Explicit Sub IPtest() Dim wsh As Object Dim RegEx As Object, RegM As Object Dim FSO As Object, fil As Object Dim ts As Object, txtAll As String, TempFil As String Set wsh = CreateObject("WScript.Shell") Set FSO = CreateObject("Scripting.FileSystemObject") Set RegEx = CreateObject("vbscript.regexp") TempFil = "C:\myip.txt" ' Save ipconfig info to temporary file wsh.Run "%comspec% /c ipconfig > " & TempFil, 0, True With RegEx .Pattern = "(\d{1,3}\.){3}\d{1,3}" .Global = False End With Set fil = FSO.GetFile(TempFil) ' Access temporary file Set ts = fil.OpenAsTextStream(1) txtAll = ts.ReadAll Set RegM = RegEx.Execute(txtAll) ' Return IP address to Activesheet cell A1 by parsing text ActiveSheet.Range("A1").Value = RegM(0) ActiveSheet.Range("A1").EntireColumn.AutoFit ts.Close ' Remove temp file Kill TempFil Set ts = Nothing Set wsh = Nothing Set fil = Nothing Set FSO = Nothing Set RegM = Nothing Set RegEx = Nothing End Sub
در یک ماژول قرار بدید و ....کامنت
-
-
با سلام ضمن تبریک عید فطر
دستورات زیرتست شده در صورت خطا طبق عکس ارسالی تیک Objet ها را بزنید.
کد:Public Function getMyIP() 'Related Reference - Microsoft WMI Scripting V1.2 Library (wbemdisp.TLB) 'Define Variable Data Types Dim objWMI As Object Dim objQuery As Object Dim objQueryItem As Object Dim vIpAddress 'Create WMI Object Set objWMI = GetObject("winmgmts:\\.\root\cimv2") 'Query WMI Set objQuery = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True") 'Loop Thru all assigned IP Addresses For Each objQueryItem In objQuery Debug.Print vbCrLf & "All Assigned IP Addresses" For Each vIpAddress In objQueryItem.ipaddress Debug.Print "User IP - " & vIpAddress MsgBox "User IP - " & vIpAddress Next Next End Function
پایدار باشید میرکامنت
-
-




کامنت