Input/Output VBS-Datein mit Java Ausführen

arca20

Neues Mitglied
Hallo ihr lieben,

ich möchte eine kleine Programm schreiben, die einige Scripte mit sich bringt, das heiß JButton klicken die da die Skripte ausführt. Ich weiß nicht was an meinem Code falsch ist.
Java:
package InfoProgramm;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;

public class InfoProgramm {

    private JFrame frame;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    InfoProgramm window = new InfoProgramm();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public InfoProgramm() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
        JPanel panel = new JPanel();
        frame.getContentPane().add(panel, BorderLayout.CENTER);
       
        JButton btnRaminfo = new JButton("RamInfo");
        btnRaminfo.addActionListener(ae -> startRamInfo());
        panel.add(btnRaminfo);
    }
   
    public void startRamInfo() {
          try {
              String raminfo = getClass().getResource("/InfoProgramm/ramInfo.vbs").getFile();
              System.out.println(raminfo);
              Runtime.getRuntime().exec(("wscript "+ raminfo));
           }
           catch( IOException e ) {
              System.out.println(e);
              System.exit(0);
           }       
    }

}

Die Fehlermeldung ist das es ein falsche Pfad gegebn wird, das Tool soll mitgenommen werden.
So wird der Pfad angenommen.
/C:/Users/*****/eclipse_project/InfoProgramm/bin/InfoProgramm/ramInfo.vbs
 
Wenn ich mich nicht irre, ist das ausführen der in der jar gepackten Dateien so nicht möglich. Du müsstest die erst irgendwo außerhalb ablegen und kannst sie dann ausführen.
 

Neue Themen


Zurück
Oben