Skip to main content
added 120 characters in body
Source Link

SORRY IF THIS IS CONSIDERED A REPOST, I DID DELETE THIS FROM THE PROGRAMMER STACK.

I am usually a silent user of this website. Picking bits and pieces of your code to better educate myself on the different ways of programming things.

I have run into a wall with VBScript, and I'm not sure how to word my issue.

I am trying to write the IP addresses of a computer (all of them) to a text file.

If you run the code below, it will output your computer's IP addresses (ipv6 and ipv4, or whatever you have active).

I want this to be written to a text file, but when I use a Scripting.FileSystemObject

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile(CurrentDirectory & "\" & SN.SerialNumber & ".txt",2,true)

I cannot simply do

objFileToWrite(strIP)

Any thoughts? This is still a work in progress, so I know my code is sloppy, so please be nice on that. This is kind of a mashup of 3-4 different code sources, and I have little idea of how VBScript works yet. I am trying to learn though!

Any help would be greatly appreciated.

'************Where I left off.  Issue is converting object to String?
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If IsArray( objItem.IPAddress ) Then
        If UBound( objItem.IPAddress ) = 0 Then
            strIP = "IP Address: " & objItem.IPAddress(0)
        Else
            strIP = "IPv4 and IPv6 Addresses: " & vbCrLf & Join(objItem.IPAddress, vbCrLf )
        End If
    End If
Next

WScript.Echo(strIP)

Update: @Noodles Apparently I don't have enough Rep to add pics?

SORRY IF THIS IS CONSIDERED A REPOST, I DID DELETE THIS FROM THE PROGRAMMER STACK.

I am usually a silent user of this website. Picking bits and pieces of your code to better educate myself on the different ways of programming things.

I have run into a wall with VBScript, and I'm not sure how to word my issue.

I am trying to write the IP addresses of a computer (all of them) to a text file.

If you run the code below, it will output your computer's IP addresses (ipv6 and ipv4, or whatever you have active).

I want this to be written to a text file, but when I use a Scripting.FileSystemObject

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile(CurrentDirectory & "\" & SN.SerialNumber & ".txt",2,true)

I cannot simply do

objFileToWrite(strIP)

Any thoughts? This is still a work in progress, so I know my code is sloppy, so please be nice on that. This is kind of a mashup of 3-4 different code sources, and I have little idea of how VBScript works yet. I am trying to learn though!

Any help would be greatly appreciated.

'************Where I left off.  Issue is converting object to String?
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If IsArray( objItem.IPAddress ) Then
        If UBound( objItem.IPAddress ) = 0 Then
            strIP = "IP Address: " & objItem.IPAddress(0)
        Else
            strIP = "IPv4 and IPv6 Addresses: " & vbCrLf & Join(objItem.IPAddress, vbCrLf )
        End If
    End If
Next

WScript.Echo(strIP)

SORRY IF THIS IS CONSIDERED A REPOST, I DID DELETE THIS FROM THE PROGRAMMER STACK.

I am usually a silent user of this website. Picking bits and pieces of your code to better educate myself on the different ways of programming things.

I have run into a wall with VBScript, and I'm not sure how to word my issue.

I am trying to write the IP addresses of a computer (all of them) to a text file.

If you run the code below, it will output your computer's IP addresses (ipv6 and ipv4, or whatever you have active).

I want this to be written to a text file, but when I use a Scripting.FileSystemObject

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile(CurrentDirectory & "\" & SN.SerialNumber & ".txt",2,true)

I cannot simply do

objFileToWrite(strIP)

Any thoughts? This is still a work in progress, so I know my code is sloppy, so please be nice on that. This is kind of a mashup of 3-4 different code sources, and I have little idea of how VBScript works yet. I am trying to learn though!

Any help would be greatly appreciated.

'************Where I left off.  Issue is converting object to String?
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If IsArray( objItem.IPAddress ) Then
        If UBound( objItem.IPAddress ) = 0 Then
            strIP = "IP Address: " & objItem.IPAddress(0)
        Else
            strIP = "IPv4 and IPv6 Addresses: " & vbCrLf & Join(objItem.IPAddress, vbCrLf )
        End If
    End If
Next

WScript.Echo(strIP)

Update: @Noodles Apparently I don't have enough Rep to add pics?

Source Link

VBScript Converting Object to String?

SORRY IF THIS IS CONSIDERED A REPOST, I DID DELETE THIS FROM THE PROGRAMMER STACK.

I am usually a silent user of this website. Picking bits and pieces of your code to better educate myself on the different ways of programming things.

I have run into a wall with VBScript, and I'm not sure how to word my issue.

I am trying to write the IP addresses of a computer (all of them) to a text file.

If you run the code below, it will output your computer's IP addresses (ipv6 and ipv4, or whatever you have active).

I want this to be written to a text file, but when I use a Scripting.FileSystemObject

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile(CurrentDirectory & "\" & SN.SerialNumber & ".txt",2,true)

I cannot simply do

objFileToWrite(strIP)

Any thoughts? This is still a work in progress, so I know my code is sloppy, so please be nice on that. This is kind of a mashup of 3-4 different code sources, and I have little idea of how VBScript works yet. I am trying to learn though!

Any help would be greatly appreciated.

'************Where I left off.  Issue is converting object to String?
Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If IsArray( objItem.IPAddress ) Then
        If UBound( objItem.IPAddress ) = 0 Then
            strIP = "IP Address: " & objItem.IPAddress(0)
        Else
            strIP = "IPv4 and IPv6 Addresses: " & vbCrLf & Join(objItem.IPAddress, vbCrLf )
        End If
    End If
Next

WScript.Echo(strIP)