Copy .lnk to 64-bit Windows shortcut content

We use SCCM 2012 R2, 2012 server servers, and Windows 7 clients. Student machines are typically Win7-64.

I created a script to install Eclipse, basically create a directory and copy files (Eclipse does not have an installer and 32-bit software). In my script, to make things better for students, I want to place shortcuts on the desktop and the Start menu. The code looks like this:

REM Put icon on desktop
copy "Eclipse Mars (64).lnk" "C:\Users\Public\Desktop"
rename "C:\Users\Public\Desktop\Eclipse Mars (64).lnk" "C:\Users\Public\Desktop\Eclipse Mars.lnk"

However, when the link appears on the client’s desktop, the correct Target from “C: \ Program Files (x86) \ Eclipse \ eclipse.exe” changes to “C: \ Program Files \ Eclipse \ eclipse.exe" and therefore does not work ( same with Start In).

What will change the contents of the shortcut to the wrong directory of program files?

Finally, although I mention Eclipse in this example, this happens with any 32-bit shortcuts written on a 64-bit machine.

+4
source share
2 answers

I have done some research, you should try the following:

ren "Eclipsce Mars (64).lnk" eclm.tmp
copy "eclm.tmp" "C:\Users\Public\Desktop"
ren "C:\Users\Public\Desktop\eclm.tmp" "C:\Users\Public\Desktop\Eclipse Mars.lnk"
ren eclm.tmp "Eclipsce Mars (64).lnk"

What I've done:

  • Renamed the original .lnktoeclm.tmp
  • Copied eclm.tmptoDesktop
  • Renamed Desktop\eclm.tmptoEclipse Mars.lnk
  • Renamed the original .lnkto normal.

This should circumvent the tendency of Windows to modify the contents of .lnkfiles.

Let me know in the comments and vote counter if this works!
~ CSS

0
source

Windows, VBS script, .

:

REM Put icon on desktop
call "Create Shortcut.vbs" "C:\Users\Public\Desktop\Eclipse Mars (64).lnk" "C:\Program Files (x86)\eclipse-mars\eclipse.exe" "C:\Program Files (x86)\eclipse-mars"

VBS " .vbs":

' Check the number of parameters
If 3 <> WScript.Arguments.Count Then
    WScript.Echo "Please call this file using the following parameters:"
    WScript.Echo
    WScript.Echo "   LINK PATH   - Absolute path where the shortcut file will be created"
    WScript.Echo "   TARGET_PATH - Absolute path of the target program"
    WScript.Echo "   WORKING_DIR - Working directory used by this shortcut"
    WScript.Quit(1)
End If

strLinkPath   = WScript.Arguments(0)
strTargetPath = WScript.Arguments(1)
strWorkingDir = WScript.Arguments(2)

set oShell = WScript.CreateObject("WScript.Shell")

set oShellLink = oShell.CreateShortcut(strLinkPath)
oShellLink.TargetPath       = sTargetPath
oShellLink.WorkingDirectory = strWorkingDir
oShellLink.WindowStyle      = 1
oShellLink.Description      = ""
oShellLink.IconLocation     = strTargetPath
oShellLink.Save
0

Source: https://habr.com/ru/post/1658019/


All Articles