在C#中将reg值写入本地机器

时间:2017-09-20 13:22:34

标签: c# .net

美好的一天,

我正在尝试为一个软件创建一个注册表项,我被要求开发并且已经碰壁了。我已经完成了多次谷歌搜索,但无法进行更改。截至上次尝试时,我的代码如下所示:

<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model app\models\RepeatInvoice */

$this->title = 'Invoice';
$this->params['breadcrumbs'][] = ['label' => 'Repeat Invoices', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="repeat-invoice-view">

    <h1 align="center"><?= Html::encode($this->title) ?></h1>

    <p align="right">
        <?= Html::a('Print', ['update', '#' => $model->id], ['class' => 'btn btn-default']) ?>
        <?= Html::a('Export to PDF', ['#', 'id' => $model->id], ['class' => 'btn btn-default']) ?>
        <?= Html::a('Email Invoice', ['#', 'id' => $model->id], ['class' => 'btn btn-default']) ?>
    </p>

    <!-- invoice -->
    <section class="invoice">
      <!-- title row -->
      <div class="row">
        <div class="col-xs-12">
          <h2 class="page-header">
            <i class="fa fa-globe"></i> <?php echo $model->company->name; ?>
            <small class="pull-right">Date Created: <?php echo date("jS F, Y", strtotime($model->created_at)) ?></small>
          </h2>
        </div>
        <!-- /.col -->
      </div>
      <!-- info row -->
        <div class="well row">
            <div class="col-sm-3">
                <p>
                    Repeat the invoice every
                </p>
                <p><strong>
                    <?php echo $model->repeat_every.' '.$model->repeat_period; ?>
                </strong></p>
            </div>
            <div class="col-sm-3">
                <p>
                    Start Date
                </p>
                <p><strong>
                    <?php echo date("jS F, Y", strtotime($model->start_date)) ?>
                </strong></p>
            </div>
            <div class="col-sm-3">
                <p>
                    Due Date
                </p>
                <p><strong>
                    <?php echo $model->dueDate;  ?>
                </strong></p>
            </div>
            <div class="col-sm-3">
                <p>
                    End Date
                </p>
                <p><strong>
                    <?php echo date("jS F, Y", strtotime($model->end_date)) ?>
                </strong></p>
            </div>
        </div>

        <div class="well row">
            <div class="col-sm-3">
                <p>
                    Tenant
                </p>
                <p><strong>
                    <?php echo $model->lease->tenant->tenantName; ?>
                </strong></p>
            </div>
            <div class="col-sm-6">
                <p>
                    Tenancy
                </p>
                <p><strong>
                    <?php echo $model->lease->leaseDetails; ?>
                </strong></p>
            </div>
            <div class="col-sm-3">
                <p>
                    Payable to:
                </p>
                <p><strong>
                    <?php echo $model->due_after_every.' '.$model->due_after_period; ?>
                </strong></p>
            </div>
        </div>

      <!-- Table row -->
      <div class="row">
        <div class="col-xs-12 table-responsive">
          <table class="table table-striped">
            <thead>
            <tr>
              <th>Item</th>
              <th>Description</th>
              <th>Qty</th>
              <th>Price</th>
              <th>Amount</th>
            </tr>
            </thead>
            <tbody>
                <?php foreach ($repeatInvoiceItems as $indexItem => $repeatInvoiceItem): ?>
                    <tr>
                        <td>
                            <?php echo $repeatInvoiceItem->item->item; ?>
                        </td>
                        <td>
                            <?php echo $repeatInvoiceItem->desc; ?>
                        </td>
                        <td>
                            <?php echo $repeatInvoiceItem->qnty; ?>
                        </td>
                        <td>
                            <?php echo $repeatInvoiceItem->itemPrice; ?>
                        </td>
                        <td>
                            <?php echo $repeatInvoiceItem->qnty * $repeatInvoiceItem->itemPrice; ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
          </table>
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->

      <div class="row">
        <!-- accepted payments column -->
        <div class="col-xs-6">
          <p class="lead">Payment Instructions:</p>

          <p class="text-muted well well-sm no-shadow" style="margin-top: 10px;">
            <?php echo $model->payment_instructions; ?>
          </p>
        </div>
        <!-- /.col -->
        <div class="col-xs-6">

          <div class="table-responsive">
            <table class="table">
              <tr>
                <th style="width:50%">Subtotal:</th>
                <td>$250.30</td>
              </tr>
              <tr>
                <th>Tax (9.3%)</th>
                <td>$10.34</td>
              </tr>
              <tr>
                <th>Total:</th>
                <td>$265.24</td>
              </tr>
            </table>
          </div>
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->

      <!-- this row will not appear when printing -->
      <div class="row no-print">
        <div class="col-xs-12">
          <a href="#" target="_blank" class="btn btn-default"><i class="fa fa-print"></i> Back</a>
          <button type="button" class="btn btn-default pull-right"><i class="fa fa-credit-card"></i> Edit Invoice
          </button>
          <button type="button" class="btn btn-default pull-right" style="margin-right: 5px;">
            <i class="fa fa-download"></i> Add Note
          </button>
        </div>
      </div>
    </section>
    <!-- /.invoice -->
</div>

上面的代码确实没有发生意外。但是,该值永远不会在“运行”子项下的注册表中实现。我也尝试使用简单的“Registry.SetValue(...)”进行更改,如上所示。任何关于这个问题的帮助都将非常感激。如果需要任何其他信息,请告诉我,我将列出下面我能想到的所有重要事项

基本信息:

  1. 程序构建为控制台应用程序
  2. app.manifest设置为“requireAdministrator”
  3. “使用Microsoft.Win32”存在
  4. 目标框架是.Net 4.5
  5. 用于win 7和win 10,结果相同

1 个答案:

答案 0 :(得分:0)

扩展@steve评论。 启用32位和64位应用程序访问  某些部分的注册表以统一的方式,WOW64模拟器提供了一个称为注册表重定向的功能。它主要维护注册表项的单独逻辑视图,该视图映射到Wow6432Node下的物理位置。 并非所有注册表项都受到影响,您可以在此处找到受影响的密钥:

https://msdn.microsoft.com/en-us/library/windows/desktop/aa384253%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396