Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Windows Console Application exe is not calling the main method when installed and system is logged off and logged in back I have created a windows console application and then its EXE using Visual Studio Installer ==> Setup Project. My requirement is that this application starts automatically when system reboots or is logoff/login . Fir this, i added the shortcut to Windows startup folder in setup project. After installing the exe, it gets start automatically. I can check this in task manager. But when system gets re start or log off and log in, the exe is not working. Though, in task manager it is showing as a running process but the main method is not getting called. Can anyone help me inn this? What I have tried: registery entry in LocalMachine>SOFTWARE>Microsoft>Windows>CurrentVersion>Run registery entry in CurrentUser>SOFTWARE>Microsoft>Windows>CurrentVersion>Run

What I have tried:

Above
Posted
Updated 7-Jul-17 9:31am
v6
Comments
Arun Vasu 7-Jul-17 6:08am    
Hi,
I hope your console application is doing background work,so you can achieve the goal using window service instead of console application.
tewary_manish 7-Jul-17 7:48am    
windows service will not capture active window details, my requirement was to capture the foregroundwindow details. The windows service will not give you this. I tried and googled also. Thats y i decided to go for a console app and while deploying I am making it as a window application from properties=>application
Richard Deeming 7-Jul-17 15:26pm    
Removing the content of your question after solutions have been posted is extremely rude!

There is a problem with your code because there is no such thing as "the Main method isn't being called". If your console app is in Task Manager, your Main method was called. Period, end of discussion.

But, since we can't see your code, we can't possible tell you what you did wrong.
 
Share this answer
 
Maybe putting a shortcut in the Windows Startup folder will help, see: How to Make a Program Run at Startup on Any Computer[^]
But you probably already tried that.
A problem in Windows 10 is that the shortcut won't work if 'Administrator' privileges are set.

Some good answers can be found here: EXE in Startup folder not running Solved - Windows 10 Forums[^]

To run a program requiring admin access at startup in Windows 10, just create a shortcut (anywhere, I used the Startup folder itself) with "run as administrator" checked, then create a short batch file in the startup folder and use the 'start' command to launch the shortcut (omit the .lnk extension and the path, else start won't work, so use 'cd' to change to the shortcut directory first). Example:
C#
@echo off
cd "C:\Users\...\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
start ThrottleStop
 
Share this answer
 
v3
Comments
tewary_manish 7-Jul-17 5:52am    
I already tried that, my shortcut is visible under "shell:startup". The application is also available under task manager after login back. But some how the functionality is not working. I mean "THE MAIN METHOD IS NOT GETTING CALLED AFTER REBOOT OR LOGFF/LOGIN".

I PUT A LOG AT THE VERY FIRST LINE OF ENTRY POINT i.e, THE MAIN METHOD BUT THAT IS ALSO NOT WORKING.
tewary_manish 7-Jul-17 6:04am    
I want to do it programmatically, the requirement is this exe will be pushed by admin to all the system in the organization and will run in the background when every any user logs in.
A way to do it programmatically is to use Task Scheduler, here is an example that shows the manual way: Elevated Program Shortcut without UAC Prompt - Create - Windows 7 Help Forums[^]
There are several ways to program Task Scheduler, via the API, or via DOS commands.
For simplicity I would recommend using DOS commands.
Good luck :)
 
Share this answer
 
Comments
tewary_manish 7-Jul-17 7:51am    
Let me tell you what I have done so far:

You told me that it could be the problem of set not installed as "Run As Administrator". So Just for testing, i uninstall that and installed again with Run As Admin. Application started just after installation automatically. But when I logged of and logged in back, again the same problem.

I can see that in task manager as an active process but it is not performing its functionality. I told you earlier also that not even the first line of the "MAIN METHOD" is executing.

SO I THINK, THERE IS SOME OTHER PROBLEM. EVEN IF I MAKE MY INSTALLER RUN AS ADMIN PROGRAMMATIC, IT WILL NOT RUN AFTER LOGIN BACK WHICH IS THE ORIGINAL PROBLEM.

My question is here is why the application is not running even though it is showing as active task in task manager?
RickZeeland 7-Jul-17 9:03am    
I don't have a crystal ball, so I don't know what exactly you did to create the console app, did you do anything special like modifying the .manifest file maybe ?
Can you show the code ? Does a standard console app run as expected on your machine ?
RickZeeland 7-Jul-17 9:10am    
I think I see your problem now, as you replied to Arun Vasu you said:
I am making it as a window application from properties=>application
Why didn't you say that in the first place ?
Just retry by creating a normal Windows application and see if that works.
tewary_manish 7-Jul-17 13:16pm    
Thanks all for suggestions/help.
I reverted it normal console app and problem remains the same. If this would have been the case, it will not run at the first time also automatically i.e, just after installation.

I think i got the problem, I am using SQL lite DB for this application. I put various log points and observed that connection object is not getting opened up (Issue with "con.open()"). Though it is running find after installation. THE PROBLEM COMES ONLY AFTER REBOOT OR LOGGOFF/LOGIN BACK.
tewary_manish 7-Jul-17 14:28pm    
Got the issue, it was because of missing manifest file in the project as the application required administrative privilege.

Thank you all for help and suggestions

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900