Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1307
  • Last Modified:

problems with "shell" command, not running ".jar" files

 why the sheel command is not able to execute
the ".jar" files like ".exe" files even though they are
also exes but in terms of Java. What i want is, if user pushes
certain button on the form then a file,"abc.jar", should be executed.
Is there another way of doing it??

Thanx in advance
1 Solution
.jar files are NOT like .exe file to Windows's point of view ! .jar file can only be excuted via Java's VM.

So, if you want to shell a .jar file, try instead this kind of command:

shell "java myProg.jar"

I don't have any longer Sun's Java SDK on my machine, as far as i remember, but this should work.

You can find more options concerning java'c command line arguments into Sun's documentation.

Hope this helps.
go to MyComputer->View->Options->File Types

then under edit file type you can find the command that is being used to open a java file

for example, on my pc for a .pdf file I have under open

"C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe" "%1"

then if in VB I do

Shell "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe c:\download\sp35ug.pdf"

I launch the pdf in a reader.

Here is a great alternative for you. Just give it a path to your .exe or any other file that is associated with an application and it'll run it for you:
' create a new VB project
' Copy+Paste on a module
Private Declare Function ShellExecute _
   Lib "shell32.dll" Alias _
   "ShellExecuteA" (ByVal _
   hWnd As Long, ByVal lpOperation As _
   String, ByVal lpFile As String, _
   ByVal lpParameters As String, _
   ByVal lpDirectory As String, _
   ByVal nShowCmd As Long) As Long

' Copy+Paste into same module
Sub RunApp(frm As Form, strXLS As _
   String, intWindowStyle As Integer)

   Dim lngSuccess As Long

   'launch the default browser
   lngSuccess = ShellExecute( _
      frm.hWnd, "Open", _
      strXLS, 0&, 0&, intWindowStyle)

End Sub

'Create a button on a form and then copy+paste
Private Sub cmdRunApp_Click()
    Dim sPath As String
    sPath = InputBox("Enter path")
    RunApp Me, sPath, 1
End Sub
ashish_arpAuthor Commented:
hi deighton
 one more problem with shell. I'm running the shell function for compiling the java file as

shell "c:\jdk1.3.1_04\bin\javac.exe abc.java"

the function is not compiling the java file and not giving any error also. what must be the problem??


Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now