问题
I want to create a batch file which creates a shortcut on the desktop or in the start menu.
The shortcut needs to open a webpage which is a local windows server ip address(like 'http:\192.168..*:81\').
I also want to provide a custom image icon to the shortcut.
回答1:
I know this is an old thread but it was the first StackOverFlow page to popup in Google, so I thought I'd make a reply.
The following is a batch script that I use to manage URL shortcuts: (please note that this script assumes that an icon also exists - MyIconName.ico - in the same directory as this script. If an icon is not available or not required, simply omit the pertinent lines)
Please note also that any trailing spaces will affect the value of the variable...
@echo off
@echo.
@echo.
@echo.
::Set the application-specific string vars
SET AppDescription=MyAppName
SET IconName=MyIconName.ico
SET Shortcut_Name=MyShortcutName.url
SET URL_PATH=http://www.Google.com
::Set the common string vars
SET WORKING_PATH=%~dp0
SET ICONDEST=c:\ProgramData\%AppDescription%
SET LinkPath=%userprofile%\Desktop\%Shortcut_Name%
@echo. Copy Icon
IF EXIST "%ICONDEST%" (GOTO _CopyIcon)
mkdir "%ICONDEST%"
:_CopyIcon
copy "%WORKING_PATH%%IconName%" "%ICONDEST%"
echo.
echo. Create desktop shortcut...
echo [InternetShortcut] > "%LinkPath%"
echo URL=%URL_PATH% >> "%LinkPath%"
echo IDList= >> "%LinkPath%"
echo IconFile=%ICONDEST%\%IconName% >> "%LinkPath%"
echo IconIndex=0 >> "%LinkPath%"
echo HotKey=0 >> "%LinkPath%"
echo.
echo.
echo.
echo.
echo.You should now have a shortcut to %AppDescription% on your desktop...
echo.
echo.
pause
回答2:
If it weren't for the custom image icon requirement, I'd suggest using the following to create a batch file on the desktop like this:
echo start http://192.168.1.1:81 > "%userprofile%\desktop\Launch website.cmd"
Naturally, replace the address with the appropriate one. This doesn't create a shortcut (actually creates a file), and it won't give you a custom icon, but it's an easy way to accomplish the functionality you seem to be looking for.
Your description doesn't give enough information about the problem you're trying to solve, but if it really is simply what you say, you could also just create the shortcut once, by hand, and then use a batch file to copy that shortcut to wherever you wanted it.
Please add more detail to your question if we're missing the boat here...
回答3:
if you use Mozilla Firefox
start /MIN /d"C:\Program Files\Mozilla Firefox" firefox.exe http://www.yourlink.com
if you use Google Chrome
start /MIN /d"C:\Program Files\Google Chrome" chrome.exe http://www.yourlink.com
回答4:
There is no way you can do with just batch file/windows shell commands. There are two options:
- Use a VBScript as described here
- Use third-party tools
回答5:
I haven't tested it, but the link below seems to have a script in batch, yes batch, that creates shortcuts!
http://www.robvanderwoude.com/amb_shortcuts.php
来源:https://stackoverflow.com/questions/12528224/how-to-create-a-batch-file-to-create-a-shortcut-to-a-webpage