command for right-click on .lnk file ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Norma
Posts: 5
Joined: 22 May 2020 18:27

command for right-click on .lnk file ?

#1 Post by Norma » 02 Aug 2020 13:23

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?

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

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

#2 Post by penpen » 03 Aug 2020 05:13

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

Post Reply