Re: setting an environment variable to the current IP
- From: "SuperGumby [SBS MVP]" <not@xxxxxxxxxxx>
- Date: Mon, 27 Mar 2006 08:35:08 +1100
OK, final (sortta) script
---------------------
On Error Resume Next
DIM EnvName
EnvName = "CurrentIPs" ' environment variable name
set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!"&_
"root\cimv2").ExecQuery("SELECT IPAddress, DefaultIPGateway FROM "&_
"Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")
Set WshShell = Wscript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment ("System")
If Err <> 0 Then
if err.number = -2147217405 then
MsgBox(" Error 0x80041003: Access Denied: Check permissions and file
security for this ASP file.")
else
MsgBox("Error description:"& Err.description &"error number "&
Err.number)
end if
end if
' First set the variable to null
WshEnv (EnvName) =""
for each IPConfig in IPConfigSet
if Not IsNull(IPConfig.IPAddress) then
for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
' MsgBox(" IP Address:"&IPConfig.IPAddress(i))
' now append the environment variable with IP info
WshEnv (EnvName) = WshEnv (EnvName) + IPConfig.IPAddress(i) + "/"
next
end if
if Not IsNull(IPConfig.DefaultIPGateway) then
for i=LBound(IPConfig.DefaultIPGateway) to
UBound(IPConfig.DefaultIPGateway)
' MsgBox("Default IP Gateway: "& IPConfig.DefaultIPGateway(i))
' and append gateway info
WshEnv (EnvName) = WshEnv (EnvName) + IPConfig.DefaultIPGateway(i) + " "
next
end if
next
If Err <> 0 Then
MsgBox("error description:"& Err.description &"error number "&
Err.number)
end if
---------------------
Once this has been executed there is an environment variable "CurrentIPs" in
the format:
IP1/gateway IP2/gateway etc...
Eg CurrentIPs=10.0.0.1/10.0.0.138 192.168.250.100/192.168.250.2
tks ur assistance
"SuperGumby [SBS MVP]" <not@xxxxxxxxxxx> wrote in message
news:OT4iabEUGHA.4792@xxxxxxxxxxxxxxxxxxxxxxx
tks Slim,
I have enough vbs to have been able to see what the script does, repair
the wraps, and she runs, giving me dialogue boxes for IP and gateway (an
add that may be handy, tks).
I suppose I need to do some legwork to replace 'MsgBox(" IP
Address:"&IPConfig.IPAddress(i))' with code that will write the info to an
environment variable. Assuming, of course, that vbs can, which in my
ignorance I have no idea about.
don't use Google for the next while, it'll be busy satisfying my
queries :-)
"Slim" <me@xxxxxxxx> wrote in message
news:%23TW%23hTDUGHA.3888@xxxxxxxxxxxxxxxxxxxxxxx
Sorry the first answer was for ASP
forgot what group I was on
On Error Resume Next
set IPConfigSet =
GetObject("winmgmts:{impersonationLevel=impersonate}!"&_
"root\cimv2").ExecQuery("SELECT IPAddress, DefaultIPGateway FROM "&_
"Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")
If Err <> 0 Then
if err.number = -2147217405 then
MsgBox(" Error 0x80041003: Access Denied: Check permissions and
file security for this ASP file.")
else
MsgBox("Error description:"& Err.description &"error number "&
Err.number)
end if
end if
for each IPConfig in IPConfigSet
if Not IsNull(IPConfig.IPAddress) then
for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
MsgBox(" IP Address:"&IPConfig.IPAddress(i))
next
end if
if Not IsNull(IPConfig.DefaultIPGateway) then
for i=LBound(IPConfig.DefaultIPGateway) to
UBound(IPConfig.DefaultIPGateway)
MsgBox("Default IP Gateway: "& IPConfig.DefaultIPGateway(i))
next
end if
next
If Err <> 0 Then
MsgBox("error description:"& Err.description &"error number "&
Err.number)
end if
"SuperGumby [SBS MVP]" <not@xxxxxxxxxxx> wrote in message
news:e7%23Knj5TGHA.2444@xxxxxxxxxxxxxxxxxxxxxxx
hopefully something quick and easy for you guys, I'm totally unfamiliar
with scripting.
all I need is to set an environment variable, say,
currentIP=192.168.1.123 when the PC is getting an IP via DHCP
Handy if it works on 2000/XP/2003
Handy if it handles multiple interfaces (eg. currentIP=192.168.0.11,
192.168.32.345)
TIA
.
- Follow-Ups:
- References:
- setting an environment variable to the current IP
- From: SuperGumby [SBS MVP]
- Re: setting an environment variable to the current IP
- From: Slim
- Re: setting an environment variable to the current IP
- From: SuperGumby [SBS MVP]
- setting an environment variable to the current IP
- Prev by Date: Need regular expression to match a word or phrase in anchor tag
- Next by Date: Re: "Log" to HTML File
- Previous by thread: Re: setting an environment variable to the current IP
- Next by thread: Re: setting an environment variable to the current IP
- Index(es):
Relevant Pages
|