WshShell.CreateShortcut メソッド
本ページには広告が含まれています。
任意のパスにショートカット(*.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
解説(自動生成)
- 1行目
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
変数WshShellを宣言し、WshShell オブジェクトを代入します。- 2行目
DIM WshShortcut = WshShell.CreateShortcut("メモ帳.lnk")
変数WshShortcutを宣言し、右辺の結果を代入します。- 3行目
WshShortcut.TargetPath = "C:\Windows\System32\notepad.exe"
- 4行目
コマンドプロンプトのショートカットを生成
デスクトップにコマンドプロンプトへのショートカットリンクを作成します。
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
結果
解説(自動生成)
- 1行目
- 定数ssfDesktopを定義し、0を割り当てます。
- 3行目
DIM Shell = CREATEOLEOBJ("Shell.Application")
変数Shellを宣言し、Shell オブジェクトを代入します。- 4行目
DIM path = Shell.NameSpace(ssfDesktop).Self.Path
変数pathを宣言し、右辺の結果を代入します。- 6行目
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
変数WshShellを宣言し、WshShell オブジェクトを代入します。- 7行目
DIM WshShortcut = WshShell.CreateShortcut(path + "\cmd.lnk")
変数WshShortcutを宣言し、右辺の結果を代入します。- 9、15行目
WITH WshShortcut
…
ENDWITH
- 10行目
.IconLocation = "C:\Windows\system32\imageres.dll, 11"
- 11行目
.TargetPath = "C:\WINDOWS\system32\cmd.exe"
- 12行目
- 13行目
.WorkingDirectory = "%LOCALAPPDATA%"
- 14行目
デスクトップにChromeのショートカットを作成
デスクトップにGoogle Chromeで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
結果

解説(自動生成)
- 1行目
- 定数ssfDesktopを定義し、0を割り当てます。
- 3行目
DIM Shell = CREATEOLEOBJ("Shell.Application")
変数Shellを宣言し、Shell オブジェクトを代入します。- 4行目
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
変数FSOを宣言し、FileSystemObject オブジェクトを代入します。- 5行目
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
変数WshShellを宣言し、WshShell オブジェクトを代入します。- 7行目
DIM Folder2 = Shell.NameSpace(ssfDesktop)
変数Folder2を宣言し、を表すFolder2 オブジェクトを代入します。- 8行目
DIM path = Folder2.Self.Path + "\Chrome.lnk"
変数pathを宣言し、Folder2 オブジェクトが示すFolderItem オブジェクト.Path + "\Chrome.lnk"を代入します。- 9行目
DIM WshShortcut = WshShell.CreateShortcut(path)
変数WshShortcutを宣言し、右辺の結果を代入します。- 11、19行目
WITH WshShortcut
…
ENDWITH
- 12行目
DIM chromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
変数chromePathを宣言し、C:\Program Files (x86)\Google\Chrome\Application\chrome.exeを代入します。- 13行目
.Description = "Chromeをシークレットモードで起動します。"
- 14行目
.Hotkey = "Ctrl+Shift+C"
- 15行目
.IconLocation = chromePath + ",7"
- 16行目
.TargetPath = chromePath
- 17行目
- 18行目
- 21行目
Folder = Shell.NameSpace(FSO.GetParentFolderName(path))
- 22行目
DIM FolderItem = Folder.ParseName(FSO.GetFileName(path))
変数FolderItemを宣言し、右辺の結果を代入します。- 23行目
DIM ShellLinkObject = FolderItem.Getlink()
変数ShellLinkObjectを宣言し、右辺の結果を代入します。- 24行目
DIM Args[] = "--incognito", "https://google.co.jp"
変数Args[]を宣言し、右辺の結果を代入します。- 26、29行目
WITH ShellLinkObject
…
ENDWITH
- 27行目
.Arguments = JOIN(Args)
- 28行目
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
解説(自動生成)
- 1行目
- 定数ssfSTARTUPを定義し、7を割り当てます。
- 3行目
DIM Shell = CREATEOLEOBJ("Shell.Application")
変数Shellを宣言し、Shell オブジェクトを代入します。- 4行目
DIM folderspec = Shell.NameSpace(ssfSTARTUP).Self.Path
変数folderspecを宣言し、右辺の結果を代入します。- 6行目
DIM WshShell = CREATEOLEOBJ("WScript.Shell")
変数WshShellを宣言し、WshShell オブジェクトを代入します。- 7行目
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
変数FSOを宣言し、FileSystemObject オブジェクトを代入します。- 8行目
DIM WshShortcut = WshShell.CreateShortcut(FSO.BuildPath(folderspec, "UWSC.exe - ショートカット.lnk"))
変数WshShortcutを宣言し、右辺の結果を代入します。- 10、16行目
WITH WshShortcut
…
ENDWITH
- 11行目
.IconLocation = "C:\Program Files (x86)\UWSC\UWSC.exe, 0"
- 12行目
.TargetPath = "C:\Program Files (x86)\UWSC\UWSC.exe"
- 13行目
- 14行目
.WorkingDirectory = "C:\Program Files (x86)\UWSC\"
- 15行目