2012-02-20 18:24:10 +0000 2012-02-20 18:24:10 +0000
81
81
Advertisement

CMDからショートカットを作成するには?

Advertisement

コマンドラインユーティリティを使って、別のファイルや実行ファイルへのショートカットファイル(.lnk)を作成するには?

Advertisement

回答 (8)

56
56
56
2012-02-20 20:06:04 +0000

このサイトには非常に有益な情報があります。 http://ss64.com/nt/shortcut.html

私が持っていないいくつかのリソースキットに shortcut.exe があるようです。 他の多くのサイトが言及しているように、バッチファイルから行う方法は組み込みではありません。

しかし、あなたはVBスクリプトからそれを行うことができます:

以下のVBscriptのオプションセクションはコメントアウトされています:

Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "C:\MyShortcut.LNK"
Set oLink = oWS.CreateShortcut(sLinkFile)
oLink.TargetPath = "C:\Program Files\MyApp\MyProgram.EXE"
' oLink.Arguments = ""
' oLink.Description = "MyProgram"   
' oLink.HotKey = "ALT+CTRL+F"
' oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
' oLink.WindowStyle = "1"   
' oLink.WorkingDirectory = "C:\Program Files\MyApp"
oLink.Save

だから、あなたが本当にmustそれを行う場合は、その後、あなたのバッチファイルは、ディスクにVBスクリプトを書き込み、それを呼び出して、再びそれを削除することができます。たとえば、次のように:

@echo off
echo Set oWS = WScript.CreateObject("WScript.Shell") > CreateShortcut.vbs
echo sLinkFile = "%HOMEDRIVE%%HOMEPATH%\Desktop\Hello.lnk" >> CreateShortcut.vbs
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> CreateShortcut.vbs
echo oLink.TargetPath = "C:\Windows\notepad.exe" >> CreateShortcut.vbs
echo oLink.Save >> CreateShortcut.vbs
cscript CreateShortcut.vbs
del CreateShortcut.vbs

上記のスクリプトを実行すると、デスクトップ上の新しいショートカットが表示されます:

ここでは、匿名の貢献者(マイナーな修正で更新)からのより完全なスニペットです:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET LinkName=Hello
SET Esc_LinkDest=%%HOMEDRIVE%%%%HOMEPATH%%\Desktop\!LinkName!.lnk
SET Esc_LinkTarget=%%SYSTEMROOT%%\notepad.exe
SET cSctVBS=CreateShortcut.vbs
SET LOG=".\%~N0_runtime.log"
((
  echo Set oWS = WScript.CreateObject^("WScript.Shell"^) 
  echo sLinkFile = oWS.ExpandEnvironmentStrings^("!Esc_LinkDest!"^)
  echo Set oLink = oWS.CreateShortcut^(sLinkFile^) 
  echo oLink.TargetPath = oWS.ExpandEnvironmentStrings^("!Esc_LinkTarget!"^)
  echo oLink.Save
)1>!cSctVBS!
cscript //nologo .\!cSctVBS!
DEL !cSctVBS! /f /q
)1>>!LOG! 2>>&1
24
24
24
2014-11-06 18:05:38 +0000

ここでは powershell を使った同様の解決策があります (私は知っています、あなたはおそらく PS でバッチファイル全体を書き換えることができますが、もしあなたが Get It Done™ をしたいだけなら…)

set TARGET='D:\Temp'
set SHORTCUT='C:\Temp\test.lnk'
set PWS=powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile

%PWS% -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut(%SHORTCUT%); $S.TargetPath = %TARGET%; $S.Save()"

あなたのファイルで PS へのパスを明示的に指定しなければならないかもしれませんが、それは動作するはずです。あなたがこのオブジェクトを介して、あまりにも、あなたがmangleすることができますいくつかの追加の属性があります:

Name MemberType Definition                             
---- ---------- ----------                             
Load Method void Load (string)                     
Save Method void Save ()                           
Arguments Property string Arguments () {get} {set}        
Description Property string Description () {get} {set}      
FullName Property string FullName () {get}               
Hotkey Property string Hotkey () {get} {set}           
IconLocation Property string IconLocation () {get} {set}     
RelativePath Property string RelativePath () {set}           
TargetPath Property string TargetPath () {get} {set}       
WindowStyle Property int WindowStyle () {get} {set}         
WorkingDirectory Property string WorkingDirectory () {get} {set}
17
Advertisement
17
17
2013-09-30 23:24:55 +0000

shortcut.exeの他にも、NirCmdのコマンドライン版を使用してショートカットを作成することができます http://nircmd.nirsoft.net/shortcut.html

12
12
12
2014-04-24 16:26:05 +0000

mklinkコマンドを使ってみませんか?C:\WindowsSystem32>mklink シンボリックリンクを作成します。リンク対象

/D Creates a directory symbolic link. Default is a file
            symbolic link.
    /H Creates a hard link instead of a symbolic link.
    /J Creates a Directory Junction.
    Link specifies the new symbolic link name.
    Target specifies the path (relative or absolute) that the new link
            refers to.
7
Advertisement
7
7
2012-02-20 18:42:56 +0000

ここでのすべての議論の後、これは私の提案する解決策です:ダウンロードしてください。ダウンロード: http://optimumx.com/download/Shortcut.zip デスクトップに解凍してください。今、あなたがscrum.pdfというファイルのショートカットを作成したいと仮定します(デスクトップにもあります): 1. CMDを開き、デスクトップのフォルダに移動 2. run: Shortcut.exe /f:"%USERPROFILE%\Desktop\sc.lnk" /a:c /t:%USERPROFILE%\Desktop\scrum.pdf

それはあなたのデスクトップに元のファイル(scrum.pdf)を指すsc.lnkというショートカットを作成します。

0
0
0
2015-07-21 15:01:08 +0000

このトピックは古いものですが、私のために働いた簡単な解決策を提供したいと思いました。その後、私は私のデスクトップ上にショートカットを作成し、私のC:ドライブ上のicoファイルにアイコンを設定します。私はその後、私のユーザーがアクセスできるネットワーク共有に.icoとショートカットの両方をコピーしました。そこで私は次のバッチファイルを書き、ユーザーのwindows 7のデスクトップにicoと.urlをコピーしました。これですべてのユーザーのデスクトップにショートカットが作成され、ショートカットを作成するときに設定したアイコンファイルが保持されます。私はこれが誰かを助けることを願っています。

0
Advertisement
0
0
2015-04-12 19:14:32 +0000

このフリープログラムには必要な機能があります http://www.nirsoft.net/utils/nircmd2.html 。(同ページからのサンプル)"Create a shortcut to Windows calculator under Start Menu->Programs->Calculators nircmd.exe shortcut "f:\winnt\system32\calc.exe" "~$folder.programs$\Calculators" "Windows Calculator"

試してみたサンプル: nircmd.exe shortcut “c:windowss\system32\calc.exe” “~$folder.desktop$” “Windows Calculator”

0
0
0
2020-01-24 16:58:48 +0000

手順 1: CMD ファイルの場所を開く


手順 2: コマンドプロンプトのプロパティを右クリックし、お気に入りのショートカットを設定します。

Advertisement
Advertisement