使用编码更改Windows设置



我想要一个代码,它将检查当前使用十进制符号的当前Windows设置,"逗号";或";点";。如果是";逗号";,代码应将其更改为"0";点";如果是";点"-至";逗号";。

我想把这段代码作为桌面上的快捷方式,只需双击即可运行。有人能帮我吗?据我所知,这应该很容易,但我还没有这些任务的经验。谢谢

你可以用几种方法做到这一点,但我猜你正在寻找一种创造性的简单方法。

Powershell

使用Powershell,您可以通过以下方式获得十进制表示法的当前值:

(Get-ItemProperty -Path "HKCU:Control PanelInternational" -Name sDecimal).sDecimal

由于您要将其更改为其他内容,因此还需要处理数千分组符号。按照上面的逻辑,你会做

(Get-ItemProperty -Path "HKCU:Control PanelInternational" -Name sThousand).sThousand

这两个都获取当前用户的设置,更改它们将是该用户的更改。如果你对此感到满意,你可以做以下事情。

首先,打开任何文本编辑器(记事本也可以),然后粘贴以下代码。

$currentDecimal = (Get-ItemProperty -Path "HKCU:Control PanelInternational" -Name sDecimal).sDecimal # let's get the current decimal separator
# if the current decimal is equal to a dot
if($currentDecimal -eq ".") {
Set-ItemProperty -Path "HKCU:Control PanelInternational" -Name sDecimal -Value ","
Set-ItemProperty -Path "HKCU:Control PanelInternational" -Name sThousand -Value "." # this line will always change the thousands grouping symbol. If you don't want that, omit this line
$wasDecimalChanged = $true
} elseif($currentDecimal -eq ",") {
Set-ItemProperty -Path "HKCU:Control PanelInternational" -Name sDecimal -Value "."
Set-ItemProperty -Path "HKCU:Control PanelInternational" -Name sThousand -Value "," # same as in the first if, omit this, if you don't want to change the thousands grouping symbol
$wasDecimalChanged = $true
} else {
$wasDecimalChanged = $false
}
if($wasDecimalChanged) {
write-host("Decimal symbol was changed to " + (Get-ItemProperty -Path "HKCU:Control PanelInternational" -Name sDecimal).sDecimal)
}
exit

然后将其保存为*.ps1文件。

此脚本可能需要以提升的(管理员)权限运行。此外,运行此脚本的系统可能需要启用运行Powershell脚本。你可以通过以下几种方式做到这一点:

  • 通过更改特定系统上的注册表,如下所示。这也将使您可以通过双击来运行脚本
  • 通过手动启用Powershell脚本的运行,以管理员身份启动Powershell,并运行以下命令:set-executionpolicy remotesigned。完成此操作后,您可以将脚本放置在系统中任何位置的目录中。然后,您可以创建一个快捷方式,并将其放置在桌面/任何其他位置,然后双击,运行脚本

请记住,这两种情况都会使系统受到恶意脚本的攻击和运行。


批处理脚本

如果你想通过一个批处理脚本来完成,它看起来像这样。

首先,让我们看看如何检索十进制分隔符的当前值。

reg query "HKEY_CURRENT_USERControl PanelInternational" /v sDecimal

本部分

reg query "HKEY_CURRENT_USERControl PanelInternational"

让我们知道该特定注册表项中的所有键,这没关系,但我们只需要十进制分隔符。通过添加此

/v sDecimal

我们的命令变成

reg query "HKEY_CURRENT_USERControl PanelInternational" /v sDecimal

我们得到了我们想要的。嗯,有点像,因为对我们命令的反应是:

HKEY_CURRENT_USERControl PanelInternational
sDecimal    REG_SZ    .

我们从这个响应中唯一需要的是最后一个字符——点(在这种情况下,它可能是逗号)。因此,要提取分隔符,我们需要这样做(从脚本中——在命令提示符下运行需要一些更改)。

for /F "tokens=3" %%A in ('reg query "HKEY_CURRENT_USERControl PanelInternational" /v sDecimal') DO (Echo %%A)

这将只返回十进制分隔符。

其余的逻辑或多或少与Powershell示例中的相同,唯一不同的是语法。综合起来,我们得到

@echo off
title "Decimal change"
REM let's get our current decimal symbol, and give its value to a variable
for /F "tokens=3" %%A in ('reg query "HKEY_CURRENT_USERControl PanelInternational" /v sDecimal') DO (SET currentDecimal=%%A)
IF /i "%currentDecimal%"=="," goto changeComma
IF /i "%currentDecimal%"=="." goto changeDecimal
echo Symbol is not a decimal point or a dot! I've changed nothing!
goto commonexit
:changeComma
%SystemRoot%System32reg.exe add "HKEY_CURRENT_USERControl PanelInternational" /v sDecimal /t REG_SZ /d "." /f
%SystemRoot%System32reg.exe add "HKEY_CURRENT_USERControl PanelInternational" /v sThousand /t REG_SZ /d "," /f
goto commonexit
:changeDecimal
%SystemRoot%System32reg.exe add "HKEY_CURRENT_USERControl PanelInternational" /v sDecimal /t REG_SZ /d "," /f
%SystemRoot%System32reg.exe add "HKEY_CURRENT_USERControl PanelInternational" /v sThousand /t REG_SZ /d "." /f
goto commonexit
:commonexit
exit

使用REG_SZ位是因为这是值存储在注册表中的方式——如果您要在Windows机器上打开注册表编辑器,然后导航到

ComputerHKEY_CURRENT_USERControl PanelInternational

您将看到各种设置的列表,并且所有设置都属于REG_SZ类型。

与Powershell脚本一样,您可以将其编译到记事本文件中。与Powershell脚本不同,您将使用*.bat扩展名保存此脚本。

关于提升/管理权限以及在桌面上放置快捷方式的说明也适用。

最新更新