|
1 #! /usr/bin/env python |
|
2 # Copyright (C) 2005, Giovanni Bajo |
|
3 # Based on previous work under copyright (c) 1999, 2002 McMillan Enterprises, Inc. |
|
4 # |
|
5 # This program is free software; you can redistribute it and/or |
|
6 # modify it under the terms of the GNU General Public License |
|
7 # as published by the Free Software Foundation; either version 2 |
|
8 # of the License, or (at your option) any later version. |
|
9 # |
|
10 # This program is distributed in the hope that it will be useful, |
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 # GNU General Public License for more details. |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License |
|
16 # along with this program; if not, write to the Free Software |
|
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|
18 from win32com.shell import shell |
|
19 import win32api |
|
20 import pythoncom |
|
21 import os |
|
22 import sys |
|
23 |
|
24 def CreateShortCut(Path, Target,Arguments = "", StartIn = "", Icon = ("",0), Description = ""): |
|
25 # Get the shell interface. |
|
26 sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, \ |
|
27 pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink) |
|
28 |
|
29 # Get an IPersist interface |
|
30 persist = sh.QueryInterface(pythoncom.IID_IPersistFile) |
|
31 |
|
32 # Set the data |
|
33 sh.SetPath(Target) |
|
34 sh.SetDescription(Description) |
|
35 sh.SetArguments(Arguments) |
|
36 sh.SetWorkingDirectory(StartIn) |
|
37 sh.SetIconLocation(Icon[0],Icon[1]) |
|
38 # sh.SetShowCmd( win32con.SW_SHOWMINIMIZED) |
|
39 |
|
40 # Save the link itself. |
|
41 persist.Save(Path, 1) |
|
42 print "Saved to", Path |
|
43 |
|
44 if __name__ == "__main__": |
|
45 try: |
|
46 TempDir = os.environ["TEMP"] |
|
47 WinRoot = os.environ["windir"] |
|
48 |
|
49 Path = TempDir |
|
50 Target = os.path.normpath(sys.executable) |
|
51 Arguments = "" |
|
52 StartIn = TempDir |
|
53 Icon = ("", 0) |
|
54 Description = "py made shortcut" |
|
55 |
|
56 CreateShortCut(Path,Target,Arguments,StartIn,Icon,Description) |
|
57 except Exception, e: |
|
58 print "Failed!", e |
|
59 import traceback |
|
60 traceback.print_exc() |
|
61 raw_input("Press any key to continue...") |