我发现一个讨厌的VBS办法做到这一点,但我正在寻找一个原生辣妹步骤编辑.LNK文件的属性。我们的目标是接触到远程计算机,复制与最正确的属性的现有的快捷方式,并编辑他们夫妇。

如果它只是更容易编写一个新的快捷方式文件,将工作过。

有帮助吗?

解决方案

Copy-Item $sourcepath $destination  ## Get the lnk we want to use as a template
$shell = New-Object -COM WScript.Shell
$shortcut = $shell.CreateShortcut($destination)  ## Open the lnk
$shortcut.TargetPath = "C:\path\to\new\exe.exe"  ## Make changes
$shortcut.Description = "Our new link"  ## This is the "Comment" field
$shortcut.Save()  ## Save

实测值VB的版本这里的代码: 的http:// www.tutorialized.com/view/tutorial/Extract-the-target-file-from-a-shortcut-file-.lnk/18349

其他提示

下面是我用来对付.LNK文件的功能。他们被修改的功能版本中 href="http://powershell.com/cs/media/p/7895.aspx">。我已经改善Get-Shortcut通过传递字符串*将其展开成组的FileInfo对象的处理等dir通配符。

function Get-Shortcut {
  param(
    $path = $null
  )

  $obj = New-Object -ComObject WScript.Shell

  if ($path -eq $null) {
    $pathUser = [System.Environment]::GetFolderPath('StartMenu')
    $pathCommon = $obj.SpecialFolders.Item('AllUsersStartMenu')
    $path = dir $pathUser, $pathCommon -Filter *.lnk -Recurse 
  }
  if ($path -is [string]) {
    $path = dir $path -Filter *.lnk
  }
  $path | ForEach-Object { 
    if ($_ -is [string]) {
      $_ = dir $_ -Filter *.lnk
    }
    if ($_) {
      $link = $obj.CreateShortcut($_.FullName)

      $info = @{}
      $info.Hotkey = $link.Hotkey
      $info.TargetPath = $link.TargetPath
      $info.LinkPath = $link.FullName
      $info.Arguments = $link.Arguments
      $info.Target = try {Split-Path $info.TargetPath -Leaf } catch { 'n/a'}
      $info.Link = try { Split-Path $info.LinkPath -Leaf } catch { 'n/a'}
      $info.WindowStyle = $link.WindowStyle
      $info.IconLocation = $link.IconLocation

      New-Object PSObject -Property $info
    }
  }
}

function Set-Shortcut {
  param(
  [Parameter(ValueFromPipelineByPropertyName=$true)]
  $LinkPath,
  $Hotkey,
  $IconLocation,
  $Arguments,
  $TargetPath
  )
  begin {
    $shell = New-Object -ComObject WScript.Shell
  }

  process {
    $link = $shell.CreateShortcut($LinkPath)

    $PSCmdlet.MyInvocation.BoundParameters.GetEnumerator() |
      Where-Object { $_.key -ne 'LinkPath' } |
      ForEach-Object { $link.$($_.key) = $_.value }
    $link.Save()
  }
}

我不认为有一个原生的方式。

有本DOS UTIL: Shortcut.exe

您还需要使用util复制到远程系统,然后使用WMI使你正在寻找的变化可能调用它。

我想更简单的方法将是覆盖和/或创建一个新文件。

你有通过远程共享访问这些系统?

一个短除了@ JasonMArcher的回答..

要看看你能在$shortcut后只需运行$shortcut = $shell.CreateShortcut($destination)可用特性的 PS 的。 这将打印所有属性和其当前值。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top