File size: 1,917 Bytes
10865e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import sys

import pythoncom
import win32api
from win32com.shell import shell, shellcon

temp_dir = win32api.GetTempPath()
linkname = win32api.GetTempFileName(temp_dir, "cmd")[0]
os.remove(linkname)
linkname += ".lnk"
print("Link name:", linkname)
ish = pythoncom.CoCreateInstance(
    shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink
)
ish.SetPath(os.environ["cOMSPEC"])
ish.SetWorkingDirectory(os.path.split(sys.executable)[0])
ish.SetDescription("shortcut made by python")

console_props = {
    "Signature": shellcon.NT_CONSOLE_PROPS_SIG,
    "InsertMode": True,
    "FullScreen": False,  ## True looks like "DOS Mode" from win98!
    "FontFamily": 54,
    "CursorSize": 75,  ## pct of character size
    "ScreenBufferSize": (152, 256),
    "AutoPosition": False,
    "FontSize": (4, 5),
    "FaceName": "",
    "HistoryBufferSize": 32,
    "InputBufferSize": 0,
    "QuickEdit": True,
    "Font": 0,  ## 0 should always be present, use win32console.GetNumberOfConsoleFonts() to find how many available
    "FillAttribute": 7,
    "PopupFillAttribute": 245,
    "WindowSize": (128, 32),
    "WindowOrigin": (0, 0),
    "FontWeight": 400,
    "HistoryNoDup": False,
    "NumberOfHistoryBuffers": 32,
    ## ColorTable copied from a 'normal' console shortcut, with some obvious changes
    ## These do not appear to be documented.  From experimentation, [0] is background, [7] is foreground text
    "ColorTable": (
        255,
        8388608,
        32768,
        8421376,
        128,
        8388736,
        32896,
        12582912,
        8421504,
        16711680,
        65280,
        16776960,
        255,
        16711935,
        65535,
        16777215,
    ),
}

ishdl = ish.QueryInterface(shell.IID_IShellLinkDataList)
ishdl.AddDataBlock(console_props)
ipf = ish.QueryInterface(pythoncom.IID_IPersistFile)
ipf.Save(linkname, 1)
os.startfile(linkname)