?
Solved

Passing parameters

Posted on 2013-05-19
3
Medium Priority
?
453 Views
Last Modified: 2013-05-19
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
0
Comment
Question by:Bianchi928
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Bill Prew earned 1000 total points
ID: 39179719
Give this a try.  You may want to add some editing if desired.

Of course, you could do it right in the BAT file to with:

set /P "IP=Please enter IP:"

strIP = Inputbox("IP address (xxx.xxx.xxx.xxx)", "Input Required")
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /C script.bat " & strIP), 1, True

Open in new window

~bp
0
 

Author Closing Comment

by:Bianchi928
ID: 39179735
Perfect. Thanks mate

Cheers
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 39179748
Welcome.

~bp
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month16 days, 21 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question