小编Кир*_*пин的帖子

在 Windows 任务栏中显示进度 (Powershell)

我想弄清楚如何在任务栏上显示进度。通过 PowerShell。

在此输入图像描述

据我了解,我应该使用这样的东西:

$Progress = [System.Windows.Shell.TaskbarItemInfo]::New()

$Progress.ProgressState = 'Normal'
$Progress.ProgressValue = 0.3
Run Code Online (Sandbox Code Playgroud)

但这是行不通的。我究竟做错了什么?如何在任务栏上显示进度?感谢您

.net powershell

5
推荐指数
1
解决办法
1257
查看次数

将 argb 转换为字符串

哪种方法允许将 ARGB 转换为字符串'int, int, int'?例子。将$Main背景色设置为一个字符串'0, 100, 200'。返回$Main.BackColor给出 ARGB 但不是字符串 '0, 100, 200':

$Main  = [System.Windows.Forms.Form] @{
    BackColor = '0, 100, 200'
}

$Main.BackColor
--------------
R             : 0
G             : 100
B             : 200
A             : 255
IsKnownColor  : False
IsEmpty       : False
IsNamedColor  : False
IsSystemColor : False
Name          : ff0064c8
Run Code Online (Sandbox Code Playgroud)

To.String()方法返回结果Color [A=255, R=0, G=100, B=200] 。这不是预期的。

目前我正在这样做:

 ('R', 'G', 'B').ForEach({ $Main.BackColor.$_ }) -join ', '

--------------
0, 100, …
Run Code Online (Sandbox Code Playgroud)

powershell winforms

4
推荐指数
1
解决办法
219
查看次数

RunSpace 及其关闭

在使用使用 RunSpace 的脚本时,我发现它占用越来越多的系统内存。据我了解,这是由于打开的 RunSpace 完成后不会关闭。它们保留在内存中,积累兆字节。

如何正确关闭RunSpace?然而,我不知道需要多长时间——1秒或1小时。完成后自行关闭。

作为示例,我将给出任意脚本。

第一个脚本是我如何在 RunSpace 完成时关闭它(它显然不起作用)。

$Array = 1..10000

$PowerShell = [PowerShell]::Create()
$RunSpace = [Runspacefactory]::CreateRunspace()
$RunSpace.Open()

$RunSpace.SessionStateProxy.SetVariable('Array', $Array)
$RunSpace.SessionStateProxy.SetVariable('PowerShell', $PowerShell)

$PowerShell.Runspace = $RunSpace

[void]$PowerShell.AddScript({

   # Fill the system memory so that it can be seen in the Task Manager.
   $Array += $Array
   $Array

   # Closing the Process, which should close the RunSpace, but this does not happen.
   $Powershell.Runspace.Dispose()
   $PowerShell.Dispose()
})

$Async = $PowerShell.BeginInvoke()

# Other jobs in the main thread...

Run Code Online (Sandbox Code Playgroud)

从系统内存来看,第二个脚本似乎更正确。然而,它当然不适用于生活,因为它Start-Sleep 10会冻结主进程。

$Array = …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-sdk runspace

3
推荐指数
1
解决办法
4767
查看次数

驱动器盘符 + 驱动器物理类型 (Powershell)

有没有一种方法可以让我们获取每个驱动程序的字母和物理类型?也就是说,获取一个数组,其中如下所示:

$Drivers = *Get-Something*   # Where $Drivers is @{} array 
$Drivers
---
C: SSD
D: HDD
E: SSD
F: SSD
Run Code Online (Sandbox Code Playgroud)

我需要将这两个数据绑定在一个数组中。第一个包含字母。第二个包含物理类型:

$DriversName = (Get-WmiObject -Class Win32_Volume).DriveLetter | Where-Object { $_ }
$DriversType = Get-PhysicalDisk | Select-Object -ExpandProperty MediaType
Run Code Online (Sandbox Code Playgroud)

但我不知道第一个数组的哪个元素引用第二个数组的元素。因为系统没有优先考虑它们。

非常感谢您的回答。

powershell

2
推荐指数
1
解决办法
5912
查看次数

标签 统计

powershell ×4

.net ×1

powershell-sdk ×1

runspace ×1

winforms ×1