creating a shortcut for a exe from a batch file

后端 未结 9 1496
清酒与你
清酒与你 2020-11-27 05:39

how to create a shortcut for a exe from a batch file.

i tried

call link.bat \"c:\\program Files\\App1\\program1.exe\" \"C:\\Documents and Settings\\         


        
相关标签:
9条回答
  • 2020-11-27 06:35

    Your link points to a Windows 95/98 version and I guess you have at least Windows 2000 or XP. You should try the NT version here.

    Alternatively use a little VBScript that you can call from the command line:

    set objWSHShell = CreateObject("WScript.Shell")
    set objFso = CreateObject("Scripting.FileSystemObject")
    
    ' command line arguments
    ' TODO: error checking
    sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0))
    sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1))
    sWorkingDirectory = objFso.GetAbsolutePathName(sShortcut)
    
    set objSC = objWSHShell.CreateShortcut(sShortcut) 
    
    objSC.TargetPath = sTargetPath
    objSC.WorkingDirectory = sWorkingDirectory
    
    objSC.Save
    

    Save the file as createLink.vbs and call it like this to get what you originally tried:

    cscript createLink.vbs "C:\Documents and Settings\%USERNAME%\Desktop\Program1 shortcut.lnk" "c:\program Files\App1\program1.exe" 
    cscript createLink.vbs "C:\Documents and Settings\%USERNAME%\Start Menu\Programs\Program1 shortcut.lnk" "c:\program Files\App1\program1.exe" 
    

    That said I urge you not to use hardcoded paths like "Start Menu" since they're different in localized versions of windows. Modify the script instead to use special folders.

    0 讨论(0)
  • 2020-11-27 06:38

    Additional note: the link.bat you're using is for Windows 95/98 only:

    This batch file is for Windows 95/98 only. I will post the NT equivalent in the NT newsgroup soon.

    NT version is posted at http://www.robvanderwoude.com/amb_shortcutsnt.html instead. You might try that for a .bat approach if preferred over vbscript.

    0 讨论(0)
  • 2020-11-27 06:38

    Alternative method, using a third party utility:

    Creating a Shortcut from the command line (batch file)

    XXMKLINK:

    With XXMKLINK, you can write a batch file for software installation which has been done by specialized installation programs. Basically, XXMKLINK is a tool that gathers various information from a command line and packages it into a shortcut.

    xxmklink spath opath 
    
    where 
    
      spath     path of the shortcut (.lnk added as needed)
      opath     path of the object represented by the shortcut
    
    0 讨论(0)
提交回复
热议问题