Local call

xiaoxiao2021-03-05  28

This program is an implementation of some commands in the local Windows, which is very easy, just use Runtime.Getruntime (). EXEC, the calls in the program can be found in System32, for the program installed by the user, only need to get The mounting path of the program, then calls the above method, the principle is the same. (This program is not implemented, don't want to write, the principle is the same)

Source code:

Localexe.java

Package Localexe;

Import java.awt. *; import java.awt.event. *; import javax.swing. *; import javax.swing.event. *;

public class LocalEXE {private JFrame mainF; private DefaultListModel LModel = new DefaultListModel (); private JMenuItem infoMI; public LocalEXE () {mainF = new JFrame (); mainF.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); addMenu (); loadInfo (); Createlist (); showframe ();} private void addmenu () {jmenubar mainmb = new jmenubar (); mainf.setjmenubar (mainmb); jMenu helpm = new jmenu ("help"); mainmb.add (helpm); infomi = NEW JMENUITEM ("info"); infromi.addactionListener (new menul ()); Helpm.Add (Infomi);} private void showframe () {mainf.settitle ("localexe"); mainf.setsize (500, 400); mainf. Setresizable (false); mainf.setlocation (200,100); mainf.setvisible (TRUE);} private void () {EXEINTERFACE EXEI; String Name, address; name = new string ("calculator"); address = new string "Calc.exe"); Exei = New ExeInterface (name, address); lmodel.addelement (exei); name = new string; address = new string ("freecell.exe"); EXI = New EXEI NTERface (name, address); lmodel.addelement (exei); name = new string ("Media Player"); address = new string ("mplay32.exe"); EXI = New ExeInterface (Name, Address); LMODEL. Addelement (Exei); Name = New String ("Red Heart Wars"); address = new string ("mshearts.exe"); EXI = New ExeInterface (name, address); lmodel.addelement (exei); name = new string "Draw Tool"); Address = New String ("mspaint.exe"); EXI = New ExeInterface (name, address); lmodel.addelement (exei); name = new string; address = new string ("Notepad.exe"); EXI =

New EXEINTERFACE (Name, Address); LMODEL.ADDELEMENT (EXEI); Name = New String ("mine"); address = new string ("WINMINE.EXE"); Exei = New EXEINTERFACE (Name, Address); lmodel.addelement (EXEI); name = new string ("Registry"); address = new string ("regedt32.exe"); Exei = New EXEINTERFACE (Name, Address); lmodel.addelement (exei);} private void createlist () {final JList sList = new JList (LModel); final JTextArea sTA = new JTextArea (8,15); JSplitPane sPane = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, new JScrollPane (sList), new JScrollPane (sTA)); sPane.setBackground ( Color.WHITE); sPane.setContinuousLayout (true); sPane.setOneTouchExpandable (true); mainF.getContentPane () add (sPane);. sList.addListSelectionListener (new ListSelectionListener () {int executeTime = 0; public void valueChanged (ListSelectionEvent event ) {EXEINTERFACE value = (exeinterface) slist.getSelectedValue (); if (value! = Null) {EXECUTETIME ; System.out.println (ExecuteTime); if (ExecuteTime% 2 == 0) {sta.settext (""); sta.settext ("System Load" value.getname ()); try {process subp = runtime. GetRuntime (). EXEC (Value.GetDress ());} catch (Exception E) {system.out.println ("Runtime Exe Error!"); Sta.Settext ("Runtime Error!"); E.PrintStackTrace );}}} If (executetime == 10) Executetime = 0;}});

} Class MenuL implements ActionListener {public void actionPerformed (ActionEvent e) {Object command = e.getSource (); if (command == infoMI) {infoDlg ();}} public void infoDlg () {JPanel msgP = new JPanel () Msgp.setLayout (New GridLayout (3, 1)); Msgp.Add (New Jlabel ("Author: Pluto")); Msgp.Add (New Jlabel ("Date: 2005.4")); msgp.add (New Jlabel ("Site: BJTU15 #")); JOPTIONPANE.SHOWMESSAGEDIALOG (NULL, MSGP, "INFO", JOPTIONPANE.YES_OPTION;}} public static void main (String [] args) {new localexe ();}} exeinterface.java

Package Localexe;

class EXEInterface {private String name, address; public EXEInterface (String name, String address) {this.name = name; this.address = address;} public String getName () {return name;} public String getAddress () {return address } Public string toString () {return name;}}

转载请注明原文地址:https://www.9cbs.com/read-35834.html

New Post(0)