-2

As per this link Is there a way of Creating lnk file using javascript I am trying to create a .lnk file. I would like to know how to set the property Start In, which is a folder location of the .lnk file and also the .lnk file that I am trying to create has additional parameters in the Target property.

Ex : Expected .lnk file properties

Target : "C:\Windows\System32\Calc.exe" /mode:QWE /role:Admin

Start In : C:\Windows\System32\

Is there a way of Creating lnk file using javascript

Deepak M
  • 3
  • 1

1 Answers1

1

You can use the WScript.Shell function CreateShortcut

var objShell = new ActiveXObject("WScript.Shell")
var lnk = objShell.CreateShortcut("C:\\my_shortcut.lnk")

lnk.TargetPath = "C:\\Windows\\System32\\Calc.exe";
lnk.Arguments = "/mode:QWE /role:Admin";
lnk.Description = "Your description here...";
lnk.IconLocation = "C:\\Windows\\System32\\Calc.exe, 0";
lnk.WorkingDirectory = "C:\\Windows\\System32";
lnk.Save();

001
  • 13,291
  • 5
  • 35
  • 66
  • Hello, Thanks for the response .I am looking for a way to do this in JavaScript. Can you please suggest? – Deepak M Sep 12 '19 at 15:35
  • My answer is Javascript. You can run this code from the command line with cscript.exe. – 001 Sep 12 '19 at 15:37
  • Hello, I am not able to create .lnk file using the above code when I Deploy the code to the server. I believe the working directory is not set or do I need to change any config in the IE? – Deepak M Oct 04 '19 at 16:50
  • @DeepakM So this is for ASP? I'm not too familiar with that. This script will work with a command prompt. Maybe you need to change the web server's permissions? You should probably ask a new question to get help with that. – 001 Oct 04 '19 at 17:57
  • Hello Johnny, this is not for asp. it's with JavaScript. Though the file gets created locally in the ide when executed , it's fails to get created when deployed on the server. I tried to replicate the same in the ide and I could replicate it by not setting the working directory. Also tried to debug and I could see it is being set and also I tried to set the current directory to the exe file location. No luck. Appreciate your help. Thanks – Deepak M Oct 04 '19 at 20:40
  • Hello Johnny, I tried to change a bit and launch the exe file with parameters using the .exec and .run method of activex . Again it works on the http local server and not in the https webserver . Do I need to change any settings in the browser ? Please let me know. Even if I try to create a .lnk file as suggested by you ,while launching the lnk with .run method ,it's not working . – Deepak M Oct 04 '19 at 23:38