Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default 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))


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default 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))




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default 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))






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default 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))








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hide Command Shell window Corey Excel Programming 0 November 20th 06 06:08 AM
Hide Window Caption Bar Mats Nilsson Excel Programming 4 August 28th 06 07:02 PM
How do I undo the Excel, Window Menu, New Window command OLDFANG Excel Discussion (Misc queries) 2 March 17th 06 05:31 PM
using WScript.CreateObject("Wscript.Shell John Keith[_2_] Excel Programming 3 August 30th 05 07:20 PM
Practical use of Window Hide Tetsuya Oguma[_4_] Excel Programming 1 August 5th 04 06:50 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"