0

For some CAD software i have been making a cleanup program (WPF) that can clean certain types of temp and journal files that i wont need anymore, but that my cad software does not clean out of itself.

As i made it into a WPF application, i just made a button to clean up any filetypes that i wont need.

Now i have been looking for a function to make it execute after i have logged into windows. So i do not try to execute the full program after the startup, only one of the commands within the program. I know that there is a folder called startup in windows, but i preffer not to use that one. Is it possible to do it in a different way? So i can just make a checkbox in my application where i can set yes or no to make it run at startup?

i have been looking around, but havent realy found anything about this.

2
  • Another option is to add it to the registry, which you can do from within your application (make sure to check the appropriate permissions!!) check this out; stackoverflow.com/questions/674628/… May 31, 2013 at 12:32
  • ill check that link out, thanx. Also added a small line to the question to explain my question bit better: "So i do not try to execute the full program after the startup, only one of the commands within the program."
    – Dante1986
    May 31, 2013 at 12:34

3 Answers 3

1

In accordance to your edit;

Check out your startup options in this post; How do I set a program to launch at startup

Then with you addition of 'So i do not try to execute the full program after the startup, only one of the commands within the program'; make use of start-up parameters. Supply your application with a command-line parameter and check it in your application's Program.cs.

When the right parameter is set, just clean your files and don't show the interface. When the parameter isn't set (which it won't be when the user just double clicks the icon) run your program like normal.

To use command-line arguments just add a string[] parameter to your Main method like so;

public static void Main(string[] args)
   {
       Console.WriteLine("Number of command line parameters = {0}",
          args.Length);
       foreach(string s in args)
       {
          Console.WriteLine(s);
       }
   }

Your full (pseudo-)code would look like this:

public static void Main(string[] args)
   {
       if (args[0].Equals("/JUSTCLEANPLEASE"))
          JustClean();
       else
          Application.Run(new Form1());
   }
1
  • thanx a lot, i think this will really help me to make what i want to.
    – Dante1986
    May 31, 2013 at 12:45
1

Why do you not want to use the auto start directory?

There are some alternatives to this. Please refer to this knowledgebase article: http://support.microsoft.com/kb/137367/en-us When you create an entry in one of those nodes specified in the link you can control whether you want to run something on every start up or only once (see RunOnce).

The simple approach would be creating a batch file in a temp directory or somewhere where it won't be deleted and add it to one of the auto run nodes, that is appropriate for you. Samples on how to access registry with C# are plenty. Edit: Or see the link, provided by Gerald Versluis However keep in mind that there is a difference in Run and RunOnce of these different nodes

0

Not sure how your program is set up, but I would split the user interface (GUI) from the logic.

You could create a service for the logic and the WPF user interface would seperately call this service.

You could then write a little code to call the service without having to use the GUI.

Have a look in MSConfig.exe for better control over the startup and services etc.

Not the answer you're looking for? Browse other questions tagged or ask your own question.