powershell - 我需要如何更改我的代码以适应 HKEY_USERS 格式而不是 HKCU?
问题描述
We are upgrading our Software to its 2019 version. Apparently it is a
bugger, so it has been suggested to do a clean install including deleting
some registry keys from previous versions.
We also want to save the autologins of our users so they don't need to
reset them up and we can also do something similar with new deployments.
I got some code working for what we want to do, but the problem is that
when I went to add it to our uninstall script, the uninstall script has
some different paths using HKEY_USERS vs my HKCU.
如何修改我的代码以适应使用 HKEY_USERS 的卸载脚本?
除了原始代码之外,还没有尝试过其他任何东西。不知道从哪里开始。这是我第一次尝试使用 powershell(或任何编码)。
#Basically this is supposed to grab the users autologin key, save it,
#then after nuking the reg, put it back
$path = 'HKCU:\Software\SolidWorks\Applications\PDMWorks
Enterprise\ServerConfig\FakeVaultName'
$autologinkey = "HKCU\Software\SolidWorks\Applications\PDMWorks
Enterprise\ServerConfig\FakeVaultName"
$user=(Get-ItemProperty -Path $path -Name User).user.ToLower()
#/y forces overwriting the existing file without prompt.
if($user -ne 'fakeusername' -and $user){
reg export $autologinkey "$env:TEMP\fakekeyname.reg" /y
}
#These next steps need to be done after the uninstall/reg scrubbing
if($user -ne 'fakeusername' -and $user){
reg.exe import "$env:TEMP\fakekeyname.reg"
}
#I think this could maybe get away with just the else part instead of
#elseif + the user?
elseif($user -eq 'fakeusername' -or !$user){
reg.exe import
"\\fakecompanyname.com\Files\Public\IT\Protected\Projects\SOLIDWORKS
2019
deployment\Vault fakeusername auto login keys.reg"
}
#I need to make my code work with the following that loops through
#all the different users on the machine (not the whole code, just the
#HKEY_USERS part that I'm concerned with
# This is where you can read/modify a users portion of the registry
$unwantedDirectories += "registry::HKEY_USERS\
{0}\Software\SolidWorks" -f
$($Item.SID)
$unwantedDirectories += "registry::HKEY_USERS\{0}\Software\SRAC" -f
$($Item.SID)
$unwantedDirectories += "registry::HKEY_USERS\{0}\Software\eDrawings"
-f
$($Item.SID)
$unwantedDirectories += "registry::HKEY_USERS\{0}\Software\SOLIDWORKS
2017" -f $($Item.SID)
我不知道从哪里开始。我的代码有效,但不确定如何将其与其他 HKEY_USERS 部分联系起来。
请指教。
编辑:2019 年 7 月 9 日该脚本有点工作,但它会将 reg 密钥导入登录用户与我们想要的配置文件。以下是当前工作(主要)代码。
###############################################################################
#This part is ran before the reg nuke.
$autologinpath = registry::HKEY_USERS\0}\Software\SolidWorks\Applications\PDMWorks Enterprise\ServerConfig\FakeVaultName' -f $($Item)
$autologinkey = "HKU\{0}\Software\SolidWorks\Applications\PDMWorks Enterprise\ServerConfig\FakeVaultName" -f $($Item)
$autologinuser=(Get-ItemProperty -Path $autologinpath -Name User).user.ToLower()
if($autologinuser -ne 'fakeusername' -and $autologinuser){
reg export $autologinkey "$env:TEMP\fakekeyname.reg" /y
}
###############################################################################
#This part is ran after the reg nuke.
if($user -ne 'fakeusername' -and $autologinuser){
reg.exe import "$env:TEMP\fakekeyname.reg"
}
else {
reg.exe import "\\fakecompanyname.com\Files\Public\IT\Protected\Projects\SOLIDWORKS 2019 deployment\Vault fakeusername auto login keys.reg"
}
编辑:2019 年 7 月 9 日下午 2:09
谢谢您的帮助!我想我们明白了。我们最终手动添加了 reg 键值。可能不是很优雅,但似乎正在工作。
Else {
reg add $autologinkey /v "SettingsFromServer" /t REG_DWORD /f /d #
reg add $autologinkey /v "User" /t REG_SZ /f /d fakeusername
reg add $autologinkey /v "Config" /t REG_BINARY /f /d blahblahblahinfinity..
reg add $autologinkey /v "CacheW" /t REG_DWORD /f /d #
reg add $autologinkey /v "SinglePointLogin" /t REG_DWORD /f /d #
}
解决方案
推荐阅读
- caching - 为什么我的设备(主机)上出现“ERR_EMPTY_RESPONSE”错误,但可以从任何其他(TOR)访问站点
- ios - 为什么我们不能在 makeUIView 中设置第一响应者?
- firebase - 试图从 Firebase 获取数据到谷歌表
- python - 如何通过按下按钮开始处理转换?
- r - 用单个字符替换多个字符
- r - mapbubble 不适用于 highcharter highmaps
- java - 在 springboot 应用程序中动态创建 postgres 模式和表
- node.js - 如何阻止帐户在 nodemailer 应用程序中发送垃圾邮件?
- excel - 执行 PowerQuery 时记录的宏:VBA 代码的意外结果
- android - Socket.io 在 Android 10.0 设备上不起作用