View Javadoc

1   /*
2    * $Id: LnKFileOnDesktop.java 125 2008-11-04 07:18:28Z arnep $
3    */
4   package net.sf.ovanttasks.ovnative.demos;
5   
6   import java.io.File;
7   import net.sf.ovanttasks.ovnative.win32.LnkFile;
8   import net.sf.ovanttasks.ovnative.win32.Win32;
9   
10  /**
11   * Demonstrates the use of {@link LnkFile} to create an shortcut on the desktop.
12   * 
13   * @author lars.gersmann@roxes.com
14   * @author arnep@users.sf.net
15   */
16  public class LnKFileOnDesktop {
17  
18      /**
19       * run dir command with funny arguments in %TEMP%
20       * @return 
21       */
22      public static LnkFile resolveCmdOnDesktop() {
23          LnkFile lnkFile = new LnkFile(Win32.SpecialDirectory.PERSONAL_DESKTOP.getPath(), "open command shell in temp (resolve)", false);
24          lnkFile.setTargetFile(Win32.getWindowsSystemDirectory() + "X"+ File.separator + "cmd.exe");
25          lnkFile.save();
26          lnkFile.resolve();
27  
28          LnkFile lnkFile1 = new LnkFile(lnkFile.getSrcFile(), true);
29          lnkFile1.setArguments("/K dir /N /Q");
30          if (!lnkFile1.getSrcFile().getAbsolutePath().equals(Win32.getWindowsSystemDirectory() + File.separator + "cmd.exe")) {
31              //Show dlg
32          }
33          return lnkFile;
34      }
35  
36      /**
37       * run dir command with funny arguments in %TEMP%
38       * @return 
39       */
40      public static LnkFile createCmdOnDesktop() {
41          LnkFile lnkFile = new LnkFile(Win32.SpecialDirectory.PERSONAL_DESKTOP.getPath(), "list TEMP", false);
42          lnkFile.setToolTipText("Open command shell in %TEMP% \n and execute command dir /N /Q");
43          lnkFile.setHotkey("Ctrl + Alt + A"); //CTRL + ALT + A
44          lnkFile.setIcon(Win32.getWindowsDirectory() + File.separator + "explorer.exe", 3);
45          
46          lnkFile.setShowState(LnkFile.ShowCmd.SHOWMAXIMIZED);
47          lnkFile.setTargetFile(Win32.getWindowsSystemDirectory() + File.separator + "cmd.exe");
48          lnkFile.setArguments("/K dir /N /Q");
49          lnkFile.setWorkingDirectory(Win32.SpecialDirectory.TEMP.getPath());
50          
51          lnkFile.save();
52          return lnkFile;
53      }
54  
55      /**
56       * run dir command with funny arguments in %TEMP%
57       * @return 
58       */
59      public static LnkFile createCmdInProgramMenu() {
60          LnkFile lnkFile = new LnkFile(Win32.SpecialDirectory.PERSONAL_PROGRAMS_MENU.getPath(), "open command shell in temp", false);
61          lnkFile.setTargetFile(Win32.getWindowsSystemDirectory() + File.separator + "cmd.exe");
62          lnkFile.setArguments("/K dir /N /Q");
63          
64          lnkFile.save();
65          return lnkFile;
66      }
67  
68      /**
69       * open explorer in programm files
70       * @return 
71       */
72      public static LnkFile createExporerOnDesktop() {
73          LnkFile lnkFile = new LnkFile(Win32.SpecialDirectory.PERSONAL_DESKTOP.getPath(), "start explorer", false);
74          lnkFile.setTargetFile(Win32.getWindowsDirectory() + File.separator + "explorer.exe");
75          lnkFile.setArguments(Win32.SpecialDirectory.PROGRAM_FILES.getPath());
76          lnkFile.save();
77          return lnkFile;
78      }
79      
80      /**
81       * 
82       * @param args
83       * @throws java.lang.Exception
84       */
85      public static void main(String[] args) throws Exception {
86          createCmdOnDesktop();
87          createExporerOnDesktop();
88          resolveCmdOnDesktop();
89          createCmdInProgramMenu();
90      }
91      
92      /**
93       * 
94       */
95      public static void cleanup() {
96          createCmdOnDesktop().getSrcFile().delete();
97          createExporerOnDesktop().getSrcFile().delete();
98          resolveCmdOnDesktop().getSrcFile().delete();
99          createCmdInProgramMenu().getSrcFile().delete();
100     }
101 }