我发现这是一个相当独特的问题。我使用以下脚本创建了一个Web快捷方式:
$target = "http://internalwebsite/subsite"
$shortcut_lnk = "$publicDesktop\usefulname.lnk"
$wscriptshell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($Shortcut_lnk)
$Shortcut.TargetPath = $Target
$ShortCut.IconLocation = "https://internalwebsite/1.ico, 0";
$Shortcut.Save()
不幸的是,目标是HTTP而不是HTTP。我想检测任何具有不安全版本的快捷方式,然后用安全版本替换它。
我找到了以下代码,该代码为 at 可以为我提供所需的信息:
$shortcut = 'C:\users\public\Desktop\usefulname.lnk'
$sh = New-Object -ComObject WScript.Shell
$target = $sh.CreateShortcut($shortcut).TargetPath
但是,这尚未返回数据。如果我刚运行:
$sh.CreateShortcut($shortcut)
返回:
FullName : C:\users\public\Desktop\usefulname.lnk
Arguments :
Description :
Hotkey :
IconLocation : https://internalwebsite/1.ico,0
RelativePath :
TargetPath :
WindowStyle : 1
WorkingDirectory :
我已经确认该链接按预期工作。我现在的问题 - 如何获得实际的Web链接?如果我转到链接的属性,我会发现目标类型是网站(http:// internalwebsite/subsite),并且目标是相同的信息。但是到目前为止,我的Google-Fu在列出目标类型方面却一无所获,或者解释了为什么我无法拉动路径(或任何替代方法)。
如果有人能提供帮助,我将非常感谢!
This is a rather unique issue, I'm finding. I have created a web shortcut using the following script:
$target = "http://internalwebsite/subsite"
$shortcut_lnk = "$publicDesktop\usefulname.lnk"
$wscriptshell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($Shortcut_lnk)
$Shortcut.TargetPath = $Target
$ShortCut.IconLocation = "https://internalwebsite/1.ico, 0";
$Shortcut.Save()
Unfortunately, the target is http instead of HTTPS. I would like to detect any shortcuts that have the unsecure version and replace it with the secure version.
I've found the following code, which is supposed to give me the information I need:
$shortcut = 'C:\users\public\Desktop\usefulname.lnk'
$sh = New-Object -ComObject WScript.Shell
$target = $sh.CreateShortcut($shortcut).TargetPath
However, this returns no data. If I just run:
$sh.CreateShortcut($shortcut)
It returns:
FullName : C:\users\public\Desktop\usefulname.lnk
Arguments :
Description :
Hotkey :
IconLocation : https://internalwebsite/1.ico,0
RelativePath :
TargetPath :
WindowStyle : 1
WorkingDirectory :
I've confirmed that the link works as intended. My question now - how do I get the actual web link? If I go to the properties of the link, I see that the target type is the website (http://internalwebsite/subsite) and the target is greyed out with the same info. But so far, my Google-fu has yielded nothing in regards to listing the target type, or explaining why I can't pull the path (or any alternative methods).
If anyone can help I would greatly appreciate it!
发布评论
评论(2)
您需要以略有不同的方式创建Web快捷方式。根据此技术论坛发布,文件名必须具有
.url
而不是.lnk <的扩展名。 /code>,并且您必须明确调用对象的
.save()
方法。You need to create the web shortcut in a slightly different way. According to this TechNet forum posting, the filename must have an extension of
.url
rather than.lnk
, and you must explicitly call the.Save()
method of the object.Jeff Zeitlin ,谢谢,最终成为我的答案!我最终不得不做更多的事情来创建一个为URL创建自定义图标(使用略有不同的方法)。看来我将不得不删除链接并用URL替换它。我正在使用以下脚本(我从另一个堆栈溢出问题):
然后,如果我想找出有关文件的信息,我可以使用:
这使得任何将来的脚本都非常容易。非常感谢您的帮助!
Jeff Zeitlin, thank you, that ended up being the answer for me! I ended up having to do a little more looking to create a custom icon for a URL (uses a slightly different method). Looks like I'm going to have to remove the link and replace it with a URL. I'm using the following script (part of which I pilfered from a different stack overflow question):
THEN, if I want to figure out information about the file, I can use:
This makes any future scripting against the path significantly easier. Thank you very much for the help!