Computing.Net > Forums > Programming > make a shortcut with a batchfile

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

make a shortcut with a batchfile

Reply to Message Icon

Name: mherber2
Date: March 28, 2009 at 08:30:17 Pacific
OS: Windows XP
CPU/Ram: UNKNOWN
Subcategory: Batch
Comment:

hello all,

I have throughly research this and abut 19 out of 20 sites say its not possible to create a shortcut with a batch file however i have found a batch file that creates a shortcust based on peramiters it is passed. i need the batch file to ask for the input rather than have peramiters passed.

i know this can be done with something like this:

set /p MyVal=Enter a value: %=%

This batch file does work for the most part. it creates the short in the start menu in a folder called }new{ but then errors out. the problem im having is deciphering the batch file can someone please help me out with ths?

here is the batch file:
@echo off & setlocal
::For Windows NT 4.0 users only!!!
::Creates LNK and PIF files from the command line.
::Author: Walter Zackery
if not %1[==[ if exist %1 goto start
echo You must pass the path of a file or folder to the
echo batch file as a shortcut target.
if not %1[==[ echo %1 is not an existing file or folder
(pause & endlocal & goto:eof)
:start
(set hkey=HKEY_CURRENT_USER\Software\Microsoft\Windows)
(set hkey=%hkey%\CurrentVersion\Explorer\Shell Folders)
(set inf=rundll32 setupapi,InstallHinfSection DefaultInstall)
start/w regedit /e %temp%\#57#.tmp "%hkey%"

for /f "tokens=*" %%? in (
'dir/b/a %1? 2^>nul') do (set name=%%~nx?)

for /f "tokens=2* delims==" %%? in (
'findstr/b /i """desktop"""= %temp%\#57#.tmp') do (set d=%%?)

for /f "tokens=2* delims==" %%? in (
'findstr/b /i """programs"""= %temp%\#57#.tmp') do (set p=%%?)

(set d=%d:\\=\%) & (set p=%p:\\=\%)
if not %2[==[ if exist %~fs2\nul (set d=%~fs2)
if not %2[==[ if exist %~fs2nul (set d=%~fs2)
set x=if exist %2\nul
if not %2[==[ if not %d%==%2 %x% if "%~p2"=="\" set d=%2
echo %d%|find ":\" >nul||(set d=%d%\)
(set file=""""""%1"""""")
for /f "tokens=1 delims=:" %%? in ("%file:"=%") do set drive=%%?
(set progman=setup.ini, progman.groups,,)
echo > %temp%\#k#.inf [version]
echo >>%temp%\#k#.inf signature=$chicago$
echo >>%temp%\#k#.inf [DefaultInstall]
echo >>%temp%\#k#.inf UpdateInis=Addlink
echo >>%temp%\#k#.inf [Addlink]
echo >>%temp%\#k#.inf %progman% ""group200="}new{"""
echo >>%temp%\#k#.inf setup.ini, group200,, """%name%"",%file%
start/w %inf% 132 %temp%\#k#.inf
del %temp%\#k#.inf %temp%\#57#.tmp
move %p%\"}new{\*.*" %d% >nul 2>&1
rd %p%\}new{ 2>nul
move %p%\}new{.lnk %d%\"drive %drive%.lnk" >nul 2>&1
endlocal

peramiters:

Parameter number one must be the complete path of the file or folder
that you're trying to create a shortcut to.

Parameter number two must be the complete path of the folder that you
wish to locate the shortcut in.

Parameter number three is the trickiest. It must be the complete path
to the Programs folder. The Programs folder is the folder that
contains your Start Menu shortcuts. It's normal location is
c:\windows\start menu\programs, or possibly
c:\windows\profiles\xxx\start menu\programs, where xxx is your user
name if you're using profiles. It's possible to obtain the location of
the Programs folder using a batch file, but doing so would more than
double the size of the batch file, so I refrained.

Parameter number four must be the name that you wish to give to the
shortcut. Don't attach the LNK extension to this name, because Windows
will do it for you when it creates the shortcut.



Sponsored Link
Ads by Google

Response Number 1
Name: mherber2
Date: March 30, 2009 at 11:50:39 Pacific
Reply:

is this the correct place for this post?


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: make a shortcut with a batchfile

Set Extentions with a Batchfile www.computing.net/answers/programming/set-extentions-with-a-batchfile/11788.html

Installing a Shortcut with a Custom www.computing.net/answers/programming/installing-a-shortcut-with-a-custom/13518.html

Making a list with batch www.computing.net/answers/programming/making-a-list-with-batch/15947.html