Page 1 of 1

command for right-click on .lnk file ?

Posted: 02 Aug 2020 13:23
by Norma
This one is a long shot but I saw no harm in asking.

I dislike the standard Windows methods of creating shortcuts. I like fell swoops.

When I set up a folder structure for a new client using a batch file with a parameter, the last of several steps is to create a dummy desktop shortcut by copying a dummy .lnk file to the desktop with a name that is generated from the parameter. Last line of batch file is:

copy dummy.lnk c:\users\norma\desktop\%str2%.lnk

Back in Windows, I locate the new file on the desktop, right-click to open the context menu, select Properties, and change Target from the dummy destination to the client's folder.

Question: is there a DOS method of opening the context menu for the newly created .lnk file?

Re: command for right-click on .lnk file ?

Posted: 03 Aug 2020 05:13
by penpen
You could create the link using a jscript/batch hybrid (sketched sample, untested):

Code: Select all

@if (true == false) @end /*
@echo off
setlocal enableExtensions disableDelayedExpansion
call :main
goto :eof

:main
cscript //E:jScript //NoLogo "%~dpnx0" /"lnk:doo1\\foo1.lnk" /"iconLocation:doo2\\foo2.ico" /"arguments: /arg1 /\u0022arg2\u0022"
:: display info only:
::cscript //E:jScript //NoLogo "%~dpnx0" /"lnk:doo1\\foo1.lnk" /"iconLocation:doo2\\foo2.ico" /"arguments: /arg1 /\u0022arg2\u0022" /displayInfoOnly
:: create link:
::cscript //E:jScript //NoLogo "%~dpnx0" /"lnk:doo1\\foo1.lnk" /"iconLocation:doo2\\foo2.ico" /"arguments: /arg1 /\u0022arg2\u0022"
goto :eof

*/

var input = {};
var info = false;
var lnk = "";

for(var e = new Enumerator(WScript.Arguments.Named); !e.atEnd(); e.moveNext()) {
	arg = e.item();
	if (arg == "lnk") {
		eval("lnk = \"" + WScript.Arguments.Named(arg) + "\"");
	} else if (arg == "displayInfoOnly") {
		info = true;
	} else {
		eval("input." + arg + " = \"" + WScript.Arguments.Named(arg) + "\"");
	}
}

if (WScript.Arguments.Named.exists("displayInfoOnly")) {
	for(arg in input) {
		WScript.echo("input." + arg + " = " + eval("input." + arg) + ";");
	}
} else if (true == false) {
	var shell = WScript.CreateObject("WScript.Shell");
	var lnk = shell.CreateShortcut(lnk);
	for(arg in input) {
		eval("lnk." + arg + " = input." + arg + ";");
	}
	lnk.save();
}
penpen