本ページには広告が含まれています。
目次
任意のパスにショートカット(*.lnk)やURLショートカット(*.url)を新規に作成します。WshShortcut オブジェクト(*.lnkの場合)もしくはWshURLShortcut オブジェクト(*.urlの場合)が返ります。作成したショートカットはWshShell.CreateShortcutを実行時に保存されます。
- 構文
- Object = WshShell.CreateShortcut( strPathname )
- 引数
- strPathname 省略可
- 作成するショートカットのパスとファイル名
- 戻り値
プログラム実行例
メモ帳を起動するショートカットファイルを作成
カレントディレクトリにメモ帳.lnkのショートカットリンクを作成します。
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM WshShortcut = WshShell.CreateShortcut("メモ帳.lnk")
WshShortcut.TargetPath = "C:\Windows\System32\notepad.exe"
WshShortcut.Save使用関数
コマンドプロンプトのショートカットを生成
デスクトップにコマンドプロンプトへのショートカットリンクを作成します。
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM path = Shell.NameSpace(ssfDesktop).Self.Path
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM WshShortcut = WshShell.CreateShortcut(path + "\cmd.lnk")
WITH WshShortcut
.IconLocation = "C:\Windows\system32\imageres.dll, 11"
.TargetPath = "C:\WINDOWS\system32\cmd.exe"
.WindowStyle = 3
.WorkingDirectory = "%LOCALAPPDATA%"
.Save
ENDWITH結果

使用関数
デスクトップにChromeのショートカットを作成
デスクトップにGoogle Chromeで[createLink url="https://google.co.jp" title="https://google.co.jp"]をシークレットモードで起動するショートカットを作成します。
CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM Folder2 = Shell.NameSpace(ssfDesktop)
DIM path = Folder2.Self.Path + "\Chrome.lnk"
DIM WshShortcut = WshShell.CreateShortcut(path)
WITH WshShortcut
DIM chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
.Description = "Chromeをシークレットモードで起動します。"
.Hotkey = "Ctrl+Shift+C"
.IconLocation = chromePath + ",7"
.TargetPath = chromePath
.WindowStyle = 3
.Save
ENDWITH
Folder = Shell.NameSpace(FSO.GetParentFolderName(path))
DIM FolderItem = Folder.ParseName(FSO.GetFileName(path))
DIM ShellLinkObject = FolderItem.Getlink()
DIM Args[] = "--incognito", "https://google.co.jp"
WITH ShellLinkObject
.Arguments = JOIN(Args)
.Save
ENDWITH結果

使用関数
UWSCのショートカットをスタートアップに作成
C:\Program Files (x86)\UWSC\UWSC.exeのショートカットをスタートアップに作成します。
CONST ssfSTARTUP = 7
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM folderspec = Shell.NameSpace(ssfSTARTUP).Self.Path
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM WshShortcut = WshShell.CreateShortcut(FSO.BuildPath(folderspec, "UWSC.exe - ショートカット.lnk"))
WITH WshShortcut
.IconLocation = "C:\Program Files (x86)\UWSC\UWSC.exe, 0"
.TargetPath = "C:\Program Files (x86)\UWSC\UWSC.exe"
.WindowStyle = 1
.WorkingDirectory = "C:\Program Files (x86)\UWSC\"
.Save
ENDWITH使用関数
