Link to home
Start Free TrialLog in
Avatar of John-Paul75
John-Paul75

asked on

C++ Windos Registry: What is the safest way to make startup entry in C++

Please Help ........

I'm using simple Registry methos off winreg for the startup entry off my application but Kaspersky and Norton antivirus says it is a dangerous application and ask for the ALLOW/DISALLOW.

I'm screwed totaly I tried cmd but not work same problem I use WinExec,ShellExecute,System,Createprocess but cant successed.

Any Help will be appreciable.


<minor phrasing clean-up by modus_operandi>
Avatar of DonConsolio
DonConsolio
Flag of Austria image

This is the expected behaviour of AV programs - they prevent unknown processes
from making such modifications to your system. You can either whitelist your application
or press allow.
Avatar of John-Paul75
John-Paul75

ASKER

Thanks...
These is not the way actualy I've to deliver this application to my client and at the time off demo he rejected this application because of it.

I need code which I should implement in my program
Any answer Plz.........................

It's an urgent
The following code would do that:
BOOL AddToRunKey ( LPCTSTR pszPath, LPCTSTR pszName) {

	BOOL bRC = FALSE;

	LPCTSTR pszSubKey = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
	HKEY hBase = HKEY_CURRENT_USER;

	HKEY hKey = NULL;
	REGSAM sam = KEY_SET_VALUE | KEY_READ;

	if ( ERROR_SUCCESS != RegOpenKeyEx ( hBase, pszSubKey, 0, sam, &hKey)) {

		return FALSE;
	} 

	__try {

	TCHAR acPath [ 2048];
	DWORD dwType = REG_SZ;
	DWORD dwSize = sizeof ( acPath);

	// Check if entry exists

	if ( ERROR_SUCCESS != RegQueryValueEx ( hKey, pszName, 0, &dwType, ( LPVOID) acPath, &dwSize)) {

		__leave;
	}

	// add new entry

		if ( ERROR_SUCCESS == RegSetValueEx ( hKey, pszName, 0, dwType, ( LPVOID) Path, dwSize)) {

		bRC = TRUE;
	}


	} __finally {

		RegCloseKey ( hKey);
	}

	return bRC;
}

Open in new window

Thanks Savant  thanks a Lot for ur quick and postive reply.

I've a question? I'm trying to make the start up entry for the all user weather I'm runnign this appliaction
from admin or from user account it should run from both accout.

While using KEY_ALL_ACCESS I've problem in windows 7 a promt came with the notification that you don't have the right priveledge to execute.

Well till now my main problem is not resolved i.e. when ever I try to invoke RegSetValueEx function Kaspersky and norton (an anvirus installed on my client PC) promt that "A dangerous program is going to run" will you allow it for running or not or block it . when ever I remove this function from my programm it work smooth.One thing more these antivirus were asking for the digital siganture to.

Why these problem persists I don't know I'm facing these ploblem since 2-3 days I've tryied all the possible know logic off mine but still stucked.

Whie googling I had found that API function hooking can make it possible but i didn't find any perfect
code regarding that I think it help me.

Please Help Me regardign  these ................

Well, that's the problem with scanners like these, they hook these calls and bring up reports regardless of the application being hostile or not. The only thing you could do is clearly informing the user that you are in fact placing an entry there and that their AV scanners will report that - that's pretty much it...
Hi Savant,

But we can't stop in this way we have to find the proper way to resolve this.
What I found is the only way is to use hooking of api the then change the memory location of the process and call it but don't know to implement it.

May be I'm wrong some were because I'm giving the answer from a malware forum .

But I  need help in this regard,
Thanks n Adv.
The only way is to ask the user to deactivate the scanner - you cannot avoid the scanner detecting the access to that very registry key and alarming the user.
You can try get a code signing certificate and sign your program, which could make these scanners happier.


Or perhaps making a shortcut in the Autostart section of start menu will work better for you?
Humm..
you all right but the point is not their any way to do that.

pjasnos can help me in making this shortcut in startup menu through c++ or if you know any link
then Please....

Thanks you all for such a postive reponse.. Apprecitating reponse.
ASKER CERTIFIED SOLUTION
Avatar of pjasnos
pjasnos
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks pjasnos,

I definately help me.

But is their any other help which is tested and fully confident one that antivirus would
not signal only for theses a dangerous application.
It depends on the antivirus and it's configuration. There is a alot of ways you can make your application autostart - e.g. you can write a windows service.

You can find a long list of most of the ways you can make a program autostart here:
http://gladiator-antivirus.com/forum/index.php?showtopic=24610

Thanks but this all r the detected behaviour of the antivirus,
may this acitvity degrade my applications.

I'm looking for the process which dont promt or let them to promt
as virus behaviour.

As this is my issue may be it comes 2 u all, so if u find any perfect solution
then intimate me Please.

Well at present I'm using the codes which were suggested by pjasnos and jkr.
Checking which will succeed
Not quite sure why you would want to delete this Q. All the choices have been presented to you, yet you refuse to accept that you cannot circumvent a scanner alert. That will happen, and all you can do is informing the user up front.
I've got a feeling you're using an antivirus with some sort of 'paranoid' settings enabled. If a user wants to enable such settings and be notified about *everything*. then that's what he should get.

As for a startup entry - why not create it with the installer you're using for packaging your program? With a tickbox allowing the user to choose whether to auto-start your program and then they would expect their antivirus to pop-up and indicate that some program wants to adds its entry to auto-start key/folder.
I repect u all quick response well creating a installer may make some thing possible for me and that
what I've decicded to do that's why I tooked this decision.

Well if any one succeed in by passing the pop up of this antiviruses then please mail me ([email address removed - Modalot]) and I do try my best to resolve  with this issue.

I'm not disappointed from you all best efforts but I don't yet got the perfect answer of my question
Thanks u All
I am afraid there is no "perfect" answer to your question.
The answer would be a way to circumvent system/antivirus protection and
such answers would violate the Experts Exchange Guidelines.
DonConsolio is right .

Well i'm agree with the suggestion of the pjasnos and I've also given my feedback on that.In this case I seem to be right and you r wrong modus operans.

As I'm not disagree with my all friends who hardly answered my question.I really appreciates the forum quick reply and I'm again and agian going to ask my problem with u all friends.

But I've yet not got the way that I was expecting. But friends I don't want to hurt any one efforts.
Sorry If my any commends hurts u all respected members.


I was here to got my anwer may be next time definetly you or me give the answer.
But right now I'm not using any of the features mentioned above I just use the installer for the deployment of my application.

OK still if some one can answer u are welcome other wise I request authoried person to delete this question.

Thanks