将MSTSC添加到快捷方式目标Powershell [英] Add mstsc to shortcut target powershell

查看:320
本文介绍了将MSTSC添加到快捷方式目标Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于我要做什么以及为什么的一些背景知识.我们正在逐步从使用最终用户Win7计算机上的Office本地副本迁移到通过RDS 2012发布办公室.在2012年,您可以让最终用户计算机订阅Webfeed,该Webfeed将快捷方式放置到Appdata中的实际RDP文件中.为了使我们的图像在RDS之前可以大致镜像,我需要将快捷方式固定在任务栏上.如果您固定快捷方式,因为它来自RDS网关服务器,则任务栏上的图标就是.rdp文件的图标.如果您编辑快捷方式的目标并将mstsc.exe放在.rdp文件的路径之前,则可以使用快捷方式的那些图标将快捷方式固定到任务栏.

A little background about what I'm trying to do and why. We are slowly migrating from using a local copy of office on our end users Win7 machines to publishing office through RDS 2012. With 2012 you can have the end users machine subscribe to a webfeed which puts the shortcuts to the actual RDP files in Appdata. In order to have our image pretty much mirror before RDS, I need to pin the shortcuts to the taskbar. If you pin the shortcut as it comes from the RDS Gateway server the icon on the taskbar is that of the .rdp file. If you edit the target for the shortcut and put mstsc.exe before the path to the .rdp file you can then pin the shortcut to the taskbar using those icons of the shortcut.

我发现了有关如何更改快捷方式的目标字段的文章,但没有关于如何向当前内容添加内容的文章.由于每个用户的短裤路径都不同,因此需要一个环境变量.下面是我到目前为止尝试过的

I have found posts on how to change the target field of shortcuts but nothing on how to add something to what is currently there. An environment variable is needed since the path to the shorts will be different for each user. Below is I have tried thus far

      $Word = $env:userprofile + "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\RemoteApp and Desktop Connections\Microsoft Word 2010.lnk"

      $sh = New-Object -COM WScript.Shell
      $targetPath = $sh.CreateShortcut($Word).TargetPath
      $sh.TargetPath = "mstsc.exe" + $targetPath ## Make changes
      $sh.Save()  ## Save$shell = New-Object -COM WScript.Shell

我遇到的错误之一是:在此对象上找不到属性参数";这是错误的.确保它存在并且可设置.

One of the errors i'm getting is : Property 'Arguments' cannot be found on this object; make sure it exists and is settable.

任何帮助将不胜感激.

推荐答案

不是使用Shell COM对象,而是使用.Net包装器类呢?有一个出色的示例.

Instead of using Shell COM object, how about using a .Net wrapper class? There is a great sample.

要在Powershell中使用VBAccelerator的包装器,请提取源代码并像这样编译DLL,

To use the VBAccelerator's wrapper in Powershell, extract the source code and compile a DLL like so,

C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe /t:library /out:ShellLink.dll /r:System.Drawing.dll .\ShellLink.cs .\FileIcon.cs

这应该创建ShellLink.dll,您可以像这样将其添加为Powershell类型,

This should create ShellLink.dll, which you can add as Powershell type like so,

Add-Type -path .\ShellLink.dll

并通过创建新对象来使用该类,

And use the class by creating a new object like so,

$lnk = new-object vbAccelerator.Components.Shell.ShellLink
$lnk.Target = "C:\Windows\System32\mstsc.exe"
$lnk.Arguments = "some arguments"
$lnk.Description = "My awesome shortcut"
$lnk.Save("c:\temp\test.lnk")

这篇关于将MSTSC添加到快捷方式目标Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆