?
Solved

run VBS from ASP page

Posted on 2006-06-07
16
Medium Priority
?
289 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:ellandrd
  • 7
  • 7
  • 2
16 Comments
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16850707
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
 
LVL 16

Author Comment

by:ellandrd
ID: 16850712
Richard, ASP isnt my strong point so looking at that makes no sense...
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16850741
Ha.

Me neither.

But, assuming you only have 1 parameter

Dim StrComputer
StrComputer = Command$

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Author Comment

by:ellandrd
ID: 16850763
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
 
LVL 11

Expert Comment

by:kelvinwkw
ID: 16850803
this shuold get you the ip address
Dim StrComputer
strComputer = request.serverVariables("remote_addr")
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16850815
undefined variable request
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16850823
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16850863
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
 
LVL 16

Author Comment

by:ellandrd
ID: 16850874
i still dont understand:  strComputer = Command$ ?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16850877
how can i run a shell script in ASP?
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16850883
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16850887
ellandrd, are you taking the piss?
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16850913
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
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 1600 total points
ID: 16850921
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
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16850932
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
 
LVL 11

Assisted Solution

by:kelvinwkw
kelvinwkw earned 400 total points
ID: 16851038
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Screencast - Getting to Know the Pipeline
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 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