selman555
New member
Hi to all...
Im a newbie when it comes to C#, so Im going to need the help of a willing C# programmer.
Ive made a little app that checks the installation state of several programs of my choise.
But there are several issues that I cant troubleshoot...
Please help me understand C# better by solving some issues for me:
- The app should stop at the end of the main() and wait for the user to complete the program (but doesnt) - marked with bold
- If the app wasnt found, it should open a downloadlocation (url) with the default browser (but doesnt find the correct settings and always opens with IE). I know that URLs can only be assigned to IE using default programs, but dont know if that the problem - marked with italics
- After checking/installing Ccleaner, it should ask weither I would like to install spybot by answering j or n (works with ccleaner), but instead it just completes the app and closes (even with the console.read() at the end of the main() - marked with underlining
- If you need to download and install any app recommended by the program, it should wait until the app has been opened by the user, but doesnt seem to do so - marked with strikethrough
There is always room for improvement/tips. Any given codes should be pretty straight-forward to me, but please explain as much as you can.
Im a newbie when it comes to C#, so Im going to need the help of a willing C# programmer.
Ive made a little app that checks the installation state of several programs of my choise.
But there are several issues that I cant troubleshoot...
Please help me understand C# better by solving some issues for me:
- The app should stop at the end of the main() and wait for the user to complete the program (but doesnt) - marked with bold
- If the app wasnt found, it should open a downloadlocation (url) with the default browser (but doesnt find the correct settings and always opens with IE). I know that URLs can only be assigned to IE using default programs, but dont know if that the problem - marked with italics
- After checking/installing Ccleaner, it should ask weither I would like to install spybot by answering j or n (works with ccleaner), but instead it just completes the app and closes (even with the console.read() at the end of the main() - marked with underlining
- If you need to download and install any app recommended by the program, it should wait until the app has been opened by the user, but doesnt seem to do so - marked with strikethrough
There is always room for improvement/tips. Any given codes should be pretty straight-forward to me, but please explain as much as you can.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.Win32;
using System.Timers;
namespace Opschonen
{
class Onderhoud
{
static bool b = false;
static Process p;
static void Main()
{
//Ccleaner installeren:
Console.WriteLine("Ccleaner:"+Environment.NewLine+"Een programma dat uw pc opschoont."+Environment.NewLine+"Met dit programma verwijderd alle overbodige bestanden op u pc, scant u het register op fouten en helpt u bij het instellen van opstartinstellingen."+Environment.NewLine+"En nog veel meer...");
String Ccleaner = "Ccleaner";
String CcleanerProces = "Ccleaner.exe";
Start(CcleanerProces, Ccleaner, "cant post links yet :s");
//Spybot S&D installeren:
Console.WriteLine(Environment.NewLine+"Spybot Search & Destroy:" + Environment.NewLine + "Een programma dat u de beste gratis bescherming kan geven tegen de meest schadelijke virussen." + Environment.NewLine + "De belangrijkste functies van het programma zijn als volgt:");
Console.WriteLine("- Scannen op virussen: In Windows en bij het opstarten van Windows" + Environment.NewLine + "- Live protecten: Detecteert ongewenste verandering van instellingen." + Environment.NewLine + "- Browser Detection en Immunization: Maakt het systeem immuum voor virusaanvallen in de toekomst en beschermt u browser tegen misbruik van buitenaf.");
[u]Console.Write(Environment.NewLine + "Wilt u Spybot - Search & Destroy installeren op u systeem? (j/n): ");
if (j == Console.Read())[/u]
{
String Spybot = "Spybot - Search & Destroy";
String SpybotProces = "C:\\Program Files (x86)\\Spybot - Search & Destroy\\SpybotSD.exe";
Start(SpybotProces, Spybot, "cant post links yet :s");
}
Console.WriteLine(Environment.NewLine+"De door u gevraagde programmas zijn geinstalleerd"+Environment.NewLine+"Druk op een toets om af te sluiten...");
[b]Console.Read();[/b]
}
public static void Start(String proces, String naam, String URL)
{
[i]string key = @"htmlfile\shell\open\command";
RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(key, false);[/i]
Console.Write(Environment.NewLine + "Wilt u " + naam + " installeren op u systeem? (j/n): ");
if (Console.Read() == j)
{
try
{
Console.WriteLine("De status van " + naam + " controleren...");
p = Process.Start(proces); //nieuw proces starten
b = true;
}
catch
{
Console.WriteLine(naam + " is niet aangetroffen of bevat een fout...");
Console.WriteLine("Er opent zich een website waar u " + naam + " kan downloaden.");
Console.WriteLine("Druk op een toets om verder te gaan...");
//In het register de default browser zoeken en starten met de opgegeven link
[i]Process.Start(((string)registryKey.GetValue(null, null)).Split(")[1], URL);[/i]
while (b == false)
{
[s]IsProcesOpen(proces);[/s]
}
}
}
if (b == true)
{
p.Kill();
b = false;
}
Console.WriteLine(naam + " is correct geïnstalleerd en is functioneel.");
}
private static void [s]IsProcesOpen(string proces)[/s]
{
//Gaat de lijst met alle actieve processen af...
foreach (Process clsProcess in Process.GetProcesses())
{
//Gaat controleren of er een proces bestaat met de opgegeven naam zonder .exe erachter.
if (clsProcess.ProcessName.Contains(proces))
{
//Als het proces is aangetroffen geven we een true terug
b = true;
}
}
}
}
}