Avatar of Bianchi928
Bianchi928
 asked on

Passing parameters

I need a little bit of help there. I will like to call the attached batch file in a VBScript where I will prompt for an IP address and pass on the IP  (%1) to the batch file

@echo off
setlocal EnableDelayedExpansion
setlocal EnableExtensions

set IP=%1

REM Get Serial
call :DoSnmpGet "%IP%" ".1.3.6.1.4.1.11.2.3.9.4.2.1.1.3.3.0" "Serial"
REM If no serial found, try the XEROX MIB to see if it responds
if "!Serial!"=="N/A" (
  call :DoSnmpGet "%IP%" ".1.3.6.1.2.1.43.5.1.1.17.1" "Serial"
  REM If no serial found, try the RICOH MIB to see if it responds
  if "!Serial!"=="N/A" (
    call :DoSnmpGet "%IP%" ".1.3.6.1.4.1.367.3.2.1.2.1.4.0" "Serial"
    if NOT "!Serial!"=="N/A" (
      for /F "tokens=1 delims=," %%z in (!Serial!) do set Serial=%%z
      set Serial=!Serial:"=!
    )
  ) else (
    for /F "tokens=1 delims=," %%z in (!Serial!) do set Serial=%%z
    set Serial=!Serial:"=!
  )
)

echo Serial=%Serial%
pause

exit /b

:DoSnmpGet
  REM Use SNMPGET to fetch value for IP and MIB passed in, return in variable passed in
  set %~3=N/A
  for /F "tokens=1-3*" %%t in ('snmpget -O T -v 1 -c public %~1 %~2 2^>nul^|find "="') do (
    set SnmpgetResult=%%w
    if "%%v"=="Hex-STRING:" (
      set SnmpgetResult=!SnmpgetResult: =!
      for /F "tokens=2 delims=[.]" %%z in ("!SnmpgetResult!") do set SnmpgetResult=%%z
    )
    set %~3=!SnmpgetResult!
  )
  exit /b
VB Script

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Bill Prew

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bianchi928

ASKER
Perfect. Thanks mate

Cheers
Bill Prew

Welcome.

~bp
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes