run VBS from ASP page

ok i have .vbs file called test.vbs.  how can i execute/run this first of all?

secondly my test.vbs file taken 1 parameter:

Dim StrComputer
strComputer = "192.168.0.79"

as you can see i have hardcoded a IP address into it.  How can i do this without hardcoding it into the test.vbs?

can i somehow pass my remote ipaddress to it?
LVL 16
ellandrdAsked:
Who is Participating?
 
Richard QuadlingSenior Software DeveloperCommented:
Sorry. I don't use any of the MS stuff, but ASP IS VB!!!!

What I don't understand is why the separation of the 2 files.

Take the VBS file and just put it into the ASP file.

Now you don't need to "run vbs from asp".
0
 
Richard QuadlingSenior Software DeveloperCommented:
http://www.devx.com/getHelpOn/10MinuteSolution/20366 contains all the juicy info on getting command line parameters into your vb script.

Enjoy!

Here is the code ...

Sub Main()
   Dim a_strArgs() As String
   Dim blnDebug As Boolean
   Dim strFilename As String
   
   Dim i As Integer
   
   a_strArgs = Split(Command$, " ")
   For i = LBound(a_strArgs) To UBound(a_strArgs)
      Select Case LCase(a_strArgs(i))
      Case "-d", "/d"
      ' debug mode
         blnDebug = True
      Case "-f", "/f"
      ' filename specified
         If i = UBound(a_strArgs) Then
            MsgBox "Filename not specified."
         Else
            i = i + 1
         End If
         If Left(a_strArgs(i), 1) = "-" Or Left(a_strArgs(i), 1) = "/" Then
            MsgBox "Invalid filename."
         Else
            strFilename = a_strArgs(i)
         End If
      Case Else
         MsgBox "Invalid argument: " & a_strArgs(i)
      End Select
     
   Next i
   MsgBox "Debug mode: " & blnDebug
   MsgBox "Filename: " & strFilename
End Sub
0
 
ellandrdAuthor Commented:
Richard, ASP isnt my strong point so looking at that makes no sense...
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Richard QuadlingSenior Software DeveloperCommented:
Ha.

Me neither.

But, assuming you only have 1 parameter

Dim StrComputer
StrComputer = Command$

0
 
ellandrdAuthor Commented:
im shaking my head as im lost.

i have a .vbs file my boss created.  i want to pass my .vbs file a ip address using ASP and then run my .vbs file?
0
 
kelvinwkwCommented:
this shuold get you the ip address
Dim StrComputer
strComputer = request.serverVariables("remote_addr")
0
 
ellandrdAuthor Commented:
undefined variable request
0
 
ellandrdAuthor Commented:
i dont have a ASP page yet.

i only have a .vbs file:

test.vbs
===========

Option Explicit

Dim StrComputer
strComputer = request.serverVariables("remote_addr")

i need a ASP page that will pass test.vbs remote IP address and run test.vbs.

i cant code very well in ASP so i need alot of help...
0
 
Richard QuadlingSenior Software DeveloperCommented:
test.vbs
===========

Option Explicit

Dim StrComputer
strComputer = Command$


Now all you need is to be able to call

test.vbs 10.0.0.1

from ASP.

This would be some sort of shell execute function (Shell maybe)

shell("test.vbs " & your_ip_address_here_by_whatever_means_necessary)

maybe.
0
 
ellandrdAuthor Commented:
i still dont understand:  strComputer = Command$ ?
0
 
ellandrdAuthor Commented:
how can i run a shell script in ASP?
0
 
Richard QuadlingSenior Software DeveloperCommented:
What don't you understand!!!

That is the code!!!!

strComputer = Command$

Command$ is the command line arguments!!!!

As you are only passing 1 parameter, the entire string can be used.

End of problem.

So, if you run ...

test.vbs 1.2.3.4

and test.vbs is

strComputer = Command$

then strComputer will be "1.2.3.4"

See?
0
 
Richard QuadlingSenior Software DeveloperCommented:
ellandrd, are you taking the piss?
0
 
ellandrdAuthor Commented:
richard

no im not taking the piss!  its easy for you as you understand, but for me, i do code in ASP or VBS so its a little harder to take in first time round..
0
 
Richard QuadlingSenior Software DeveloperCommented:
ASP uses VB as the language. VB is just another language. Add web functionality to it and you have ASP. Add browser DOM to it and you have browser client-side VBScript scripting language. Add MS Word support and you have VBA for MS Word.

Just a language.

0
 
kelvinwkwCommented:
On Error Resume Next

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

Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE")

For Each objItem in colItems
    For Each strIPAddress in objItem.IPAddress
        Wscript.Echo "IPAddress: " & strIPAddress
    Next
Next

this will return u ur pc's ip
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.