Monday, December 10, 2007
ServiceController class to interact with windows service
You can use the ServiceController class to connect to and control the behavior of existing services. When you create an instance of the ServiceController class, you set its properties so it interacts with a specific Windows service. You can then use the class to start, stop, and otherwise manipulate the service.
Friday, December 7, 2007
Thursday, December 6, 2007
Opening a File e.g. PDF, EXCEL, WORDD etc.
ProcessStartInfo ps = new ProcessStartInfo(@"c:\CERT\ActualTest_070-444_v03.27.07.pdf");
Process pr = new Process();
pr.StartInfo = ps;
pr.Start();
Process pr = new Process();
pr.StartInfo = ps;
pr.Start();
Wednesday, December 5, 2007
TraceListeners
Create Listeners like Console, Textwriter and eventlog and add it to the List of listeners of Trace Class, whenever anything in written to Trace or Debug it will be written to all the registered listeners. In order to enable trace and debug, right click the project in visual studio solution explorer and click properties, go to the Build tab and check the boxes against TRACE and DEBUG
using System.Diagnostics;
Stream str = File.Create(@"c:\test_env\log.txt");
TextWriterTraceListener twl = new TextWriterTraceListener(str);
ConsoleTraceListener cwl = new ConsoleTraceListener();
EventSourceCreationData esct = new EventSourceCreationData("", ""); ;
esct.MachineName = ".";
esct.LogName = "Application";
esct.Source = "MyLog";
if (!EventLog.SourceExists("MyLog"))
{
EventLog.CreateEventSource(esct);
}
EventLogTraceListener elt = new EventLogTraceListener("MyLog");
Trace.Listeners.Add(twl);
Trace.Listeners.Add(cwl);
Trace.Listeners.Add(elt);
Debug.WriteLine("Hello Debug");
Trace.WriteLine("Hello Trace");
Trace.Flush();
using System.Diagnostics;
Stream str = File.Create(@"c:\test_env\log.txt");
TextWriterTraceListener twl = new TextWriterTraceListener(str);
ConsoleTraceListener cwl = new ConsoleTraceListener();
EventSourceCreationData esct = new EventSourceCreationData("", ""); ;
esct.MachineName = ".";
esct.LogName = "Application";
esct.Source = "MyLog";
if (!EventLog.SourceExists("MyLog"))
{
EventLog.CreateEventSource(esct);
}
EventLogTraceListener elt = new EventLogTraceListener("MyLog");
Trace.Listeners.Add(twl);
Trace.Listeners.Add(cwl);
Trace.Listeners.Add(elt);
Debug.WriteLine("Hello Debug");
Trace.WriteLine("Hello Trace");
Trace.Flush();
Monday, December 3, 2007
Code Access Security (CAS) Policy - Tool Caspol.exe
Security policy is expressed using three policy levels: machine policy, user policy, and enterprise policy. The set of permissions that an assembly receives is determined by the intersection of the permission sets allowed by these three policy levels. Each policy level is represented by a hierarchical structure of code groups. Every code group has a membership condition that determines which code is a member of that group. A named permission set is also associated with each code group. This permission set specifies the permissions the runtime allows code that satisfies the membership condition to have. A code group hierarchy, along with its associated named permission sets, defines and maintains each level of security policy. You can use the–user, -customuser, –machine and -enterprise options to set the level of security policy.
Subscribe to:
Posts (Atom)