如何在运行在64位模式下的PowerShell中调用TpmVscMgr.exe(一个32位实用程序)

huangapple go评论82阅读模式
英文:

How to Call TpmVscMgr.exe (a 32-Bit Utility) from PowerShell Running in 64-Bit Mode

问题

I'm having trouble running TpmVscMgr.exe from a PowerShell script that runs in 64-bit mode on Windows 10. I gather that TpmVscMgr.exe is a 32-bit utility, as witnessed by the fact that it resides in C:\Windows\System32. Trying to run it straight-up from my script leads to an exception saying that the cmdlet cannot be found. I have also tried this method just to destroy a TPM slot for starters:

Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show('Test')

try
{
	$32bitPSCode =
	{
		$tpmVscMgrFullyQualified = (Join-Path ([System.Environment]::SystemDirectory) "TpmVscMgr.exe")
		$cmdLine = "$tpmVscMgrFullyQualified destroy /instance ROOT\SMARTCARDREADER
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show('Test')

try
{
	$32bitPSCode =
	{
		$tpmVscMgrFullyQualified = (Join-Path ([System.Environment]::SystemDirectory) "TpmVscMgr.exe")
		$cmdLine = "$tpmVscMgrFullyQualified destroy /instance ROOT\SMARTCARDREADER\0000"
		Invoke-Expression $cmdLine
	}

	Invoke-Command -ScriptBlock $32bitPSCode -ConfigurationName microsoft.powershell32 -ComputerName .
}
catch
{
	[System.Windows.MessageBox]::Show($_)
}
00"
Invoke-Expression $cmdLine } Invoke-Command -ScriptBlock $32bitPSCode -ConfigurationName microsoft.powershell32 -ComputerName . } catch { [System.Windows.MessageBox]::Show($_) }

This does not even seem to lead to an exception. The script seems to get into some kind of hang, followed by terminating with a console message that says,

[...] Connecting to remote server ... failed with the following error message : The client cannot connect to the destination specified in the
request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service
running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and
configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (...:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroke
英文:

I'm having trouble running TpmVscMgr.exe from a PowerShell script that runs in 64-bit mode on Windows 10. I gather that TpmVscMgr.exe is a 32-bit utility, as witnessed by the fact that it resides in C:\Windows\System32. Trying to run it straight-up from my script leads to an exception saying that the cmdlet cannot be found. I have also tried this method just to destroy a TPM slot for starters:

Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show('Test')

try
{
	$32bitPSCode =
	{
		$tpmVscMgrFullyQualified = (Join-Path ([System.Environment]::SystemDirectory) "TpmVscMgr.exe")
		$cmdLine = "$tpmVscMgrFullyQualified destroy /instance ROOT\SMARTCARDREADER
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show('Test')
try
{
$32bitPSCode =
{
$tpmVscMgrFullyQualified = (Join-Path ([System.Environment]::SystemDirectory) "TpmVscMgr.exe")
$cmdLine = "$tpmVscMgrFullyQualified destroy /instance ROOT\SMARTCARDREADER\0000"
Invoke-Expression $cmdLine
}
Invoke-Command -ScriptBlock $32bitPSCode -ConfigurationName microsoft.powershell32 -ComputerName .
}
catch
{
[System.Windows.MessageBox]::Show($_)
}
00" Invoke-Expression $cmdLine } Invoke-Command -ScriptBlock $32bitPSCode -ConfigurationName microsoft.powershell32 -ComputerName . } catch { [System.Windows.MessageBox]::Show($_) }

This does not even seem to lead to an exception. The script seems to get into some kind of hang, followed by terminating with a console message that says,

[...] Connecting to remote server ... failed with the following error message : The client cannot connect to the destination specified in the
request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service
running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and
configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (...:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroke

答案1

得分: 0

有一个误解在这里。从64位应用程序的角度看,C:\Windows\System32并不是32位目录。这实际上是微软出于兼容性原因而命名的本机64位目录(叹气)。只有当32位应用程序查看C:\Windows\System32时,它才会看到实际的32位目录(参见文件系统重定向器)。

当你在64位PowerShell控制台中输入(Get-Command TpmVscMgr).Source命令时,它输出C:\WINDOWS\system32\tpmvscmgr.exe,这实际上意味着TpmVscMgr是一个64位应用程序!而且没有32位版本(当从32位PowerShell控制台运行时,Get-Command TpmVscMgr会失败)。

因此,实际上你不需要使用Invoke-Command以32位模式运行PowerShell,你可以直接调用命令TpmVscMgr而无需多言。你甚至不需要指定它的完整路径,因为系统目录中的本机命令会被自动找到。

TpmVscMgr destroy /instance ROOT\SMARTCARDREADER
TpmVscMgr destroy /instance ROOT\SMARTCARDREADER
TpmVscMgr destroy /instance ROOT\SMARTCARDREADER\0000
000
000

链接:

英文:

There is a misconception here. C:\Windows\System32 isn't the 32-bit directory, when seen from a 64-bit application. It's the native 64-bit directory which MSFT named like this for compatibility reasons (sigh). Only when a 32-bit application looks at C:\Windows\System32, it will see the actual 32-bit directory (see File System Redirector).

When you enter (Get-Command TpmVscMgr).Source command in a 64-bit PowerShell console, it outputs C:\WINDOWS\system32\tpmvscmgr.exe, which actually means TpmVscMgr is a 64-bit application! And there is no 32-bit version (Get-Command TpmVscMgr fails, when run from a 32-bit PowerShell console).

It follows that you actually don't need to use Invoke-Command to run PowerShell in 32-bit mode and you can simply call the command TpmVscMgr without further ado. You don't even need to specify it's full path, because native commands in system directory will be found automatically.

TpmVscMgr destroy /instance ROOT\SMARTCARDREADER
TpmVscMgr destroy /instance ROOT\SMARTCARDREADER
TpmVscMgr destroy /instance ROOT\SMARTCARDREADER\0000
000
000

Links:

huangapple
  • 本文由 发表于 2023年3月7日 16:39:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75659649.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定