我想在桌面上创建Autostart目录的快捷方式。
我知道如何创建任何应用程序的快捷方式,例如记事本,但如何创建目录的快捷方式?
我正在尝试这样的事情
$objShell = New-Object -ComObject ("WScript.Shell")
$objShortCut = $objShell.CreateShortcut($env:USERPROFILE + "\Desktop" + "\Autostart.lnk")
$objShortCut.TargetPath="C:\Users\" + $env:USERPROFILE + "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
$objShortCut.Save()
错误:
+ $objShortCut.TargetPath="C:\Users\" + $env:USERPROFILE + "\AppData\Ro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
答案 0 :(得分:3)
您可以使用环境类:
$StartupFolder = [Environment]::GetFolderPath('Startup')
$DesktopFolder = [Environment]::GetFolderPath('Desktop')
$wshshell = New-Object -ComObject WScript.Shell
$link = $wshshell.CreateShortcut((Join-path $DesktopFolder "Autostart.lnk"))
$link.TargetPath = $StartupFolder
$link.Save()
答案 1 :(得分:3)
删除"C:\Users\" +
。
$objShell = New-Object -ComObject ("WScript.Shell")
$objShortCut = $objShell.CreateShortcut($env:USERPROFILE + "\Desktop" + "\Autostart.lnk")
$objShortCut.TargetPath=$env:USERPROFILE + "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
$objShortCut.Save()