Hey, i wish to make a program that changes the registry. I want "Shell" in "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Winlogon" to have the value "". when i try to compile this code

#include <iostream>
#include <Windows.h>

using namespace std;

int main(){	
	HKEY hKey;

	RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE/Microsoft/Windows NT/CurrentVersion/Winlogon", 
0, KEY_WRITE, &hKey);

	RegSetValueEx(hKey, "Shell", 0, REG_DWORD, 
	reinterpret_cast<BYTE *>(&""), sizeof(""));

	RegCloseKey(hKey);
	
	return 0;
	}

i get

/out:reg.exe
reg.obj
reg.obj : error LNK2019: unresolved external symbol __imp__RegCloseKey@4 referenced in function _main
reg.obj : error LNK2019: unresolved external symbol __imp__RegSetValueExA@24 referenced in function _main
reg.obj : error LNK2019: unresolved external symbol __imp__RegOpenKeyExA@20 referenced in function _main
reg.exe : fatal error LNK1120: 3 unresolved

Recommended Answers

All 7 Replies

Try adding the following include:

#include<WinReg.h>

Cheers for now,
Jas.

ty for response :D

I tried:
#include <WinReg.h>
but no differance, still get the same error messages.

Also tried:
#import "Advapi32.dll"
Since the documentation from http://msdn.microsoft.com/en-us/library/ms724897(VS.85).aspx said it required that .dll

then i get:
"reg.cpp
C:\Programfiler\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : warning 530: c++ exception handler used, but unwind semantics are not enabled. Specify EHsc.
reg.cpp(4) : fatal error C1083: Cannor open type library file: 'c:\stuff\cpp\test\advapi32.dll'
"

i doubt this got anything with the solution to do but better with to much info than to less.

I think i know whats going on now. If i have understood it right i will need to link it to the .DLL advAPI32.dll, by linking it to the lib file advAPI32. i've tried this with both VC++ and now downloaded dev-c++ to make an attept but can't seem to figure it out.

Have tried to #include <advapi32.lib> but get compile error anyway.

Does it sound like im on the right track?

What compiler are you using? Your program compiled and linked ok for me using VC++ 2010 Express and Code::Blocks w/Mingw.

The last two parameters of lines 12 and 13 are wrong. Should be this:

RegSetValueEx(hKey, "Shell", 0, REG_DWORD,
	NULL, 0);

What compiler are you using? Your program compiled and linked ok for me using VC++ 2010 Express and Code::Blocks w/Mingw.

The last two parameters of lines 12 and 13 are wrong. Should be this:

RegSetValueEx(hKey, "Shell", 0, REG_DWORD,
	NULL, 0);

ty for response, corrected line 12 and 13. I have tried both dev-c++ and the VC++ 2008 command promt, have downloaded VC++ 2010, got the same error messages with that command promt.

Tried to build with VC++ 2010 and now i succeed but the .exe don't do anything and when try debugging i get:

'reg.exe': Loaded 'C:\Documents and Settings\kjekje1\Mine dokumenter\Visual Studio 2010\Projects\reg\Debug\reg.exe', Symbols loaded.
'reg.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file
'reg.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file
'reg.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Cannot find or open the PDB file
'reg.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Cannot find or open the PDB file
'reg.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Cannot find or open the PDB file
'reg.exe': Loaded 'C:\WINDOWS\system32\msvcr100d.dll', Symbols loaded.
The program '[1360] reg.exe: Native' has exited with code 0 (0x0).

Now i also tried to add

#pragma comment( lib, "advapi32.lib" )

and now i succesfully built with VC++ 2010 command line, but the program don't edit my registry.

Are you logged into Windows with Admin account?

In vc++ perform Build --> Clean Solution then Build-->Rebuild Solution. In VC++ 2010 you might have to activate that Build menu by selecting Tools -->Settings --> Expert Settings.

Post the program, or testable code snippet that demonstrates your problem, so that we can test it.

I am acctually not the administrator over this computer but should have rights to edit the registry since i was perfectly able to edit it with a .reg file.

here is my code

#include <iostream>
#include <Windows.h>
#include <WinReg.h>
#pragma comment( lib, "advapi32" )
using namespace std;

int main(){	
    
	HKEY hKey;

	RegOpenKeyEx(HKEY_LOCAL_MACHINE, reinterpret_cast<LPCWSTR>("SOFTWARE/Microsoft/Windows NT/CurrentVersion/winlogon"), 0, KEY_WRITE, &hKey);

	RegSetValueEx(hKey, reinterpret_cast<LPCWSTR>("Shell"), 0, REG_DWORD, NULL, 0);

	RegCloseKey(hKey);
	

	
	return 0;
	}

http://dl.dropbox.com/u/6645860/reg.exe

and there is the executeable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.