IShellLinkDataList.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from win32com.shell import shell, shellcon
  2. import pythoncom, win32api, os, sys
  3. temp_dir=win32api.GetTempPath()
  4. linkname=win32api.GetTempFileName(temp_dir,'cmd')[0]
  5. os.remove(linkname)
  6. linkname+='.lnk'
  7. print 'Link name:',linkname
  8. ish=pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None,
  9. pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
  10. ish.SetPath(os.environ['cOMSPEC'])
  11. ish.SetWorkingDirectory(os.path.split(sys.executable)[0])
  12. ish.SetDescription('shortcut made by python')
  13. console_props={
  14. 'Signature':shellcon.NT_CONSOLE_PROPS_SIG,
  15. 'InsertMode':True,
  16. 'FullScreen':False, ## True looks like "DOS Mode" from win98!
  17. 'FontFamily':54,
  18. 'CursorSize':75, ## pct of character size
  19. 'ScreenBufferSize':(152, 256),
  20. 'AutoPosition':False,
  21. 'FontSize':(4, 5),
  22. 'FaceName':u'',
  23. 'HistoryBufferSize':32,
  24. 'InputBufferSize':0,
  25. 'QuickEdit':True,
  26. 'Font':0, ## 0 should always be present, use win32console.GetNumberOfConsoleFonts() to find how many available
  27. 'FillAttribute':7,
  28. 'PopupFillAttribute':245,
  29. 'WindowSize':(128, 32),
  30. 'WindowOrigin':(0, 0),
  31. 'FontWeight':400,
  32. 'HistoryNoDup':False,
  33. 'NumberOfHistoryBuffers':32,
  34. ## ColorTable copied from a 'normal' console shortcut, with some obvious changes
  35. ## These do not appear to be documented. From experimentation, [0] is background, [7] is foreground text
  36. 'ColorTable':(255, 8388608, 32768, 8421376, 128, 8388736, 32896, 12582912,
  37. 8421504, 16711680, 65280, 16776960, 255, 16711935, 65535, 16777215)
  38. }
  39. ishdl=ish.QueryInterface(shell.IID_IShellLinkDataList)
  40. ishdl.AddDataBlock(console_props)
  41. ipf=ish.QueryInterface(pythoncom.IID_IPersistFile)
  42. ipf.Save(linkname,1)
  43. os.startfile(linkname)