Thursday, September 13, 2012

Google URL shortner

Your website url too long?
 Visit http://goo.gl/ and shorten it.It is a google service.

Friday, September 7, 2012

closing command prompt using java


import java.io.*;
import javax.swing.JOptionPane;
import java.net.BindException;
class Loader
{
    public static void main(String as[])
    {
        try
        {
            System.out.println("Loading application.........");

             //pass the name of your exe in place of my.exe
             Process p = Runtime.getRuntime().exec("my.exe");

             //getting inputstream reader from process
             BufferedReader reader = new BufferedReader
                                     (newInputStreamReader(p.getInputStream()));

             String line = reader.readLine();

              //exit from this class when get "Loaded" from your application
              while (line.equals("Loaded") == false)
               {
                       line = reader.readLine();
               }
                reader.close();
            }
            catch (Exception e)
            {
            }
    }
}

nice tutorial about how to create exe file using bat file

make shortcut for program using vbscript


L_Welcome_MsgBox_Message_Text = _
    "A shortcut to Notepad" & _
    vbcrlf & "will be created on your desktop."
 L_Welcome_MsgBox_Title_Text = _
    "Windows Scripting Host Sample"
 Call Welcome()
 Dim WSHShell
 Set WSHShell = _
    WScript.CreateObject("WScript.Shell")
 Dim MyShortcut, MyDesktop, DesktopPath
 ' Read desktop path using WshSpecialFolders object
 DesktopPath = _
    WSHShell.SpecialFolders("Desktop")
 ' Create a shortcut object on the desktop
 Set MyShortcut = _
    WSHShell.CreateShortcut( _
    DesktopPath & "\Shortcut to notepad.lnk")
 ' Set shortcut object properties and save it
 MyShortcut.TargetPath = _
    WSHShell.ExpandEnvironmentStrings( _
    "%windir%\notepad.exe")
 MyShortcut.WorkingDirectory = _
    WSHShell.ExpandEnvironmentStrings( _
    "%windir%")
 MyShortcut.WindowStyle = 4
 MyShortcut.IconLocation = _
    WSHShell.ExpandEnvironmentStrings( _
    "%windir%\notepad.exe, 0")
 MyShortcut.Save
 WScript.Echo _
    "A shortcut to Notepad now exists on your Desktop."
 Sub Welcome()
    Dim intDoIt
    intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _
       vbOKCancel + vbInformation, _
       L_Welcome_MsgBox_Title_Text )
    If intDoIt = vbCancel Then
       WScript.Quit
    End If
 End Sub

Java Call main() method of a class using another class in java


public static void main(String[] args) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
 
 Class<?> cls = Class.forName("pkg1.pkg2.classname");
   
Method meth = cls.getMethod("main", String[].class);
 
 String[] params = null; // init params accordingly
 
  meth.invoke(null, (Object) params); // static method doesn't have an instance
}