如何在Powershell中编辑Windows应用商店应用的settings.dat文件
发布时间:2020-12-14 04:03:27  所属栏目:Windows  来源:网络整理 
            导读:我正在自动部署 Windows应用商店应用,我想自动设置用户通常在设置超级按钮中配置的设置之一.我了解到这些设置存储在settings.dat文件中,该文件可以在注册表中打开.但这是一个二进制文件,我不知道如何通过Powershell编辑我想要的设置.这是我能做的事情还是不
                
                
                
            | 
                         
 我正在自动部署 
 Windows应用商店应用,我想自动设置用户通常在设置超级按钮中配置的设置之一.我了解到这些设置存储在settings.dat文件中,该文件可以在注册表中打开.但这是一个二进制文件,我不知道如何通过Powershell编辑我想要的设置.这是我能做的事情还是不值得的努力?谢谢. 
  
  
这就是特定设置看起来像注册表 解决方法
 当AFAIK未加载到注册表中时,无法编辑注册表文件.我玩了一段时间并找到了一种方法,但您需要暂时将注册表文件加载到注册表中并在那里进行编辑.看来你需要使用reg.exe来做到这一点. 
  
  
        另一个问题是在此注册表文件中使用的自定义属性类型(5f5e10c而不是例如REG_BINARY). PowerShell和.NET API似乎都无法加载它们或正确保存它们.我必须导出密钥,在.reg文件中编辑它们并将它们导回. 另一个需要考虑的特性是所有编码值中包含的时间戳,如this blog post中所述. 这是我设法编写的工作脚本,并在注释中添加了其他说明(您需要以管理员身份运行它或加载注册表文件将失败): # full path to the registry file to edit
$settingsFile = "c:UsersDamirAppDataLocalPackages113f4f59-2aa3-455b-8531-185f633c1ffe_ecet6zh215f6eSettingssettings.dat"
# setting name to change
$settingKey = "ServerUrl"
# new setting value
$newValue = "http://prodserver.local/esign/"
# name of temporary .reg file
$regFile = ".settings.reg"
# temporary registry location to import registry file into
$registryImportLocation = "HKLM_TMP"
# prefix matching the setting in the .reg file
$settingKeyPattern = """$settingKey""="
# load the settings file into registry
reg load $registryImportLocation $settingsFile
# export the settings into .reg file
reg export $registryImportLocation $regFile
$fileContents = Get-Content $regFile
$finalContents = @()
$processing = $false
Foreach ($line in $fileContents) 
{ 
    If (-Not ($processing))
    {
        If ($line.StartsWith($settingKeyPattern))
        {
            # setting key found,stop copying file contents
            $processing = $true
            # read key value without its name
            $oldSerializedValue = $line.Replace($settingKeyPattern,"")
        }
        Else
        {
            # setting key not found yet,copy old file contents to output
            $finalContents += $line
        }
    }
    else
    {
        # value can span multiple lines,trim leading spaces from non-first lines
        $oldSerializedValue += $line.TrimStart(" ")
    }
    If ($processing)
    {
        If ($oldSerializedValue.EndsWith(""))
        {
            # trailing  indicates non-final line with key value
            $oldSerializedValue = $oldSerializedValue.TrimEnd("")
        }
        Else
        {
            # split key type and value
            $match = $oldSerializedValue -match '(.*:)(.*)'
            # final 8 bytes are timestamp of the value - don't modify
            $timestamp = $matches[2].Substring($matches[2].Length - 23)
            # encode new value in UTF-16
            $newValueInBytes = [System.Text.Encoding]::Unicode.GetBytes($newValue)
            # key name and type
            $newValue = $settingKeyPattern + $matches[1]
            # encode byte array into required string format
            Foreach ($byte in $newValueInBytes)
            {
                $newValue += [System.Convert]::ToString($byte,16).PadLeft(2,"0") + ","
            }
            # end null character string terminator
            $newValue += "00,00," + $timestamp
            $finalContents += $newValue
            # reenable copying of the remaining file
            $processing = $false
        }
    }
}
# dump new file contents to file
$finalContents | Out-File $regFile
# import the changed value into registry
reg import $regFile
# onload the registry file from registry
reg unload $registryImportLocation
# delete temporary file
Remove-Item $regFile 
 您需要对其进行一些修改以将其包含在部署过程中,但它应该可以帮助您入门. 编辑:我写了一篇accompanying blog post,描述了答案背后的思考过程.它提供了更深入的解释和链接到包含上述脚本的PowerShell function implementation. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
相关内容
- 如何让Windows记得我的密码?
 - 更改Win32 Windows项目中的默认窗口字体
 - .net – 使用适用于Windows XP / 7的Metro UI开发应用程序
 - 如何在Windows上的C中实现计时器
 - windows-server-2012 – ISCSI驱动器未安装在Windows Serve
 - windows-server-2016 – Windows Server 2016中的“数据共享
 - 在Windows 7上使用Powershell创建网络共享文件夹
 - 如何在Windows中设置和使用Jpegtran
 - 如何在Windows Server 2016上运行Linux Docker镜像?
 - winapi – Win8 – Windows.UI.Xaml.dll中的未处理异常
 
推荐文章
            站长推荐
            - 无法将64位Windows 8.1 Pro Client加入Windows 2
 - windows – 如何将不同的SCSI硬盘驱动器放入不同
 - Windows 7上的内联函数的doParallel问题(适用于L
 - VirtualBox 收缩 vdi镜像文件
 - winapi – Win32:写入文件不缓冲?
 - windows – 您能否精确控制SCSM 2012中SCOM CI连
 - windows-7 – 在BSOD上使Windows 7机器崩溃
 - MIT Kerberos for Windows下的多领域和多个TGT
 - .net – Windows窗体的任何地方都有免费的“旋转
 - opengl – FreeGLUT编译的dll lib?
 
热点阅读
            