bat批处理文件
REG ADD "HKLM\SOFTWARE\DataDirect\Connect for ADO.NET 3.5" /V LicFileLocation /T REG_SZ /D "D:\Avidm"
C#、ASP.net的代码文件相同,只是新建的工程类型不同,一个是winform,一个是webform。 为什么要建webform的注册工程,因为服务器后台调用DDTEK的时候,需要注册文件的路径,只有用webfrom写出的路径才能被找到。具体原因不知。
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Win32;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string path = System.Configuration.ConfigurationManager.AppSettings["Path"];
RegistryKey docNetItem = null;
RegistryKey ndpItem = null;
//RegistryKey versionItem;
RegistryKey machinelocalItem = Registry.LocalMachine;
RegistryKey softwareItem = machinelocalItem.OpenSubKey("SOFTWARE", true);
if (softwareItem != null) docNetItem = softwareItem.CreateSubKey("DataDirect");
if (docNetItem != null) ndpItem = docNetItem.CreateSubKey("Connect for ADO.NET 3.5");
if (ndpItem != null) ndpItem.SetValue("LicFileLocation", path);
RegistryKey checkKey = machinelocalItem.OpenSubKey(@"SOFTWARE\DataDirect\Connect for ADO.NET 3.5");
if (checkKey != null)
{
Console.WriteLine("Registry OK!");
}
}
}
}
Web.config
<?xml version="1.0"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
<appSettings>
<add key="Path" value="D:\Avidm"/>
</appSettings>
</configuration>