ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hide WScript Command window (https://www.excelbanter.com/excel-programming/421721-hide-wscript-command-window.html)

AP[_3_]

Hide WScript Command window
 
This code gives the IP address of the computer. It however displays a
command window momentarily. How can I prevent the window from being
displayed ? Thanks.

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("%comspec% /c ipconfig")

Do While oExec.stdOut.AtEndOfStream < True
StrLine = oExec.stdOut.Readline

If InStr(StrLine, "Address") 0 Then
'found
strIP = StrLine
Exit Do
End If
Loop

MsgBox Mid(strIP, (InStr(strIP, ":") + 2))



Steve Yandl[_2_]

Hide WScript Command window
 
Below is a routine that won't eliminate the appearance of the console window
but will limit it's duration to a shorter time (probably a second or less).
Basically, you don't need the %comspec% in your command line.

'-------------------------------------

Set objShell = CreateObject("WScript.Shell")

Set objWshExec = objShell.Exec("ipconfig")

Set objStdOut = objWshExec.StdOut

Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
If Instr(strLine, "IP Address") 0 Then
arrText = Split(strLine, ":")
strIPaddress = arrText(1)
End If
Loop

MsgBox strIPaddress

'------------------------------------

If that is still too much, consider using WMI to retrieve the IP instead of
running ipconfig.

Steve Yandl



"AP" wrote in message
...
This code gives the IP address of the computer. It however displays a
command window momentarily. How can I prevent the window from being
displayed ? Thanks.

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("%comspec% /c ipconfig")

Do While oExec.stdOut.AtEndOfStream < True
StrLine = oExec.stdOut.Readline

If InStr(StrLine, "Address") 0 Then
'found
strIP = StrLine
Exit Do
End If
Loop

MsgBox Mid(strIP, (InStr(strIP, ":") + 2))





Steve Yandl[_2_]

Hide WScript Command window
 
Here is an option using WMI

Sub GetMyIpAddress()
Set objWMIService = GetObject("winmgmts:")
Set colNicConfig = objWMIService.ExecQuery("SELECT * FROM " & _
"Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objNicConfig In colNicConfig
If Not IsNull(objNicConfig.IPAddress) Then
For Each strIPAddress In objNicConfig.IPAddress
MsgBox strIPAddress
Next
End If
Next
End Sub


Steve Yandl




"Steve Yandl" wrote in message
...
Below is a routine that won't eliminate the appearance of the console
window but will limit it's duration to a shorter time (probably a second
or less). Basically, you don't need the %comspec% in your command line.

'-------------------------------------

Set objShell = CreateObject("WScript.Shell")

Set objWshExec = objShell.Exec("ipconfig")

Set objStdOut = objWshExec.StdOut

Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
If Instr(strLine, "IP Address") 0 Then
arrText = Split(strLine, ":")
strIPaddress = arrText(1)
End If
Loop

MsgBox strIPaddress

'------------------------------------

If that is still too much, consider using WMI to retrieve the IP instead
of running ipconfig.

Steve Yandl



"AP" wrote in message
...
This code gives the IP address of the computer. It however displays a
command window momentarily. How can I prevent the window from being
displayed ? Thanks.

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("%comspec% /c ipconfig")

Do While oExec.stdOut.AtEndOfStream < True
StrLine = oExec.stdOut.Readline

If InStr(StrLine, "Address") 0 Then
'found
strIP = StrLine
Exit Do
End If
Loop

MsgBox Mid(strIP, (InStr(strIP, ":") + 2))







AP[_3_]

Hide WScript Command window
 

Thanks Steve. It works beautifully.
Cheers,
Al

"Steve Yandl" wrote in message
...
Here is an option using WMI

Sub GetMyIpAddress()
Set objWMIService = GetObject("winmgmts:")
Set colNicConfig = objWMIService.ExecQuery("SELECT * FROM " & _
"Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objNicConfig In colNicConfig
If Not IsNull(objNicConfig.IPAddress) Then
For Each strIPAddress In objNicConfig.IPAddress
MsgBox strIPAddress
Next
End If
Next
End Sub


Steve Yandl




"Steve Yandl" wrote in message
...
Below is a routine that won't eliminate the appearance of the console
window but will limit it's duration to a shorter time (probably a second
or less). Basically, you don't need the %comspec% in your command line.

'-------------------------------------

Set objShell = CreateObject("WScript.Shell")

Set objWshExec = objShell.Exec("ipconfig")

Set objStdOut = objWshExec.StdOut

Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
If Instr(strLine, "IP Address") 0 Then
arrText = Split(strLine, ":")
strIPaddress = arrText(1)
End If
Loop

MsgBox strIPaddress

'------------------------------------

If that is still too much, consider using WMI to retrieve the IP instead
of running ipconfig.

Steve Yandl



"AP" wrote in message
...
This code gives the IP address of the computer. It however displays a
command window momentarily. How can I prevent the window from being
displayed ? Thanks.

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("%comspec% /c ipconfig")

Do While oExec.stdOut.AtEndOfStream < True
StrLine = oExec.stdOut.Readline

If InStr(StrLine, "Address") 0 Then
'found
strIP = StrLine
Exit Do
End If
Loop

MsgBox Mid(strIP, (InStr(strIP, ":") + 2))










All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com