如何获得Web快捷型LNK文件的目标?

发布于 2025-01-26 15:47:31 字数 1212 浏览 4 评论 0 原文

我发现这是一个相当独特的问题。我使用以下脚本创建了一个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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那一片橙海, 2025-02-02 15:47:31

您需要以略有不同的方式创建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.

我乃一代侩神 2025-02-02 15:47:31

Jeff Zeitlin ,谢谢,最终成为我的答案!我最终不得不做更多的事情来创建一个为URL创建自定义图标(使用略有不同的方法)。看来我将不得不删除链接并用URL替换它。我正在使用以下脚本(我从另一个堆栈溢出问题):

$WshShell = New-Object -comObject WScript.Shell
$targetPath = "http://internalwebsite/subsite"
$iconLocation = "https://internalwebsite/1.ico"
$iconFile = "IconFile=" + $iconLocation
$path = "$publicDesktop\usefulname.url"
$Shortcut = $WshShell.CreateShortcut($path)
$Shortcut.TargetPath = $targetPath
$Shortcut.Save()

Add-Content $path "HotKey=0"
Add-Content $path "$iconfile"
Add-Content $path "IconIndex=0"

然后,如果我想找出有关文件的信息,我可以使用:

get-content $path

这使得任何将来的脚本都非常容易。非常感谢您的帮助!

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):

$WshShell = New-Object -comObject WScript.Shell
$targetPath = "http://internalwebsite/subsite"
$iconLocation = "https://internalwebsite/1.ico"
$iconFile = "IconFile=" + $iconLocation
$path = "$publicDesktop\usefulname.url"
$Shortcut = $WshShell.CreateShortcut($path)
$Shortcut.TargetPath = $targetPath
$Shortcut.Save()

Add-Content $path "HotKey=0"
Add-Content $path "$iconfile"
Add-Content $path "IconIndex=0"

THEN, if I want to figure out information about the file, I can use:

get-content $path

This makes any future scripting against the path significantly easier. Thank you very much for the help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文