Link to home
Start Free TrialLog in
Avatar of rflook
rflook

asked on

Using batch process to create shortcuts

As a teacher i need to access on a regular basis my pupils work directories. At the moment i have to go through a very long winded process of navigating through various windows to get to their user space. Now i created a group of shortcuts to do this for me (which made my life easier), however creating the shortcuts in the firstplace was a pain in the bum. Is it possible to use a batch process based upon a list in a text file to create all of these shortcuts?

Many thanks in advance
Avatar of Visual3DMaya
Visual3DMaya
Flag of Romania image

Write in a .bat file like:
explorer c:\temp
explorer e:\temp
explorer and folder you want to open.
This will open windows explorer with the path as a parameter, then close the command window.
I think i did a wrong answer, maybe somebody else has it.
There is a program called Shortcut available from www.optimumx.com.

Does pretty much what it says on the can.

Here is the builtin help ...

Shortcut [Version 1.11]

Creates, modifies or queries Windows shell links (shortcuts)


The syntax of this command is:

shortcut /F:filename /A:C|E|Q [/T:target] [/P:parameters] [/W:workingdir]
         [/R:runstyle] [/I:icon,index] [/H:hotkey] [/D:description]

 /F:filename    : Specifies the .LNK shortcut file.
 /A:action      : Defines the action to take (C=Create, E=Edit or Q=Query).
 /T:target      : Defines the target path and file name the shortcut points to.
 /P:parameters  : Defines the command-line parameters to pass to the target.
 /W:working dir : Defines the working directory the target starts with.
 /R:run style   : Defines the window state (1=Normal, 3=Max, 7=Min).
 /I:icon,index  : Defines the icon and optional index (file.exe or file.exe,0).
 /H:hotkey      : Defines the hotkey, a numeric value of the keyboard shortcut.
 /D:description : Defines the description (or comment) for the shortcut.

 Notes:
 - Any argument that contains spaces must be enclosed in "double quotes".
 - If Query is specified (/A:Q), all arguments except /F: are ignored.
 - To find the numeric hotkey value, use Explorer to set a hotkey and then /A:Q
 - To prevent an environment variable from being expanded until the shortcut
   is launched, use the ^ carat escape character like this: ^%WINDIR^%

 Examples:
   /f:"%ALLUSERSPROFILE%\Start Menu\Programs\My App.lnk" /a:q
   /f:"%USERPROFILE%\Desktop\Notepad.lnk" /a:c /t:^%WINDIR^%\Notepad.exe /h:846
   /f:"%USERPROFILE%\Desktop\Notepad.lnk" /a:e /p:C:\Setup.log /r:3

 An argument of /? or -? displays this syntax and returns 1.
 A successful completion will return 0.


 Copyright 2000-2005 Marty List, www.OptimumX.com



Here is an example of when I use it ...

"%SourceRoot%\Programs\Shortcut.exe" /F:"%ALLUSERSPROFILE%\Start Menu\Programs\Dimensions\Dimensions - %Company%.lnk" /A:C /T:"%DestinationRoot%\%Company%\Access.exe" /W:"%DestinationRoot%\%Company%" /R:1 /D:"Dimensions - %Company%">> "%LogFile%"


Ok, slightly OTT, but this is part of a script which generates shortcuts on users PCs based upon various settings determined at run time by the same script.

But you can see how to call it.

Avatar of RobSampson
You could use VBS to create shortcuts, which could also read usernames from a text file, and create shortcuts accordingly.

Have a look here for a start:
How to create a desktop shortcut with the Windows Script Host
http://support.microsoft.com/kb/244677/

And if that looks feasible, I'll help you work more with it.

Regards

Rob.
Avatar of rflook
rflook

ASKER

Hmm, i have managed to make the shortcut program work in a batch file but what would be ideal is to batch create the shortcuts. Lets say i have a text file with multiple lines - each one of those lines contains a name that needs to be used. I wold like to be able to iterate through the text file and use the name on each of those lines to create a shortcut. Can this be done with a batch file?
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can fill an array with shortcut details, then iterate through that, using a VBS file.  Save this into a VBS file, and change the shortcut details.

'==========
arrDetails = Array(_
      "Filename1.lnk;C:\myicon1.ico;%windir%\notepad.exe", _
      "Filename2.lnk;C:\myicon2.ico;%windir%\notepad.exe", _
      "Filename3.lnk;C:\myicon3.ico;%windir%\notepad.exe" _
      )

Set WshShell = CreateObject("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")

For Each strDetail In arrDetails
      arrShortcut = Split(strDetail, ";")
      Set oMyShortcut = WshShell.CreateShortcut(strDesktop + "\" & arrShortcut(0))
      ' 3=Maximized 7=Minimized  4=Normal
      oMyShortcut.WindowStyle = 3
      oMyShortcut.IconLocation = arrShortcut(1)
      OMyShortcut.TargetPath = arrShortcut(2)
      oMyShortCut.Save
Next
'==========

Regards,

Rob.
rflook, have we provided a satisfactory solution for you?

Regards,

Rob.