Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Core Java Code Examples

List of users in the network

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
List of users in the network import java.io.*; public class NetworkUsers { public static void main(java.lang.String[] args) { StringBuffer strBuffer= new StringBuffer(); String line= null; try { Process process= Runtime.getRuntime().exec("cmd"); BufferedReader b= new BufferedReader(new InputStreamReader(process.getInputStream())); PrintWriter to= new PrintWriter(process.getOutputStream()); to.println("net view"); to.println("exit"); to.close(); try { // we need the process to end, else we'll get an // illegal Thread State Exception line= b.readLine(); while (line != null) { strBuffer.append(line+" "); line= b.readLine(); } process.waitFor(); } catch (InterruptedException inte) { System.out.println("InterruptedException Caught"); } if (process.exitValue() == 0) { System.out.println(strBuffer.toString()); } process.destroy(); } catch (IOException ioe) { System.out.println( "IO Exception Occured While Messing aruond with Processes! -> " + ioe); } } }