mksc plugin for Take Command / TCC / TCC/LE

Version 1.4.4.7     2024-10-24

Charles Dye

Purpose:

This plugin provides one command, MKSC, and one function, @SCINFO, to create, modify, list, and retrieve information from shortcut files.

Both are from my UIStuff plugin. I have made them available as a separate plugin for those who don’t want the bulk, and unrelated features, of the larger plugin. I think MKSC and @SCINFO are useful enough to stand on their own two… features.


MKSC is similar to the internal SHORTCUT command, but with a number of differences:

Installation:

To use this plugin, copy mksc.dll and mksc.chm to some known location on your hard drive. (If you are still using the 32-bit version of Take Command, take mksc-x86.dll instead of mksc.dll.) Load the .DLL file with a PLUGIN /L command, for example:

plugin /l c:\bin\tcmd\test\mksc.dll

If you copy these files to a subdirectory named PlugIns within your Take Command program directory, the plugin will be loaded automatically when TCC starts.

Plugin Features:

New command: MKSC

New function: @SCINFO

Syntax Note:

The syntax definitions in the following text use these conventions for clarity:

BOLD CODEindicates text which must be typed exactly as shown.
CODEindicates optional text, which may be typed as shown or omitted.
Bold italicnames a required argument; a value must be supplied.
Regular italicnames an optional argument.
ellipsis…after an argument means that more than one may be given.

New Command:

MKSC — Create, modify, or display a shortcut file.

Syntax: (to create or modify a shortcut file)
MKSC linkfile target /A:args /Bx:value /C:comment /D:directory /I:iconfile /J:index /K:key /M:mode /N:flags /U:level /Z

Syntax: (to display shortcut files)
MKSC linkfile /F:fields /N:flags /P /S

linkfilethe shortcut file to create, change, or display
targetthe filename or object that the shortcut points to
/A:argscommand-line arguments to be passed to the target
/Bx:valueset various console properties
/C:commenta descriptive comment
/D:directorythe default directory
/F:fieldsspecify which information to display
/I:iconfilefilename of an .EXE or .DLL file containing an icon
/J:indexnumber of the icon in iconfile to use; 0 = the first
/K:keya hotkey which can be used to launch the shortcut
/M:modethe suggested window mode: Normal, MINimized, or MAXimized
/N:flagsdisable features; flags may include:
C — disable highlight
D — don’t canonicalize directory
E — suppress many error messages (display mode only)
H — don’t search into hidden subdirectories; only useful with /S
I — don’t canonicalize iconfile
J — don’t search into junctions; only useful with /S
T — don’t canonicalize target
Z — don’t search into system subdirectories; only useful with /S
/Ppage output
/Srecurse into subdirectories; only useful when displaying shortcuts
/U:levelthe UAC level: Normal or Elevated
/Zoverwrite read-only files

Quote any argument containing spaces, angle brackets, or other special characters.

This command can be used for three different tasks: to create a new shortcut file, to modify an existing shortcut file, or to dump the contents of shortcut files to standard output.

Create a shortcut file:

You can create a new shortcut to a file or a folder; a TCC command, alias, or batch file; or one of a number of Explorer objects. To create a shortcut, pass a filename for the new shortcut as the first argument, linkfile. The second argument, target, is required when creating a new shortcut; it specifies the file or object that the shortcut will open.

rem  Create a shortcut to the calculator:
mksc "%@shfolder[16]\Calculator.lnk" "%windir\system32\calc.exe" /k:control-alt-=


Other kinds of files are legal too. If the file is a document, Windows will use the registered program to open it. You can even create a shortcut to a directory:

rem  Create a shortcut to the Fonts folder:
mksc "%@shfolder[16]\Fonts.lnk" "%windir\Fonts"


To create a shortcut to an internal command, alias, or batch file, specify "%_cmdspec" as the target. Set args to either /C or /K followed by the desired command. (/C causes TCC to close immediately after running the command; /K keeps it open after the command finishes.) For instance, to create a shortcut which runs the command TIME /S, you might use:

rem  Create a shortcut to run TIME /S command:
mksc "%@shfolder[16]\Sync System Time.lnk" "%_cmdspec" /a:"/c time /s" /m:min


MKSC also recognizes a short list of Explorer objects. You can use any of the following as target:

<Desktop>the desktop
<Computer>the list of drives
<Documents>the default save location for many applications
<Music>the suggested save location for music files
<Pictures>the suggested save location for graphics files
<Video>the suggested save location for video files
<Printers>the list of printers
<Network>Network Neighborhood; LAN locations
<Connections>network interfaces
<Recycle Bin>deleted-but-recoverable files
<Control Panel>Windows configuration utilities
<Recent>list of shortcuts to recently-opened files
<SendTo>Explorer’s list of send-to locations
(This is not a complete list; see Objects Supported for more.)

Note that all of the above must be quoted to protect the angle brackets.

rem  Create a shortcut to My Computer:
mksc "%@shfolder[16]\My Computer.lnk" "<Computer>"

If the target is in angle brackets but is not in the built-in list of objects, MKSC will search for an object with a matching display name in a few predefined locations; see Objects Supported for more information. For example, if you have a printer named “DrizzleJet 9000”, you can create a shortcut to it:

rem  Create a shortcut to my printer:
mksc "%@shfolder[16]\Printer.lnk" "<DrizzleJet 9000>"


The linkfile should normally end in .LNK. If you do not specify an extension, MKSC will supply the extension by default. Directory aliases are supported in linkfile.

Target should name a file, directory, or one of the Explorer objects listed above. Directory aliases are supported, and the filename is automatically canonicalized (“truenamed”) when the shortcut file is created. If the target is not qualified at all — if it has no drive letter or directory — the plugin will search the path for a matching file. You can bypass canonicalization and the path search with /NC, which stores a non-canonical filename; doing this also disables directory aliases in target. Canonicalization will also be skipped if the target begins with a percent sign followed by a letter.


/A:args specifies the command-line arguments for the target program. Different programs support different arguments, and some ignore them altogether. See the program’s documentation for information about its command-line options.

/AX:args works like /AX:, but supports the use of C-style character escapes in the string. If you need problematic characters like double quotes or backquotes in the arguments list, you can use /AX: with escapes like \q or \k. Note that any backslashes in the arguments must be doubled.


/C:comment specifies a descriptive comment to be stored in the shortcut file. Explorer can display this comment in a tooltip when you hover the mouse pointer over the shortcut icon.

/CX:comment works like /C:, but expands C-style character escapes in the comment. If you need a backslash in the comment, you must double it.


/D:directory sets the starting directory for the target program. Some programs use this as a default directory; others ignore it. The directory is canonicalized, and directory aliases are supported. You can use /ND to store a non-canonicalized filename; this will also disable directory aliases in directory. If you give a directory of *, MKSC will choose an appropriate directory based on target: the parent directory if target is a filename, target itself if it names a directory, and nothing if target names an object. If the directory begins with a percent sign followed by a letter, canonicalization will be disabled automatically. If the directory is a ~ or begins with ~\, the tilde will automatically be replaced with the string %USERPROFILE%; this also will disable canonicalization.

/M:mode sets the default window state for the target program. Most programs will honor this option, but a few set their own window size at startup; /M won’t appear to affect these. Mode should be one of Normal, MINimized, or MAXimized; case is not significant, and only the letters shown in uppercase are required.

/K:key specifies a hotkey which can be used to launch the target with a keystroke. The exact requirements for this feature to work don’t seem to be documented anywhere. For best results, I suggest that (1) the shortcut file should be created in the user’s desktop directory; and (2) the hotkey should be in the form Control-Alt-letter, Control-Alt-digit, or Control-Alt-Numdigit. See Hotkeys for a list of the hotkey names supported by this command; note that some of them differ from the names used by KEYSTACK. You can also specify a hotkey of None, which will remove any hotkey associated with the shortcut.

/I:iconfile and /J:index specify the icon which Explorer uses to display the shortcut. When creating a shortcut, you should specify both or neither. When modifying an existing shortcut file, you can use /J:index alone to select a different icon within the same iconfile.

/U:level sets the UAC level for the shortcut; level is either Normal or Elevated (only the first letter is significant). If it’s not specified, the default level is Normal. This option has no effect under Windows XP.


Console properties:

MKSC allows you to set or change many of the console properties stored in a shortcut. Setting console properties for things that don’t run in a console window is possible, but pointless. Console properties options all start with /B.


/BB:n sets the console font’s weight. n is 400 for normal, 700 for bold.

/BF:font set the console font’s name. Quote it if it contains spaces. If font doesn’t match the name of an actual font, or if it isn’t suitable for use in a console window, Windows will substitute some other font at random — generally the ugliest available.

/BG:x,y sets the desired size of the console font. x is the width, and y is the height. If you’re using a TrueType font, the width is not relevant and may be set to 0.

/BB, /BF, and /BG all affect the console font. If you want to set one of them, it’s probably a good idea to set all three.


/BA:n sets the console’s auto-position option. 0 disables auto-positioning; the console window will open at the screen position specified in the “Layout” tab. 1 allows the system to position the window automatically; the coordinates in the “Layout” tab will be ignored.

/BC:n sets the cursor size. n is a percentage, 10 to 100. (This setting does not affect TCC, which sets its own cursor size.)

/BD:n set the console’s default colors. You may specify the new value either as decimal, or hexadecimal with a leading 0x. The usual value is 0x0007, white on black.


/BHn:color lets your redefine the console palette. n is the color index, 0 (black) through 15 (bright white). Color is a W3C color name or an RGB value. You may give a name, or a three- or six-digit hex value preceded by a number sign. For example, you could use either /BH7:ORANGE or /BH7:#FFA500 to redefine ‘white’ as orange.

You can give more than one color name, separated by commas or semicolons, to define multiple consecutive colors. For example, /BH0:#000,#009,#090,#099,#900 would set values for black, blue, green, cyan, and red.


/BI:n sets the console’s insert mode. 0 disables insert (the console defaults to overtype mode); 1 enables it. (This setting does not affect TCC, which has its own default edit mode settings.)

/BO:x,y sets the console window’s starting screen position (its origin). Using this option automatically disables the auto-position option, as if /BA:0 had been specified.

/BP:n set the console’s “popup” colors. You may specify the new value either as decimal, or hexadecimal with a leading 0x. (TCC does not use these colors for anything; CMD.EXE uses them for its command history popup.)

/BQ:n sets the console’s QuickEdit mode. 0 disables QuickEdit, 1 enables it.


/BS:x,y sets the size of the console scrollback buffer. x is the width and y is the height.

/BS also has an optional third argument to set the height of the visible window: /BS:x,y,h. The height h must be between 5 and 100, and not greater than the screen buffer height y. If you do not specify h, the plugin will supply a reasonable value.

Modify a shortcut file:

To modify an existing shortcut file, the syntax is the same, except that the target parameter is optional. You don’t have to specify a target when changing an existing shortcut, and you probably shouldn’t.

Display shortcut files:

To display the contents of shortcut files, specify only a linkfile. It may contain wildcards to dump multiple shortcut files, and you can use /S to recurse into subdirectories. To prevent MKSC from searching into junctions, use /NJ; to skip hidden subdirectories, use /NH; to skip system subdirectories, use /NZ. If linkfile names a directory, all .LNK files in that directory will be shown.

You can use /F:fields to choose which fields to display. Fields is letters:

Tthe link target
Acommand-line arguments
Dstartup directory
Khotkey
Ccomment
Mstart mode
Iicon filename and index
UUAC level (only under Vista and later)
Nnormal (default) fields; short for TADKCMIU
Bconsole screen buffer info, if available
Fconsole font info, if available
Hthe console palette, if available

If no fields are specified, the default is TADKCMIU.


/P causes MKSC to pause after each screenful of data.

mksc /s "%@shfolder[23]"


See also: the @SCINFO function, which returns values from a shortcut file.



New Function:

@SCINFO — Returns values from a shortcut file.

Syntax:
%@SCINFO[filename,field]

filenamethe file to examine
fieldwhich field to return:
0the target filename or object name (default)
1the command-line arguments
2the working directory
3the descriptive comment
4the hotkey
5the startup window mode
6the icon filename
7the icon index
8the UAC level
32 the width of the console screen buffer
33 the height of the console screen buffer
34 the width of the visible window
35 the height of the visible window
36 the console font name
37 the font width in pixels (may be 0 for TrueType fonts)
38 the font height in pixels
39 the font weight: 400 = normal, 700 = bold
40 the cursor size: 25 = small, 100 = large
41 QuickEdit mode: 0 = disabled, 1 = enabled
42 auto position window: 0 = disabled, 1 = enabled
43 insert mode: 0 = overstrike, 1 = insert
44 default console colors as hex, e.g. 0x0007 = white on black
45 console popup colors as hex, e.g. 0x00F5 = magenta on bright white
46 console window position (if auto position is disabled) as x,y

   Console property. If the shortcut does not contain a console properties block, @SCINFO will return -1.

The filename is required. Quote it if it contains commas or other special characters. Wildcards are not allowed, but directory aliases are supported.

If field is 0 or absent, @SCINFO will attempt to return the shortcut’s target. The return value will be quoted. It may be empty if the target is an object which the plugin doesn’t recognize.

A field of 1, 2, or 3 returns the shortcut’s command-line arguments, working directory, or description, respectively. These return values are all quoted; any of them may return an empty string if the respective field is not defined in the shortcut.

A field of 4 returns the shortcut’s hotkey. This value is not quoted. It will return None if the shortcut has no hotkey defined.

A field of 5 returns the shortcut’s startup window mode. This value is not quoted; possible values are Normal, Maximized, and Minimized.

Values of 6 and 7 return the shortcut’s icon filename and offset, respectively. The filename will be quoted. If there is no icon, the filename will be empty and the index will be 0.

If field is 8, the shortcut’s UAC level will be returned; possible values are Normal and Elevated. (Under Windows XP and earlier, the value is always Normal.) The returned string is not quoted.


If you add 256 to the field number, the return string will not be automatically quoted. If you add 512, the return string will be escapified.

rem  Read info from a shortcut file:
set shortcut="%userprofile\desktop\test.lnk"
set target=%@scinfo[%shortcut,0]
set args=%@scinfo[%shortcut,1]
set dir=%@scinfo[%shortcut,2]


See also: the MKSC command, which creates, modifies, or displays shortcut files.



Reference Information:


Objects SupportedPointing to things other than files.
HotkeysUsed in shortcuts.
Escape SequencesPutting awkward characters in the arguments or comment.
Highlight VariableChoose your colors.
Startup MessageAnd how to suppress it.
AcknowledgmentsCredit where credit is due.
ChangesSlow march of progress, or just another bug hunt?
Status and Licensing

Objects Supported:

These are the Explorer objects explicitly supported in the target parameter to the MKSC command:

<Desktop>the desktop
<Computer>the list of drives
<Printers>the list of printers
<Network>Network Neighborhood; LAN locations
<Connections>network interfaces
<Recycle Bin>deleted-but-recoverable files
<Control Panel>Windows configuration utilities
<Desktop Directory>the user’s desktop directory
<Documents>the default save location for many applications
<Music>the suggested save location for music files
<Pictures>the suggested save location for graphics files
<Video>the suggested save location for video files
<Start Menu>the root of the user’s Start menu
<Programs>the “Programs” folder in the user’s Start menu
<Startup>the “Startup” folder in the user’s Start menu
<Templates>the user’s document templates directory
<Profile>the user’s profile directory
<NetHood>the user’s “Network Shortcuts” folder
<Common Desktop Directory>the common desktop directory
<Common Documents>the suggested location for shared documents
<Common Music>the suggested location for shared music files
<Common Pictures>the suggested location for shared graphics files
<Common Video>the suggested location for shared video files
<Common Start Menu>the root of the common Start menu
<Common Programs>the “Programs” folder in the common Start menu
<Common Startup>the “Startup” folder in the common Start menu
<Common Templates>the common document templates directory
<Recent>list of shortcuts to recently-opened files
<SendTo>Explorer’s list of send-to locations
<Windows>the root Windows directory, %WINDIR%
<System>the Windows system directory, %WINDIR%\System32
<System x86>the Windows SysWOW64 directory, %WINDIR%\SysWOW64
<Fonts>the Windows fonts directory
<Program Files>the default location for installed programs
<Program Files x86>the default location for WoW64 programs

Note that all of the above must be quoted to protect the angle brackets.

If you supply a name in angle brackets and it doesn’t match any of the above, MKSC will search for an object with a matching display name in: (1) Control Panel, (2) Administrative Tools, (3) Printers, and (4) Windows’s “Constant Special Item ID List”, in that order.


Many of the objects listed in the table above — the ones marked with a bullet in the left column — resolve to directories in the file system. These may be used at the start of linkfile, directory, or iconfile. For example, you can use <Desktop> to create a shortcut on the desktop:

mksc "<Desktop>Printers.lnk" "<Printers>"

Hotkeys:

These are the key names recognized by the MKSC command. Be aware that they differ somewhat from the key names used by the KEYSTACK command. In particular, MKSC distinguishes between the number keys on the numeric keypad, and those above the alphabetic keys.


Modifier keys: use one or more of these before a named key. Case is not significant. Modifiers listed on the same line are equivalent.

Control-Ctrl-C- the Ctrl key
Alt-A- the Alt key
Shift-S- the Shift key

Named keys. Case is not significant. Some have two names; names on the same line are equivalent.

NameAlternate name Comments
A — Z letter keys
0 — 9 number keys on the top row
Num0 — Num9 numbers on the numeric keypad when NumLock is on
BackspaceBksp  
Tab  not recommended
EnterReturn not recommended
Esc  not recommended
PageUpPgUp also 9 on the keypad when NumLock is off
PageDownPgDn also 3 on the keypad when NumLock is off
Home also 7 on the keypad when NumLock is off
End also 1 on the keypad when NumLock is off
Left also 4 on the keypad when NumLock is off
Right also 6 on the keypad when NumLock is off
Up also 8 on the keypad when NumLock is off
Down also 2 on the keypad when NumLock is off
InsertIns also 0 on the keypad when NumLock is off
DeleteDel also . on the keypad when NumLock is off
Num** * on the numeric keypad
Num+  + on the numeric keypad
Num-  - on the numeric keypad
Num/  / on the numeric keypad
F1 — F12  function keys
;Semicolon 
=Equals 
,Comma 
-Minus 
.Period 
/Slash the key with the question mark on U.S. keyboards
Grave` the key with the swung dash on U.S. keyboards
[LeftBracket 
]RightBracket 
\Backslash 
'Apostrophe 
SpaceSpacebar not recommended

• Note: Some key combinations are reserved by Windows, and others may not be recognized. Also, while it may be possible to use a named key without any modifiers, it’s probably a Bad Idea.

Escape Sequences:

This plugin recognizes these escape sequences:

Code:Expands to:Example:
\aASCII BEL character (0x07)
\bASCII backspace (0x08)
\ccomma
\eASCII ESC character (0x1b)
\fform feed (0x0c)
\kgrave accent (0x60)
\nline feed (0x0a)
\qdouble quotes (0x22)
\rcarriage return (0x0d)
\sspace (0x20)
\ttab (0x09)
\vvertical tab (0x0b)
\\backslash (0x5c)
\unnnnUnicode character, up to U+FFFF\u03a3 → Σ
\UnnnnnnnnUnicode character, up to U+10FFFF\U0001f63a → 😺
\nnnoctal value, up to 777\101 → A
\xnnnnhexadecimal value, up to FFFF\x0041 → A
\#nnnnndecimal value, up to 65535\#65 → A

Note that case is significant for the letter after the backslash. All must be lowercase, except for \Uxxxxxxxx.

Case is not significant in hexadecimal values. \uxxxx and \xxxxx read up to four hexadecimal digits; \Uxxxxxxxx reads up to eight. You may use fewer than four (or eight) digits if the following character is not a valid hex digit.

Similarly, octal character escapes read up to three octal digits. You may use fewer than three if the following character is not an octal digit. Decimal escapes read up to five decimal digits; you may use fewer than five if the following character is not a digit.

Highlight Variable:

MKSC features highlighted output. You can customize this feature by setting an environment variable Highlight:

rem  Disable highlight:
set highlight=none

rem  Set the highlight foreground:
set highlight=bright cyan

rem  Set both foreground and background:
set highlight=bri whi on blu

rem  Numbers are also supported:
set highlight=46

If the Highlight environment variable is not defined, the plugin will check the registry for a value named Highlight of type REG_SZ. The plugin will search, in this order:

•  HKEY_CURRENT_USER\Software\JPPlugins\mksc(affects this plugin only)
•  HKEY_CURRENT_USER\Software\JPPlugins(affects several of my plugins)

You can also use /NC to disable highlighting in MKSC.

Startup Message:

This plugin displays an informational line when it initializes. The message will be suppressed in transient or pipe shells. You can disable it for all shells by defining an environment variable named NOLOADMSG, for example:

set /e /u noloadmsg=1

Acknowledgments:

Here’s one necessary step in converting those bizarre “Darwin” strings into something readable: Working with Darwin Descriptors, by EdT. Thanks, man. (2023: Link no longer works, and the Wayback Machine doesn’t have it cached. Which is too bad; it really was a helpful page.)

Changes:


Version:Date:Changes:
1.4.4.72024-10-24ParseSignedInt() also supports octal with a leading 0o.
1.4.4.62024-09-30ParseInt() now supports octal with a leading 0o. ParseSignedInt() allows a leading plus sign. Changed http:// to https:// in the PLUGININFO block.
1.4.4.52024-04-03Updated to NewHelp.cpp v1.0.8.14, conlist.cpp v1.1.0.1.
1.4.4.42023-01-04Updated to conlist.cpp v1.1 to better handle Ctrl-C and Ctrl-Break.
1.4.4.32023-10-16Tweaked ShowCmdHelp() to include VER_PATCH.
1.4.4.22023-10-12Updated the plugin’s web address.
1.4.4.12023-07-25Updated to the current version of w3ccolors.cpp.
1.4.42023-07-21Updated to the current versions of conlist.cpp, NewHelp.cpp, and ParseArgs.cpp. The Highlight variable can now be set in the registry instead of the environment.
1.4.32023-06-13Removed all calls to QueryIsFile(), to work around an issue in TCC v30.00.20.
1.4.12023-04-18Now \b correctly expands to ASCII backspace. Updated to the latest versions of ExpandEscapes.cpp and conlist.cpp.
1.4.02022-06-01Added a .CHM help file. No changes to MKSC or @SCINFO.
1.3.142022-01-12Removed /X and /Y, and replaced them with /AX: and /CX:.
1.3.132021-12-18Added /NE to suppress many error messages. Fixed a problem with extensionless files being incorrectly included.
1.3.122021-12-17Now MKSC checks for Ctrl-C and Ctrl-Break while dumping shortcuts. (Previously this only happened during /P pauses.) Also, MKSC now returns errorlevel 3 for user abort; it was -3 before.
1.3.112021-12-16Split /FB into /FB (buffer info) and /FF (font info). Added /F? to list available fields. Documented the optional third argument to /BS.
1.3.102021-12-15Added /FH to dump the console palette. Renamed /BKn: to /BHn: (think H for hue).
1.3.92021-12-13Now /BKn: can accept multiple color names, separated by commas or semicolons, to define more than one color at a time.
1.3.82021-12-09Added many new /Bx: options to set various console properties. Removed the letter field specifiers from @SCINFO.
1.3.72021-12-08Reworked /N a bit. Now /NC disables highlight, and /NT prevents canononicalizing the target filename. Also added a semi-undocumented /N? which describes the available /N flags.
1.3.62021-12-01Experimental support for reporting console properties in both MKSC and @SCINFO. (MKSC does not yet have support for setting console properties.) De-documented SafeChars support and letter field values in @SCINFO.
1.3.52021-11-29Added the ability to decode installer “Darwin” strings, and return either a product name or GUID.

Status and Licensing:

This plugin is © Copyright 2024, Charles Dye. Unaltered copies of the binary and documentation files may be freely distributed. I make no guarantee and give no warranty for its operation. If you find a problem, you can report it in the JP Software support forum.

Download:

You can download the current version of the plugin from https://charlesdye.net/dl/mksc.zip.