2013-07-21 2 views
0

글쎄, 내 응용 프로그램에서 SubKey를 쓰거나 읽으려고하는데 오류가 발생합니다.레지스트리 읽기 및 쓰기 오류가 발생했습니다.

Registry.LocalMachine.OpenSubKey("Software\\SAMP", true).SetValue("PlayerName", textBox1.Text); 
string gamePath = Registry.LocalMachine.OpenSubKey("Software\\SAMP").GetValue("gta_sa_exe").ToString(); 

오류가 첫째 줄에 ". 개체의 인스턴스로 설정되지 않은 개체 참조"

미안하지만 나는 C#에서 꽤 초보자이며 그걸 알아낼 수 없습니다.

+0

64 비트 OS에서 32 비트 EXE 실행되면 [이 응답 표시 (http://stackoverflow.com/q/3655968/2065121) 몇 가지 관련 정보. –

+0

아니, 32 비트 앱이며 올바른 키에 있습니다. – Los799

답변

0

당신은 존재하지 않는 키를 얻으려고합니다. 키를 가져 오기 전에 키를 만들어야합니다. 여기

샘플 코드

Registry.LocalMachine.CreateSubKey("Software\\SAMP"); 
      Registry.LocalMachine.OpenSubKey("Software\\SAMP", true).SetValue("PlayerName", "tremp"); 
      string gamePath = Registry.LocalMachine.OpenSubKey("Software\\SAMP").GetValue("PlayerName").ToString(); 
+0

실제로 해당 키가 이미 있습니다. – Los799

+0

LocalMachine에 확실합니까? 다른 뿌리에 있을까? – Beno

+0

예, 사실 PlayerName 하위 키의 SetValue가 작동하지만 "gta_sa_exe"하위 키 값을 가져 오면 내 앱이 충돌하고 오류가 발생합니다. – Los799