How to auto-start my own .NET app when Windows starts?

Page 1 of 5 123 ... LastLast

  1. Posts : 14
    Windows 10 Pro [Version 10.0.19041.329]
       #1

    How to auto-start my own .NET app when Windows starts?


    Hi,
    I'm having some trouble auto-starting my own application when Win10 starts / user logs in (auto-login enabled).
    I'm moving my application to a new machine running Windows 10 Pro [Version 10.0.19041.329].
    Before it was running on Windows 7 and there I just copied a shortcut to the executable into the Start-Up folder in the Start menu - simples...

    The application is my own C# .Net 4.5.2 app. It does not have an installer, I just copy all .exe and .dll files to a folder and run the .exe.

    I have followed a few tutorials (on here and other websites) but I just can't get the app to auto-start.

    Initially the app does not show up in Task Manager - Start-up (understandable as it was not installed through an installer, so Windows doesn't know about it)

    I have tried copying a shortcut to the folder that opens with "shell:startup". This did not make the app auto-start, but now it was showing up in Task Manager - Start-up as Enabled.

    I have also tried the "Use my sign-in info to automatically finish setting up my device after an update or restart" setting to no avail.

    I have also tried the "Register this program for restart" checkbox under Properties - Compatibility. With this enabled the app now seems to auto-start but it closes again after a second or two. It does actually seem to run for a bit as it has written some entries to its own log file. But I have no idea why it quits shortly after.

    If I run the app manually, everything works fine and as expected.
    The app is configured to run as Administrator, if that makes any difference.

    So the question is: What is the official / best way to make this kind of app auto-start on Windows 10? It was so easy on Win7!
      My Computer


  2. Posts : 17,641
    Windows 10 Pro
       #2

    Create a shortcut for your EXE file, place it in %userprofile%\Microsoft\Windows\Start Menu\Programs\Startup folder.

    Kari
      My Computer


  3. Posts : 11,634
    Windows 10 Home x64 Version 21H2 Build 19044.1776
       #3

    Add a startup command to Task scheduler and set the task to be triggered by user logon rather than startup because Windows resists that for Admin-level applications.

    To create a task that needs to run as Admin, you'll need to run TS as Admin so you can then set the task to run 'with the highest privileges'.

    TS can only start tasks as Admin if they have a user interface. If that is not the case then you have to jump through a few hoops - write a vbs procedure to start the application and set TS to run that vbs instead of the application itself.

    Denis
      My Computer


  4. Posts : 7,484
    Windows 10 Home 20H2
       #4

    I have put a VBScript file into C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
    The script is run at Windows startup. The script is shown on Task Manager-->Startup.
      My Computer


  5. Posts : 14
    Windows 10 Pro [Version 10.0.19041.329]
    Thread Starter
       #5

    Hi Dalchina. Thank for replying.

    dalchina said:
    It is most likely not compatible. as you say it seems to start, then closes.

    You haven't mentioned what happens if you simply try to launch it manually. Does it run then, or does it close?

    First prove it runs, then worry about it starting up.
    I have... Towards the bottom of my post: "If I run the app manually, everything works fine and as expected."
    So yes, when started manually, it works fine. I assume that means that all the prerequisites are there (.NET runtime, ...)

    dalchina said:
    Have a look at Reliability History. (Just type that in the search box). Do you see a red x corresponding to your program crashing?
    What does it tell you? Is there e.g. a BEX error?
    I didn't know about Reliability History, thanks. It shows one error related to my app. That was yesterday when the app auto-started and then quit after a few seconds.
    This is the error info.
    Code:
    Source
    HomeAutomation.Manager
    
    Summary
    Stopped working
    
    Date
    ‎11/‎06/‎2020 12:13
    
    Status
    Report sent
    
    Description
    Faulting Application Path:	C:\HA\Homeautomation.Manager.exe
    
    Problem signature
    Problem Event Name:	CLR20r3
    Problem Signature 01:	Homeautomation.Manager.exe
    Problem Signature 02:	2.0.7466.31878
    Problem Signature 03:	5ee10d7e
    Problem Signature 04:	System.Data.SQLite
    Problem Signature 05:	1.0.104.0
    Problem Signature 06:	585309b6
    Problem Signature 07:	e9
    Problem Signature 08:	125
    Problem Signature 09:	System.Data.SQLite.SQLite
    OS Version:	10.0.19041.2.0.0.256.48
    Locale ID:	2057
    Additional Information 1:	2beb
    Additional Information 2:	2beba6fb4680d73a8c78ca7c24ccdb46
    Additional Information 3:	ab31
    Additional Information 4:	ab31236752fcb0c711def892810629b8
    
    Extra information about the problem
    Bucket ID:	6406c044f5e6fca530512a38e6e11f48 (1175767401600458568)


    dalchina said:
    Is it all 32 bit or 64 bit code? Is any element of it 16 bits? If so, it won't run on a 64 bit system.
    It's all 32bit (x86 target). It was running fine on Win7 x64 and is running fine on Win10 x64 when started manually.

    dalchina said:
    I think you're aware of using rt click, click Troubleshoot compatibility.
    It recommend Windows 8 compatibility mode. I tried that and it makes no difference to auto start.

    - - - Updated - - -

    Kari said:
    Create a shortcut for your EXE file, place it in %userprofile%\Microsoft\Windows\Start Menu\Programs\Startup folder.

    Kari
    Thanks, but I tried that. This is the folder than opens when you type "shell:startup" in an Explorer window. Copying a shortcut to that folder made the app appear in Task Manager - Start-up. But it still doesn't start.
      My Computer


  6. Posts : 35,508
    Win 10 Pro (21H2) (2nd PC is 21H2)
       #6

    Sorry, missed the line where you said that it runs manually.

    Try3's right- if it needs admin privileges as you say, it won't run from the Startup folder- launch it as a scheduled task.
      My Computers


  7. Posts : 7,484
    Windows 10 Home 20H2
       #7

    Copy the following into a .vbs file and save it.

    CreateObject("wscript.shell").run("""C:\HA\Homeautomation.Manager.exe""")

    Double-click on the file and see whether the app is run. If it is run, copy the file into the following folder and see whether the app is run at Windows startup.

    C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

    If the app is not run at Windows startup, use Task Scheduler to run it.
      My Computer


  8. Posts : 14
    Windows 10 Pro [Version 10.0.19041.329]
    Thread Starter
       #8

    Thanks everyone!

    I have now tried with Task Scheduler and the VB script. In both cases the app starts briefly, then closes without any error messages. Reliability History shows an app crash just like the one I posted above.

    In Task Scheduler I have even tried delaying the start by 30 seconds (in case something wasn't quite ready when the app tried to start. No change.

    I just now noticed that the error (when it starts briefly, then stops) is actually in System.Data.SQLite
    That is a 3rd party library I use in my app. I assume that means that the issue is in that library?
    What I don't understand is, why, then, does it work if I start the app manually? What is the difference?
      My Computer


  9. Posts : 7,484
    Windows 10 Home 20H2
       #9

    yesyes said:
    What I don't understand is, why, then, does it work if I start the app manually?
    Manually run the following via Command Prompt and see whether it works.

    Start "" "C:\HA\Homeautomation.Manager.exe"
      My Computer


  10. Posts : 7,484
    Windows 10 Home 20H2
       #10

    yesyes said:
    What I don't understand is, why, then, does it work if I start the app manually?
    Manually run the following via PowerShell and see whether it works.

    Start-Process "C:\HA\Homeautomation.Manager.exe"
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:36.
Find Us




Windows 10 Forums