/* class ShowShares shows Windows shared resources for Win95, NT4 and Win2000. Win95, 98: Launches application "netwatch.exe" WinNT, Win2000: writes local file "C:/temp/$$migshowshare.bat" executes batch file Code for IE4 or Netscape (requires signed CAB for IE and signed JAR for Netscape). M. Gallant 01/09/2001 */ import com.ms.security.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.* ; import java.util.*; import netscape.security.PrivilegeManager; public class ShowShares extends Applet implements ActionListener { int strings = 0; private Button clearbutton = new Button("Clear") ; private Button sendbutton = new Button("Show Shares") ; private TextArea statustext = new TextArea (3, 40); private PrintWriter pwrite = null ; private BufferedReader dis = null; private String thecommand = "" ; private static String batchcommand = "cmd /K net share" ; private static String sendcommand = "C:/temp/$$migshowshare.bat" ; // temp batch for for NT/Win2000 public void init() { try { if (Class.forName("com.ms.security.PolicyEngine") != null) { // required for IE PolicyEngine.assertPermission(PermissionID.SYSTEM); } } catch (Throwable cnfe) { } this.setBackground(new Color(153,204,255)) ; // light blue add(sendbutton) ; add(clearbutton); add(statustext) ; sendbutton.setBackground(Color.red) ; clearbutton.setBackground(Color.white) ; statustext.setBackground(Color.gray) ; sendbutton.addActionListener(this) ; clearbutton.addActionListener(this) ; try{ PrivilegeManager.enablePrivilege("UniversalFileAccess") ; // required for NN PrivilegeManager.enablePrivilege("UniversalExecAccess") ; // required for NN } catch(Exception cnfe) { // System.out.println("netscape.security.PrivilegeManager class not found") ; } } public void actionPerformed(ActionEvent e) { if( (e.getActionCommand()).equals("Clear")) { statustext.setText("") ; } else if( (e.getActionCommand()).equals("Show Shares")) { try{ PrivilegeManager.enablePrivilege("UniversalFileAccess") ; // required for NN PrivilegeManager.enablePrivilege("UniversalExecAccess") ; // required for NN } catch(Exception cnfe) { // System.out.println("netscape.security.PrivilegeManager class not found") ; } try { if(!(System.getProperty("os.name").equals("Windows NT") || System.getProperty("os.name").equals("Windows 2000"))) { // if NOT NT or Win2000, adjust path statustext.setText("Win95 or Win98 platform\nTrying to launch \"netwatch.exe\" ... \n") ; thecommand = "C:\\Windows\\netwatch.exe" ; if(!(new File(thecommand)).exists()){ statustext.append(thecommand + " file not found.") ; return; } Process proc = Runtime.getRuntime().exec(thecommand) ; return; } else { thecommand = sendcommand ; statustext.setText("WinNT or Win2000 platform\nTrying to run \"net share\" ... \n") ; pwrite = new PrintWriter(new BufferedWriter(new FileWriter(sendcommand))) ; // write batch file pwrite.println(batchcommand) ; // one line batch file to run net share command. pwrite.close() ; Process proc = Runtime.getRuntime().exec(thecommand) ; } } catch(Exception ioe) { statustext.setText("Problem starting " + thecommand + "\n") ; System.out.println("Problem starting " + thecommand) ; } finally { try{ if(pwrite!=null) pwrite.close() ; } catch (Exception ioe) { } } // end finally } // end if } // end actionPerformed public void paint(Graphics g) { // draw black border-line around applet g.setColor(Color.black) ; g.drawRect(0,0,this.getSize().width-1, this.getSize().height-1) ; } }