Use c++ to change users browser homepage

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 13768 Views - Last Post: 31 October 2010 - 09:36 AM Rate Topic: -----

#16 sharpie349   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 28-October 10

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 08:38 PM

Thank you for your comments.
no2pencil I think I changed my code using your tip but I am still gettting those errors..am I doing it correctly?
#include <windows.h>
#include <iostream>
using namespace std;
int main(){
char registry_location[]= "Software\\Microsoft\\Internet Explorer\\Main";
HKEY key;
RegOpenKeyEx(HKEY_CURRENT_USER,registry_location,0,KEY_ALL_ACCESS,&key);

RegSetValueEx(key, TEXT("Start Page"), 0, REG_SZ, (LPBYTE)"http://msn.com/", strlen("http://msn.com/")*sizeof(char));

RegCloseKey(key);
}



Was This Post Helpful? 0
  • +
  • -

#17 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 08:42 PM

This code works perfectly fine on Windows XP.
Was This Post Helpful? 0
  • +
  • -

#18 sharpie349   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 28-October 10

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 08:48 PM

The code that I just posted?
Was This Post Helpful? 0
  • +
  • -

#19 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 08:51 PM

Yes.

I opened ie, set my home page to google, closed, reopened, verified google was the home page, ran your program, closed ie, opened ie, verified msn.com was the home page, & even repeated the process.
Was This Post Helpful? 0
  • +
  • -

#20 sharpie349   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 28-October 10

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 08:54 PM

ughhh damnn I feel so close!!
I have windows 7 and whenever I build it i just get that const char error not being able to initialize LPCTSTR.
I'm stumped.
Was This Post Helpful? 0
  • +
  • -

#21 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 08:57 PM

Must be an issue with the OS then, because this is as close to showing you that it works as I can get...

Quote

C:\code\c>dir regi*
Volume in drive C has no label.
Volume Serial Number is 94C5-581D

Directory of C:\code\c

10/30/2010 11:40 PM 407 registry_test.cpp
10/30/2010 11:41 PM 47,616 registry_test.exe
10/30/2010 11:41 PM 7,047 registry_test.obj
10/30/2010 11:41 PM 393,216 registry_test.tds
4 File(s) 448,286 bytes
0 Dir(s) 2,403,205,120 bytes free

C:\code\c>registry_test.exe

C:\code\c>registry_test.exe


I'm using the borland C++ 5.5 command line compiler.
Was This Post Helpful? 1
  • +
  • -

#22 sharpie349   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 28-October 10

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 08:59 PM

Yeah it does seem to work.
I have visual basic 2010.
I may know the problem though.
When creating the project and such what type of template did you use and also did you use a cpp file?
Was This Post Helpful? 0
  • +
  • -

#23 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 09:01 PM

View Postsharpie349, on 30 October 2010 - 09:59 PM, said:

When creating the project and such what type of template did you use and also did you use a cpp file?

The borland compiler is just a compiler, there are no templates. I just posted the code into a text editor (I use the Crimson Editor), saved it, & compiled it. & yes, it was as a cpp file. Your using the windows header is C++ style... & there for cannot compile as a c file.
Was This Post Helpful? 0
  • +
  • -

#24 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 09:02 PM

View Postsharpie349, on 31 October 2010 - 12:54 PM, said:

ughhh damnn I feel so close!!
I have windows 7 and whenever I build it i just get that const char error not being able to initialize LPCTSTR.
I'm stumped.


As stated above I am guessing here so take it all with a grain of salt.

The way you are declaring the string is making it a const.
Whenever you supply the string as part of the declaration you make the C-string a const.
Try breaking the declaration of the character array (make it length 43 or greater) and setting its value to the string onto different lines.
Ensure you have a null terminator in place.

Then at least you have got past the 'const' part of the warning.

Worth a try, maybe?
Was This Post Helpful? 0
  • +
  • -

#25 sharpie349   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 28-October 10

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 09:04 PM

Ahhh i see. But do you think me starting with a empty win32 project console application and adding a cpp file to add the code has to do with anything?
Was This Post Helpful? 0
  • +
  • -

#26 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 09:08 PM

Anything is possible.

IDEs do do strange things sometimes.
They want to be helpful but they just get in the way sometimes.

Starting up a fresh project and copy-and-paste all your code into its main() might be worth a try to eliminate one possible suspect.
Was This Post Helpful? 0
  • +
  • -

#27 sharpie349   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 28-October 10

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 09:11 PM

I will try but in the meantime I looked into what you said previously about the string thing.
I dont know exactly where I should be changing my code would you be able to copy the part of my code that should be changed?

I will try but in the meantime I looked into what you said previously about the string thing.
I dont know exactly where I should be changing my code would you be able to copy the part of my code that should be changed?
Was This Post Helpful? 0
  • +
  • -

#28 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 09:27 PM

I had forgotten you are doing this in C++ so no need for the character array at all.

Something like this should work in C++, I think.
#include <iostream>
#include <string>

int main(){
	std::string registry_location;
	registry_location  = "Software\\Microsoft\\Internet Explorer\\Main";
	
	std::cout << registry_location << std::endl;

	return 0;
}


Was This Post Helpful? 1
  • +
  • -

#29 sharpie349   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 28-October 10

Re: Use c++ to change users browser homepage

Posted 30 October 2010 - 09:32 PM

I made a second code and made some changes and this one builds fine but when I run it I go to the registry value and instead of it saying msn.com it has a bunch of like chinese characters its weird.

#include <windows.h>
#include <iostream>

int main()
{
HKEY key;
RegOpenKeyEx(HKEY_CURRENT_USER,TEXT("Software\\Microsoft\\Internet Explorer\\Main"),0,KEY_ALL_ACCESS,&key);
RegSetValueEx(key, TEXT("Start Page"), 0, REG_SZ, (LPBYTE)"http://google.com/", strlen("http://google.com/")*sizeof(char));
RegCloseKey(key);
	
	return 0;
}

Characters are like this. 睷⹷獭⹮潣⽭
Was This Post Helpful? 0
  • +
  • -

#30 oscode   User is offline

  • D.I.C Regular

Reputation: 109
  • View blog
  • Posts: 257
  • Joined: 24-October 10

Re: Use c++ to change users browser homepage

Posted 31 October 2010 - 02:50 AM

By the way sharpie, sizeof(char) is always 1. You should be checking the return values to see what the problems are.

This post has been edited by oscode: 31 October 2010 - 02:52 AM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3