Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bat file to create a Windows 7 shortcut.lnk on my desktop

How can I create a bat or vbs file to create a Windows 7 compatible desktop shortcut?

I need the bat or vbs file to create the desktop shortcut using the following target and start-in locations (below). I basically created a desktop app that uses Google Chrome Portable to render my webapp as if it is Windows native and the shortcut will launch Chrome so it is very lightweight and looks like a genuine Windows application kinda like what Prism used to do. I've tried manually creating the shortcut.lnk but when my user installs my app it wont extract my shortcut.lnk via this path C:\Users\Public\Desktop so thats why I am now trying to create a bat or vbs file I can run on install. Thanks for your help.

Target:

C:\MyProgram\App\Chrome-bin\chrome.exe --user-data-dir="C:\MyProgram\Data\profile" --app=http://my-web-site-url.com/

Start in:

C:\MyProgram\App\Chrome-bin

like image 633
Jay Avatar asked Feb 18 '23 16:02

Jay


2 Answers

Your installer should be able to do this ... here is how in VBS:

Set wsc = WScript.CreateObject("WScript.Shell")
Set lnk = wsc.CreateShortcut(wsc.SpecialFolders("desktop") & "\XXXX.LNK")

lnk.targetpath = "C:\MyProgram\App\Chrome-bin\chrome.exe"
lnk.arguments = "--user-data-dir=""C:\MyProgram\Data\profile"" --app=http://my-web-site-url.com/"
lnk.description = "Bla bla"
lnk.workingdirectory = "C:\MyProgram\App\Chrome-bin" 
lnk.save
like image 167
Alex K. Avatar answered Mar 03 '23 22:03

Alex K.


You can use the INTERNAL command MKLINK to make a SYMBOLIC link (ie: It acts just like the file it's linked to).

You need to have an elevated command prompt, or have the Administrator account activated (with a password set, as RUNAS will not accept a blank password).

From an elevated command prompt:

mklnk.bat

@echo off
mklink %~n1.lnk %~dpnx1

With an active Administrator account:

mklnk.bat

@echo off
runas /user:administrator "cmd /c mklink %~dpn1.lnk %~dpnx1"

Because mklink is an internal command, you can't use RUNAS to directly access it, but you can run CMD.EXE as the Administrator, and then call mklink from there.


Both of the above batch files will accept the same options and create the same files in the same place. So if you call the batch file mklnk.bat :

c:>mklnk welcome.msg
symbolic link created for welcome.lnk <<===>> welcome.msg

Another CMD.EXE window will flash on the screen, but that is normal.

like image 41
James K Avatar answered Mar 03 '23 22:03

James K