Unexpected regex results and script error

3 posts · Closed

rmpf2 Guest
9 Feb 2024
  1. I'm testing some regular expressions, but the results are unexpected. Can you give me a hand and tell me what I'm doing wrong? Especially with the Replacement Expression for Columns Display Options.

Example:

Regex for MAC Address:

([A-Za-z0-9]{2})([A-Za-z0-9]{2}).([A-Za-z0-9]{2})([A-Za-z0-9]{2}).([A-Za-z0-9]{2})([A-Za-z0-9]{2})

Regex Replacement:

\1-\2-\3-\4-\5-\6

To change MAC Address format from f8b1.56e0.0e07 to f8-b1-56-e0-0e-07.

  1. I'm trying to adapt the Packet Loss Script (Ping Example) to check for computers' license status, especially to find out if they are activated, but I'm lost with the following error message: Invalid procedure call or argument.

Script:

'Create process object and execute
Set proc = Internal.CreateObject("process")
proc.execute("cscript.exe " & "//nologo " & "c:\windows\system32\slmgr.vbs " & Input.Column("Host name") & " -xpr")

'Check cscript exit code
If proc.ExitCode = 0 Then

    'Setup a regex object
  Set objRegex = New RegExp
  objRegex.IgnoreCase = True
  objRegex.Multiline = True
  objRegex.Global = True
  'Regex to look for a specific string
  objRegex.Pattern = "activated"

'Traverse output lines
  For Each line in proc.output
    Set matches = objRegex.Execute(line)
      
           'Print regex match
    For Each match in matches
         Output.Write match.SubMatches(0)
    Next
  Next
Else
  Output.Write "Exit code " & proc.ExitCode
End If

Thanks!!

Andrew SoftPerfect
10 Feb 2024

1) Network Scanner uses a slightly different syntax for backreferences. Like JavaScript, Python and Perl, it uses $1 $2 $3 instead of \1 \2 \3.

Simply replace

\1-\2-\3-\4-\5-\6

with the following, and it should work as expected:

$1-$2-$3-$4-$5-$6

2) Regarding the script, try the following modifications. It uses a capture group to collect any associated information and trims the output:

'Create process object and execute
Set proc = Internal.CreateObject("process")
proc.execute("cscript.exe " & "//nologo " & "c:\windows\system32\slmgr.vbs " & Input.Column("Host name") & " -xpr")
'Check cscript exit code
If proc.ExitCode = 0 Then
    
    'Setup a regex object
    Set objRegex = New RegExp
    objRegex.IgnoreCase = True
    objRegex.Multiline = True
    objRegex.Global = True
    'Regex to look for a specific string
    objRegex.Pattern = "(.+activated.+)"
    
    'Traverse output lines
    For Each line In proc.output
        Set matches = objRegex.Execute(line)
        'Print regex match
        For Each match In matches
            Output.Write Trim(match.SubMatches(0))
        Next
    Next
Else
    Output.Write "Exit code " & proc.ExitCode
End If

Here on our machine it prints:

The machine is permanently activated.
rmpf2 Guest
13 Feb 2024

Hi Andrew.

Thanks for all your help.

This topic is closed. It has had no new posts for over a year, so the software versions it talks about may be out of date. Start a new topic in Network Scanner if you have a similar question.