Mục lục bài viết
Cập Nhật: 2021-12-06 11:37:13,Bạn Cần tương hỗ về PowerShell create shortcut on desktop with arguments. You trọn vẹn có thể lại Comments ở phía dưới để Tác giả được tương hỗ.
by · Published January 22, năm nay · Updated March 7, 2018
Have you ever needed to create shortcuts while scripting. Shortcuts are simply .lnk files with a few details highlighting a few details of the file that you would like to launch. Many people simply copy an already created shortcut. With PowerShell you can actually create a shortcut from scratch by utilizing the New-Object commandlet. Here is the quick run down with explanation.
Step #1: The first step is to create a variable referencing a Wscript.Shell COM Object.
$Shell = New-Object -ComObject (“WScript.Shell”)
Step #2: The second step is to define the location and name of your shortcut. The following example will add the shortcut to the users desktop with a name of Your Shortcut.
$Shell = New-Object -ComObject (“WScript.Shell”)
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + “DesktopYour Shortcut.lnk”)
Step #3: The third step is to add the target path, any relevant arguments, along with anything else that may be required.
$Shell = New-Object -ComObject (“WScript.Shell”)
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + “DesktopYour Shortcut.lnk”)
$ShortCut.TargetPath=”yourexecutable.exe”
$ShortCut.Arguments=”-arguementsifrequired”
$ShortCut.WorkingDirectory = “c:yourexecutablethư mụcpath”;
$ShortCut.WindowStyle = 1;
$ShortCut.Hotkey = “CTRL+SHIFT+F”;
$ShortCut.IconLocation = “yourexecutable.exe, 0”;
$ShortCut.Description = “Your Custom Shortcut Description”;
Step #4: The final step is to envoke the Save() method to save your shortcut.
$Shell = New-Object -ComObject (“WScript.Shell”)
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + “DesktopYour Shortcut.lnk”)
$ShortCut.TargetPath=”yourexecutable.exe”
$ShortCut.Arguments=”-arguementsifrequired”
$ShortCut.WorkingDirectory = “c:yourexecutablethư mụcpath”;
$ShortCut.WindowStyle = 1;
$ShortCut.Hotkey = “CTRL+SHIFT+F”;
$ShortCut.IconLocation = “yourexecutable.exe, 0”;
$ShortCut.Description = “Your Custom Shortcut Description”;
$ShortCut.Save()
Step #5: As a bonus here is how you would create a Favorite in Windows which is a .url shortcut.
$Shell = New-Object -ComObject (“WScript.Shell”)
$Favorite = $Shell.CreateShortcut($env:USERPROFILE + “DesktopYour Shortcut.url”)
$Favorite.TargetPath = “yoururl”;
$Favorite.Save()
– Một số Keywords tìm kiếm nhiều : ” Review PowerShell create shortcut on desktop with arguments tiên tiến và phát triển nhất , Share Link Cập nhật PowerShell create shortcut on desktop with arguments “.
Bạn trọn vẹn có thể để lại phản hồi nếu gặp yếu tố chưa hiểu nghen.
#PowerShell #create #shortcut #desktop #arguments