查询reg键值的数据,并使用“goto”和“if”来基于所述值的输出

时间:2016-12-16 01:19:54

标签: powershell batch-file registry

您好我正在尝试创建一个查询注册表项的批处理文件,并根据其值启动特定程序。

我尝试过互联网的各种组合,但我似乎无法获得正确的行为。

基本上,脚本将检查定义当前DPI的regkey。根据该值,将运行两个程序中的一个(PowerShell脚本),然后运行具有特定大小限制的InternetExplorer.Application窗口。

来源:

到目前为止我得到的是:

@echo off
setlocal
set "Key=HKCU\Control Panel\Desktop\WindowMetrics"
set Type=REG_DWORD
set Value=AppliedDPI

set Data=
for /f "tokens=2,3" %%a in ('reg query %Key% /v %Value% 2^>NUL ^| find /i "%Value%"') do (
 set TestType=%%a
 set Data=%%b
)
if /i "%Data%"=="0x60" goto Data_96
if /i "%Data%"=="0xc0" goto Data_192
if /i not "%TestType%"=="%Type%" goto :Data_Missing
goto Data_Undefined

:Data_96
echo Data is "%Data%".
goto 96

:Data_192
echo Data is "%Data%".
goto 192

:Data_Missing
echo Key or value not found.
goto leave

:Data_Undefined
echo No action for data "%Data%" defined.
goto leave

:96
powershell.exe -ExecutionPolicy Unrestricted -File somescript1.ps1
goto leave

:192
powershell.exe -ExecutionPolicy Unrestricted -File somescript2.ps1
goto leave

:leave

但它不起作用。继续获得“未找到关键或价值”。 我试过的其他样本最终加载了两个脚本。 我显然设置了一些错误,但不确定它是什么。

2 个答案:

答案 0 :(得分:0)

在这里,为了您的信息,脚本应该做同样的事情:

 String[] from = new String[]{DBHelper.ID, DBHelper.FNAME, DBHelper.LNAME, DBHelper.ADDRESS, DBHelper.REGID};
int[] to = new int[]{R.id.id,R.id.fname,R.id.lname,R.id.address,R.id.regid};
  adapter = new SimpleCursorAdapter(this, R.layout.list, cursor, from, to, 0);
  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        //listview click event handling
            id = (TextView) arg1.findViewById(R.id.id);
            int id_To_Search = Integer.valueOf(id.getText().toString());

            Bundle dataBundle = new Bundle();
            dataBundle.putInt("_id", id_To_Search);

            Intent intent = new Intent(getApplicationContext(), AddPatient.class);

            intent.putExtras(dataBundle);
            startActivity(intent);
        }
    });

它使用了操作符不关心值是十六进制还是十六进制的事实。

答案 1 :(得分:0)

使用@Squashman的解决方案,并且在我的&#34;设置&#34;之前也意识到我自己的错误。命令,脚本现在按预期工作。