注册表值被视为错误的方式 [英] registry values taken as wrong way in

查看:88
本文介绍了注册表值被视为错误的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注册表值在我的c#代码中被视为错误的方式它是早期写入的值,我的新连接字符串值即使删除并重新创建注册表项也不会生效。



单独的winUI(windows应用程序)用于输入数据库名称,密码和用户名,它在保存时调用此应用程序属性类,并且此类调用连接字符串。









这里是代码

/ *

*加密

* /

使用System;

使用Microsoft.Win32;

使用eSenze.SystemFramework.Common .Encryption;



命名空间eSenze.SystemFramework.Common.ApplicationProperties

{

///< summary> ;

///提供申请的属性。

///

公共密封类ApplicationProperty

{



私有静态字符串m_connectionString;


私有静态字符串m_gwGlobleConnectionString;

私有静态字符串m_gwDataConnectionString;

私有静态字符串m_gwDateFormat;

private static bool m_itergrationON;



私有静态字符串m_mailServer;

私有静态字符串m_dateFormat;

private static string m_fileName;

private static string m_ge​​neralMailFooter;

private static readonly string m_Key =eSenze;



// public ApplicationProperty()

// {



//}

静态ApplicationProperty( )

{

// RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(SOFTWARE \\ eSenze \\ eHRMODEL);

//registryKey.SetValue(\"ConnectionString\",\"wiGguALNyJO12uaRRquvbrYGSDorzltCHZakF0o6nVcE2KNvxXPTsta0qxcdT4i94KE/2dQuVUWgsNCeSSJ7v0SoZHbcHFT2EakDacAcA2xR0kjxm7IY/r LSFJHPu6TMs /米/ SO + J0cad0VPUfUAmh2WVvvrNjaoxca + PJi3HegWyVDEEGMLgkhQo6xzeOubSO5BoYtzn / oYB6isPy + 0PV9tzvmAFQNUrp8bHNDy4rY5URhdT7nbE2KlsZqnR4jzJ );

的RegistryKey的RegistryKey = Registry.LocalMachine.OpenSubKey( SOFTWARE\\eSenze\\eHRM_AitkenSpence);

if(registryKey == null)

{

ApplicationProperty.SetRegistryValue();

}

else

{

object connectionString = registryKey.GetValue(ConnectionString);

object mailServer = registryKey.GetValue(MailServer);

object dateFormat = registryKey.GetValue(DateFormat);



object fileName = registryKey.GetValue(ServiceFileName);

object generalMailFooter = registryKey.GetValue(GeneralMailFooter);



object gwGlobleConnectionString = registryKey.GetValue(GWGlobleConnectionString);

object gwDataConnectionString = registryKey.GetValue(GWDataConnectionString);



object gwDateFormat = registryKey.GetValue(GWDateFormat);

object itergrationON = registryKey.GetValue(ItergrationON);

if(connectionString == null)

{

ApplicationProperty.SetRegistryValue();

}

else

{

尝试

{

CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new Cryptogr aphyDotNetTripleDESEncryption();

m_connectionString = cryptographyDotNetTripleDESEncryption.Decrypt(connectionString.ToString(),m_Key);



CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption() ;

m_gwGlobleConnectionString = cryptographyDotNetRijndaelEncryption.Decrypt(gwGlobleConnectionString.ToString(),m_Key);

m_gwDataConnectionString = cryptographyDotNetRijndaelEncryption.Decrypt(gwDataConnectionString.ToString(),m_Key);

}

catch

{

m_connectionString = string.Empty;

}



if(mailServer == null)

{

m_mailServer = string.Empty;

}

else

{

m_mailServer = mailServer.ToString();

}

if(dateFormat == null)

{

m_dateFormat =MM / dd / yyyy;

}

其他

{

m_dateFormat = dateFormat.ToString();

}



if(fileName == null)

{

m_fileName =C:\\Inetpub \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ b $ b}

其他

{

m_fileName = fileName.ToString();

}

if(generalMailFooter == null)

{

m_ge​​neralMailFooter =

管理员
e-HRM系统
注意:这是e-HRM系统生成的电子邮件。
登录系统点击此处;

}

else

{

m_ge​​neralMailFooter = generalMailFooter.ToString();

}



if(gwDateFormat == null)

{

m_gwDateFormat =dd / MM / yyyy;

}

其他

{

m_gwDateFormat = gwDateFormat.ToString();

}

if(itergrationON == null)

{

m_itergrationON = false;

}

else

{

m_itergrationON = Convert.ToBoolean(itergrationON); < br $>
}

}

}

}

private static void SetRegistryValue()

{

m_connectionString =data source = local; persist security info = True; initial catalog = SLBC; UID = sa; PWD = 1234 @ com;

CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new CryptographyDotNetTripleDESEncryption();

string encryptString = cryptographyDotNetTripleDESEncryption.Encrypt(m_connectionString,m_Key);

RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(SOFTWARE \\ eSenze \\\\ HMR_AitkenSpence);

registryKey.SetValue(ConnectionString,encryptString);

registryKey.SetValue(DateFormat,MM / dd / yyyy);





}



public void SaveConnectionString(string serverMachineName,string database,string userName,string password)

{

m_connectionString =data source = + serverMachineName +; persist security info = True; initial catalog =+ database +; UID =+ userName +; PWD =+密码;

CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new CryptographyDotNetTripleDESEncryption();

string encryptString = cryptographyDotNetTripleDESEncryption.Encrypt(m_connectionString,m_Key);

this.SetRegistryValue(ConnectionString,encryptString);



}

public void SaveMailServer(string mailServer)

{

this.SetRegistryValue(MailServer,mailServer);

}

public void SaveDateFormat(string dateFormat)

{

this.SetRegistryValue(DateFormat,dateFormat);

}

private void SetRegistryValue(string key,string registryValue)

{

RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(SOFTWARE \\ eSenze \\\ HRR_AitkenSpence);

registryKey .SetValue(key,registryValue);

}



p ublic void SaveServiceFileName(string fileName)

{

this.SetRegistryValue(ServiceFileName,fileName);

}

public void SaveGeneralMailFooter(string generalMailFooter)

{

this.SetRegistryValue(GeneralMailFooter,generalMailFooter);

}



public void SaveGWGlobleConnectionString(string fileName)

{

m_gwGlobleConnectionString =Provider = VFPOLEDB.1; Data Source =+ fileName +; Mode = Share Deny None; Extended Properties = \\; User ID = \\; Mask Password = False; Cache Authentication = False; Encrypt Password = False; Collat​​ing Sequence = MACHINE ; //data source =+ serverMachineName +; persist security info = True; initial catalog =+ database +; UID =+ userName +; PWD =+密码;

CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption();

string encryptString = cryptographyDotNetRijndaelEncryption.Encrypt(m_gwGlobleConnectionString,m_Key);

this.SetRegistryValue(GWGlobleConnectionString,encryptString);



}

public void SaveGWDataConnectionString(string fileName)

{

m_gwDataConnectionString =Provider = VFPOLEDB.1; Data Source =+ fileName +; Mode = Share Deny None;扩展属性= \\;用户ID = \ \; Mask Password = False; Cache Authentication = False; Encrypt Password = False; Collat​​ing Sequence = MACHINE; //data source =+ serverMachineName +; persist security info = True; initial catalog =+ + database + ; UID =+ userName +; PWD =+密码;

CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption();

string encryptString = cryptographyDotNetRijndaelEncryption.Encrypt(m_gwDataConnectionString,m_Key);

this.SetRegistryValue(GWDataConnectionString,encryptString);



}

public void SaveGWDateFormat(string dateFormat)

{

this.SetRegistryValue(GWDateFormat,dateFormat);

}

public void SaveIntergrationSwitch(string itergationMode)

{

this.SetRegistryValue(ItergrationON,itergationMode);

}

公共静态字符串ConnectionString

{

get

{

返回m_connectionString;

}

}

公共静态字符串MailServer

{

get

{

返回m_mailServer ;

}

}

公共静态字符串DateFormat

{

get

{

返回m_dateFormat;

}

}



public static string ServiceFileName

{

get

{

return m_fileName;

}

}

公共静态字符串GeneralMailFooter

{

get

{

返回m_generalMailFooter;

}

}

公共静态字符串ReportHeader

{

get

{

返回MCB;

}

}



公共静态字符串HRMName

{

get

{

返回HR Manager;

}

}



公共静态字符串HRMDesignation

{

get

{

返回经理 - 人力资源;

}

}



公共静态字符串GWGlobleConnectionString

{

get

{

返回m_gwGlobleConnectionString; //提供者= VFPOLEDB.1;数据源= D:\\GW \\GLOBAL \\dbGlobal.dbc;模式=共享拒绝无;扩展属性= \\;用户ID = \\; Mask Password = False; Cache Authentication = False; Encrypt Password = False; Collat​​ing Sequence = MACHINE;

}

}

公共静态字符串GWDataConnectionString

{

get

{

返回m_gwDataConnectionString;

}

}

公共静态字符串GWDateFormat

{

get

{

返回m_gwDateFormat;

}

}

public static bool GWItergrationOn

{

get

{

return m_itergrationON;

}

}

}

}



registry values taken as wrong way in my c# code it is something early wrote values, my new connection string values not take into affect even though delete and recreate the registry key.

seperate winUI(windows application) was used to enter database name,pasword and username, it calls this application property class when saving and also this class called for connection string.




here is the code
/*
* Encryption
*/
using System;
using Microsoft.Win32;
using eSenze.SystemFramework.Common.Encryption;

namespace eSenze.SystemFramework.Common.ApplicationProperties
{
/// <summary>
/// Provide the properties for the appliction.
///
public sealed class ApplicationProperty
{

private static string m_connectionString;

private static string m_gwGlobleConnectionString;
private static string m_gwDataConnectionString;
private static string m_gwDateFormat;
private static bool m_itergrationON;

private static string m_mailServer;
private static string m_dateFormat;
private static string m_fileName;
private static string m_generalMailFooter;
private static readonly string m_Key = "eSenze";

//public ApplicationProperty()
//{

//}
static ApplicationProperty()
{
//RegistryKey registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\eSenze\\eHRMODEL");
//registryKey.SetValue("ConnectionString","wiGguALNyJO12uaRRquvbrYGSDorzltCHZakF0o6nVcE2KNvxXPTsta0qxcdT4i94KE/2dQuVUWgsNCeSSJ7v0SoZHbcHFT2EakDacAcA2xR0kjxm7IY/rLSFJHPu6TMs/m/SO+J0cad0VPUfUAmh2WVvvrNjaoxca+PJi3HegWyVDEEGMLgkhQo6xzeOubSO5BoYtzn/oYB6isPy+0PV9tzvmAFQNUrp8bHNDy4rY5URhdT7nbE2KlsZqnR4jzJ");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\eSenze\\eHRM_AitkenSpence");
if(registryKey == null)
{
ApplicationProperty.SetRegistryValue();
}
else
{
object connectionString = registryKey.GetValue("ConnectionString");
object mailServer = registryKey.GetValue("MailServer");
object dateFormat = registryKey.GetValue("DateFormat");

object fileName = registryKey.GetValue("ServiceFileName");
object generalMailFooter = registryKey.GetValue("GeneralMailFooter");

object gwGlobleConnectionString = registryKey.GetValue("GWGlobleConnectionString");
object gwDataConnectionString = registryKey.GetValue("GWDataConnectionString");

object gwDateFormat = registryKey.GetValue("GWDateFormat");
object itergrationON = registryKey.GetValue("ItergrationON");
if(connectionString == null)
{
ApplicationProperty.SetRegistryValue();
}
else
{
try
{
CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new CryptographyDotNetTripleDESEncryption();
m_connectionString = cryptographyDotNetTripleDESEncryption.Decrypt(connectionString.ToString(),m_Key);

CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption();
m_gwGlobleConnectionString = cryptographyDotNetRijndaelEncryption.Decrypt(gwGlobleConnectionString.ToString(),m_Key);
m_gwDataConnectionString = cryptographyDotNetRijndaelEncryption.Decrypt(gwDataConnectionString.ToString(),m_Key);
}
catch
{
m_connectionString = string.Empty;
}

if(mailServer == null)
{
m_mailServer = string.Empty;
}
else
{
m_mailServer = mailServer.ToString();
}
if(dateFormat == null)
{
m_dateFormat = "MM/dd/yyyy";
}
else
{
m_dateFormat = dateFormat.ToString();
}

if(fileName == null)
{
m_fileName = "C:\\Inetpub\\wwwroot\\eHRMPCHWeb\\bin\\eHRMServiceProcess.exe";
}
else
{
m_fileName = fileName.ToString();
}
if(generalMailFooter == null)
{
m_generalMailFooter = "

Administrator
e-HRM System
Note: This is an e-HRM System generated email.
To Login the system Click here ";
}
else
{
m_generalMailFooter = generalMailFooter.ToString();
}

if(gwDateFormat == null)
{
m_gwDateFormat = "dd/MM/yyyy";
}
else
{
m_gwDateFormat = gwDateFormat.ToString();
}
if(itergrationON == null)
{
m_itergrationON = false;
}
else
{
m_itergrationON = Convert.ToBoolean(itergrationON);
}
}
}
}
private static void SetRegistryValue()
{
m_connectionString = "data source=local;persist security info=True;initial catalog=SLBC; UID = sa; PWD = 1234@com";
CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new CryptographyDotNetTripleDESEncryption();
string encryptString = cryptographyDotNetTripleDESEncryption.Encrypt(m_connectionString,m_Key);
RegistryKey registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\eSenze\\eHRM_AitkenSpence");
registryKey.SetValue("ConnectionString",encryptString);
registryKey.SetValue("DateFormat","MM/dd/yyyy");


}

public void SaveConnectionString(string serverMachineName,string database, string userName, string password)
{
m_connectionString = "data source=" + serverMachineName + ";persist security info=True;initial catalog=" + database + "; UID = " + userName + "; PWD = " + password;
CryptographyDotNetTripleDESEncryption cryptographyDotNetTripleDESEncryption = new CryptographyDotNetTripleDESEncryption();
string encryptString = cryptographyDotNetTripleDESEncryption.Encrypt(m_connectionString,m_Key);
this.SetRegistryValue("ConnectionString",encryptString);

}
public void SaveMailServer(string mailServer)
{
this.SetRegistryValue("MailServer",mailServer);
}
public void SaveDateFormat(string dateFormat)
{
this.SetRegistryValue("DateFormat",dateFormat);
}
private void SetRegistryValue(string key, string registryValue)
{
RegistryKey registryKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\eSenze\\eHRM_AitkenSpence");
registryKey.SetValue(key,registryValue);
}

public void SaveServiceFileName(string fileName)
{
this.SetRegistryValue("ServiceFileName",fileName);
}
public void SaveGeneralMailFooter(string generalMailFooter)
{
this.SetRegistryValue("GeneralMailFooter",generalMailFooter);
}

public void SaveGWGlobleConnectionString(string fileName)
{
m_gwGlobleConnectionString = "Provider=VFPOLEDB.1;Data Source=" + fileName + ";Mode=Share Deny None;Extended Properties=\"\";User ID=\"\";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=MACHINE";//"data source=" + serverMachineName + ";persist security info=True;initial catalog=" + database + "; UID = " + userName + "; PWD = " + password;
CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption();
string encryptString = cryptographyDotNetRijndaelEncryption.Encrypt(m_gwGlobleConnectionString,m_Key);
this.SetRegistryValue("GWGlobleConnectionString",encryptString);

}
public void SaveGWDataConnectionString(string fileName)
{
m_gwDataConnectionString = "Provider=VFPOLEDB.1;Data Source=" + fileName + ";Mode=Share Deny None;Extended Properties=\"\";User ID=\"\";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=MACHINE";//"data source=" + serverMachineName + ";persist security info=True;initial catalog=" + database + "; UID = " + userName + "; PWD = " + password;
CryptographyDotNetRijndaelEncryption cryptographyDotNetRijndaelEncryption = new CryptographyDotNetRijndaelEncryption();
string encryptString = cryptographyDotNetRijndaelEncryption.Encrypt(m_gwDataConnectionString,m_Key);
this.SetRegistryValue("GWDataConnectionString",encryptString);

}
public void SaveGWDateFormat(string dateFormat)
{
this.SetRegistryValue("GWDateFormat",dateFormat);
}
public void SaveIntergrationSwitch(string itergationMode)
{
this.SetRegistryValue("ItergrationON",itergationMode);
}
public static string ConnectionString
{
get
{
return m_connectionString;
}
}
public static string MailServer
{
get
{
return m_mailServer;
}
}
public static string DateFormat
{
get
{
return m_dateFormat;
}
}

public static string ServiceFileName
{
get
{
return m_fileName;
}
}
public static string GeneralMailFooter
{
get
{
return m_generalMailFooter;
}
}
public static string ReportHeader
{
get
{
return "MCB";
}
}

public static string HRMName
{
get
{
return "HR Manager";
}
}

public static string HRMDesignation
{
get
{
return "Manager - Human Resources";
}
}

public static string GWGlobleConnectionString
{
get
{
return m_gwGlobleConnectionString; //"Provider=VFPOLEDB.1;Data Source=D:\\GW\\GLOBAL\\dbGlobal.dbc;Mode=Share Deny None;Extended Properties=\"\";User ID=\"\";Mask Password=False;Cache Authentication=False;Encrypt Password=False;Collating Sequence=MACHINE";
}
}
public static string GWDataConnectionString
{
get
{
return m_gwDataConnectionString;
}
}
public static string GWDateFormat
{
get
{
return m_gwDateFormat;
}
}
public static bool GWItergrationOn
{
get
{
return m_itergrationON;
}
}
}
}




推荐答案

此代码项目文章中解释了所有与注册表相关的操作/>
请参考它。

如果您仍有问题,请在问题中包含您的代码。

代码项目文章
All the registry related operations are explained in this codeproject article.
Please refer to it.
If you still have problem, please do include your code in the question.
Code Project Article


删除所有已发布的内容IIS的应用程序版本。在注册表中找到所有注册表引用(使用计算机的ctrl + f)并删除所有注册表引用。重写到注册表,构建应用程序并发布。现在它工作正常
deleted all the published version of the application frm IIS. found all the registry refernces in the registry(using ctrl+f of the computer)and deleted all of them. rewrote to the registry,built the application and published.now it works fine


这篇关于注册表值被视为错误的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆