Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

How to run a .vbs file using JSP


  • Please log in to reply

#1
jayeth

jayeth

    Member

  • Member
  • PipPip
  • 18 posts
Hi Guys,
i've developed chat program using Swing named server.java and clientRunner.java..
i created a batch file(one 4 each server.bat & client.bat) to execute that java file so that i donnt have to open the commad prompt and run it using tat everytime...then i wanted that batch file to run with command prompt hidden so i created .vbs file(again one 4 each server.vbs & client.vbs)..
so then i executed this file using java code..it worked but i want to run it with jsp file...then i embedded that java code in jsp and i run that file using Netbeans 6.5..the browser window opens but nothing happens...if not with jsp atleast help me with executing .vbs file using html...i tried with form action but i jus displays the code ...pls help me :) :)

Edited by jayeth, 10 March 2009 - 09:22 AM.

  • 0

Advertisements


#2
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 31,676 posts
Hi jayeth,

I hope an example how you can run a VBscript in a html page will get you going again:

<html>
<head>
</head>
<body>
<script type="text/vbscript">
<!--
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set objAccount = objWMIService.Get _
  ("Win32_SID.SID='S-1-5-21-220523388-1844823847-682003330-500'")
document.write(objAccount.AccountName)
-->
</script>
</body>
</html>

The script get's the name of the useraccount that belongs to that SID.
To get a result the SID has to exist on your computer.
  • 0

#3
jayeth

jayeth

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
Hi Metallica,
i created an html file and added the script code of client.vbs file to it...
---------------------

<html>
<head>
</head>
<body>
<script type="text/vbscript">
<!--
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "f:/code_proj/pendir/chatt/final/client/client.bat" & Chr(34),0
Set WshShell = Nothing
-->
</body>
</html>

----------------------
it shows some syntax error...wat shud i do?
  • 0

#4
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 31,676 posts
Can you post the exact text of the syntax error?

I think it should be:
<!-- 
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run("f:/code_proj/pendir/chatt/final/client/client.bat",0,False)
Set WshShell = Nothing
-->

but I can't test it here.
  • 0

#5
jayeth

jayeth

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
i've changed the code like you said and tried running it, still i get the same error..when i tried openning the html file by dbl clickin it i got the error like the on in net2.jpg and when i used NetBeans, i got the error like the one in net.jsp...

PS:i've attached the net and net2 image files...pls chk

Attached Thumbnails

  • net.JPG
  • net2.JPG

  • 0

#6
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 31,676 posts
missing ; before statement looks to me like the program expects it to be a comment
I'm not familiar with that program so I could be wrong.

And the file not found could be about the bat you are trying to run. Did you make sure that the path is correct?



I
  • 0

#7
jayeth

jayeth

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
actually he html file is in a different folder and the bat file is in different one..so tat's y i gave the full address..n i rechecked the address..it is correct..
  • 0

#8
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 31,676 posts
Line 7 is the line where we point it to the .bat

If you paste this in the Command prompt
f:/code_proj/pendir/chatt/final/client/client.bat
does the file run?
  • 0

#9
jayeth

jayeth

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
yes...it does
  • 0

#10
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 31,676 posts
OK that rules that out. I'll have to do some testing when I get home. (a few hours from now)
I'll post back later.
  • 0

Advertisements


#11
jayeth

jayeth

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
Thank you so much :)
  • 0

#12
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 31,676 posts
Looks like I put you on the wrong track. :)

This works for me:
<html>
<head>
</head>
<body>
<script type="text/vbscript">
<!-- 
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "f:\code_proj\pendir\chatt\final\client\client.bat",0
Set WshShell = Nothing
-->
</script>
</body>
</html>

  • 0

#13
jayeth

jayeth

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
i tried your code...didn't work in mine :) ...
i found this site http://weblogs.asp.n...3/14/89240.aspx...
and i followed it... then it throwed
object cannot be created "WScript.Shell"...
so i added the localhost to the list of trusted sites in explorer...now i'm gettin a blank page..
i found that wen i run this bat file, it is openin C:\ desktop and tryin to run that file from there n so it displays
cannot find the specified file :) ...
how do i correct this? :)

Attached Thumbnails

  • bat_file_error.JPG
  • add_localhost_trusted_site.JPG

Edited by jayeth, 13 March 2009 - 01:51 AM.

  • 0

#14
Metallica

Metallica

    Spyware Veteran

  • GeekU Moderator
  • 31,676 posts
Looks to me like the error is thrown when the bat starts the java.
I must admit that I don't understand why it would run if you execute it directly and fail when we call it from the html file. :)
  • 0

#15
jayeth

jayeth

    Member

  • Topic Starter
  • Member
  • PipPip
  • 18 posts
i found tat wen i run the bat file directly by dbl clickin it, it open with the path
f:/code_proj/pendir/chatt/final/client/
but wen i run it through html file it opens with te path
C:\Documents and Settings\All Users\Desktop
n run te file n tat's y it says file not found...
now te problem is ...i donno how to make te bat file open wit te path
f:/code_proj/pendir/chatt/final/client/client.bat...

sry 2 bother u...pls do help me..i need 2 finish my proj by nxt month...i'm caught in this 4 a long time..
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP