gpt4 book ai didi

powershell - GetVersionInfo 和 powershell 的参数异常

转载 作者:行者123 更新时间:2023-12-03 00:31:18 26 4
gpt4 key购买 nike

我正在尝试使用 powershell 获取文件的文件版本。如果我右键单击该文件并查看版本,它会显示一个值。这是我正在尝试的方式:

$path = "MSDE2000A";
$info = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path);

这是它抛出的异常信息:

Exception calling "GetVersionInfo" with "1" argument(s): "MSDE2000A.exe"
At line:1 char:58
+ $f = [system.diagnostics.fileversioninfo]::getversioninfo <<<< ("MSDE2000A.exe")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

我检查过的每个文件都有相同的结果。但是,如果我的路径是 c:\windows\notepad.exe(如在 example 中),它会按预期工作。怎么回事?

最佳答案

.NET 和 PowerShell 的当前目录概念并不总是相同的。尝试传入绝对路径。

[Diagnostics.FileVersionInfo]::GetVersionInfo('C:\Windows\System32\user32.dll')

ProductVersion FileVersion FileName
-------------- ----------- --------
6.1.7600.16385 6.1.7600.1638... C:\Windows\System32\user32.dll

此外,您可以像这样使用 Get-ChildItem 获取此信息:

Get-ChildItem C:\Windows\System32\user32.dll | fl VersionInfo

关于powershell - GetVersionInfo 和 powershell 的参数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1917738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com