By Request VBS Script To Split Forward Space Separated Stings

 

This By Request VBS Script will provide you with an example of how to separate WMI Class stings that are separated by forward spaces (\). The user also requested a simple way to reverse the output and that script is included as well.

 

VBS Script:

 

strComputer = "."

 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objItem in colItems

 

ArrayName = Split(objItem.UserName, "\")

MsgBox ArrayName(0) 'DomainName

MsgBox ArrayName(1) 'User Name

 

Next

 

  • To reverse the order to display the user name and then the domain name use this:

strComputer = "."

 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each objItem in colItems

 

ArrayName = Split(objItem.UserName, "\")

MsgBox ArrayName(1) 'User Name

MsgBox ArrayName(0) 'DomainName

 

Next

 

 

Published Sunday, September 28, 2008 1:46 PM by dhite
Filed under:

Comments

No Comments