New to this and need help!
I'm totally new to C#. I just started working on my first program today.
Basically what I'm trying to do is create an application that, when executed, will grab files from the registry and place them into a notepad file (and then later on possibly have it set to email this file to me).
I have created the console application file (using SharpDevelop) and a batch file. My question now is, what do I do with it? How do I get the batch file in with the actual application program? I just want to create the program so i can send it to someone and when they open it, it will execute automatically. Or, if possible, I'd like for it to be a web application...as in when someone goes to a link, the program will execute from there.
This is the code I have so far:
Quote:
using System;
using Microsoft.Win32;
class reg
{
static void Main()
{
RegistryKey hklm =Registry.LocalMachine;
hklm=hklm.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0 ");
Object obp=hklm.GetValue("Identifier");
Console.WriteLine("Processor Identifier :{0}",obp);
RegistryKey hklp =Registry.LocalMachine;
hklp=hklp.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0 ");
Object obc=hklp.GetValue("VendorIdentifier");
Console.WriteLine("Vendor Identifier :{0}",obc);
RegistryKey biosv =Registry.LocalMachine;
biosv=biosv.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\MultiFunctionAdapte r\\4");
Object obv=biosv.GetValue("Identifier");
Console.WriteLine("Bios Status :{0}",obv);
RegistryKey biosd =Registry.LocalMachine;
biosd=biosd.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
Object obd=biosd.GetValue("SystemBiosDate");
Console.WriteLine("Bios Date :{0}",obd);
RegistryKey bios =Registry.LocalMachine;
bios=bios.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
Object obs=bios.GetValue("Identifier");
Console.WriteLine("System Identifer :{0}",obs);
string x = Console.ReadLine();
}
}
Like I said, I have the batch file and everything created. Now what do I do with it? Any help is greatly appreciated.
Thanks in advance.
Re: New to this and need help!
To execute an external file you call Process.Start. In a console app you can get the folder from which it was executed using:
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
This means you can execute a batch file from the same folder as your EXE like this:
Code:
System.Diagnostics.Process.Start(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "MyFile.bat"));
Note that you must ensure that the .NET Framework is installed on all target machines or your app will not run.
Re: New to this and need help!
So I just insert this
System.Diagnostics.Process.Start(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Refle ction.Assembly.GetEntryAssembly().Location), "MyFile.bat"));
somewhere in my program? After placing the .bat file in the folder that contains the solution files?
Re: New to this and need help!
You place the batch file in the same folder as the executable, which is not the same as the solution folder. The solution folder contains the solution and subfolders for each project. Each project folder contains the project source files and some subfolders, including a 'bin' folder. Depending on your project settings, that 'bin' folder will either contain the EXE itself, or it will contain Debug and Release folders, which will contain the EXE, along with anyother output files. If you add the batch file to your project then you can have it automatically copied to the output folder each time.