就我而言,我在与数据不同的文件夹中有一个可执行文件,并使用修改了“开始”目录的快捷方式链接它们,例如:
C:/Test - Data dir
C:/Test/3 - Exe dir
Shortcut: C:/Test/3/test3.exe :: Start In C:/Test
但是我需要一种自动生成快捷方式的方法,因此我有一个批处理文件,它在桌面上创建当前目录 exe 的快捷方式,但是因为我不知道如何更改目录中的启动,所以它们不起作用。
答案1
我使用这个批处理文件。如你所见,我不是原作者(一个叫 Walter Zackery 的聪明人),我只是在几个地方做了修改(上面写着由 gw 修改的地方)
它没有回答你的标题问题,因为它没有设置起始目录。但它应该按照你在问题详细信息中描述的那样做。
示例调用:
link c:\Test\3\test3.exe "my shortcut" c:\test\x.txt some_other_parameter another_parameter
这将使用 test3.exe 打开测试目录中的 x.txt,并附带一些其他参数(其他参数不能是带引号的参数)。
::Subject: Re: Shortcut in start menu
::Date: Mon, 27 Dec 1999 06:34:17 -0500
::From: "Walter Zackery" <[email protected]>
::Organization: Prodigy Internet http://www.prodigy.com
::Newsgroups: alt.msdos.batch
::References: 1 , 2 , 3
::
::I posted this in an NT group 2 weeks ago, but here it is again.
::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.
::
::Here's an example command line for the batch file.
::
::link.bat c:\windows\notepad.exe c:\windows\desktop "A Notepad Shortcut" fred.txt
:: gw 22/5/9 made certain changes:
:: uses reg not regedit, since regedit export format changed
:: can pass parameter 3 for shortcut name
:: can pass parameter 4 ,5, .. 9 for command line parameters after name, these
:: will NEVER be quoted in the shortcut so make sure to use short paths
::@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
:: gw changed so can pass name as parameter 2
if %3_==_ for /f "tokens=*" %%? in (
'dir/b/a %1? 2^>nul') do (set name=%%~nx?)
if %name%_==_ set name=%3
(set hkey=HKEY_CURRENT_USER\Software\Microsoft\Windows)
(set hkey=%hkey%\CurrentVersion\Explorer\Shell Folders)
(set inf=rundll32 setupapi,InstallHinfSection DefaultInstall)
:: gw - replaced with reg call to get inot NT4 format which findstr understands
::start/w regedit /e %temp%\#57#.tmp "%hkey%"
reg export "%hkey%" %temp%\#57#.tmp /nt4
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"""""")
:set_params
if %4_==_ goto create_file
:: can't even get quotes in with this indirect method
:: if %4==/q (
:: set params=%params% "
:: set first_in_quotes=true
:: ) else if %4==\q (
:: set params=%params%"
:: ) else if first_in_quotes==true (
:: set params=%params%%4
:: set first_in_quotes=
:: ) else set params=%params% %4
set params=%params% %4
shift
goto set_params
:create_file
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% %params%
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