Powershell的注册表HKEY用户

时间:2018-09-24 07:15:11

标签: powershell

您好,我正在尝试从注册表中读取本地用户帐户,然后将其传递给变量。 我想这样做是因为那里安装了某些软件而不是HKLM。所以我正在使用以下代码。

$root= "HKLM:\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Deployment\Package\*\*"
$user=Get-ChildItem $root | where {$_.Name -like "*S-1-5*"} |select Name
Write-Host $user

然后

$soft=Get-ItemProperty"REGISTRY::HKEY_USERS\$user\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"| where {$_.DisplayName -like "*$program*"} | Select DisplayName, DisplayVersion 
}    
if ($soft)
{
Write-Host "npp query = "$soft""
Write-Host -ForegroundColor green "$program already installed!" 
$array +=  $soft[0]
}

唯一的问题是,我正在尝试获取定义本地用户帐户的S-1 ....数字,而不是获取完整路径。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

所需路径的一部分存储在另一个属性 import subprocess def pytest_sessionfinish(session, exitstatus): """ Run command to set allure path and generate allure report after the test run is over """ # Running pytest can result in six different exit codes: # Exit code 0: All tests were collected and passed successfully # Exit code 1: Tests were collected and run but some of the tests failed # Exit code 2: Test execution was interrupted by the user # Exit code 3: Internal error happened while executing tests # Exit code 4: pytest command line usage error # Exit code 5: No tests were collected print '\nrun status code:', exitstatus if (exitstatus != 2 or exitstatus != 3 or exitstatus!= 4 or exitstatus != 5): command_to_export_allure_path= ['export PATH=$PATH:/usr/local/bin:/usr/local/bin/allure-commandline/allure-2.7.0/bin/'] command_generate_allure_report= ['allure generate --clean -o %s/Allure/ %s'%(allure_report_dir, allure_report_dir)] print command_to_export_allure_path print command_generate_allure_report subprocess.call(command_to_export_allure_path, shell=True) subprocess.call(command_generate_allure_report, shell=True) 中。您可以像这样检索它:

PSChildName

作为旁注,您可以像这样将SID解析为用户名:

$root = "HKLM:\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Deployment\Package\"

$user = (Get-ChildItem $root -Recurse -Include "*S-1-5*").PsChildName