Kill Process in C# Application

using System.Diagnostics;


public bool FindAndKillProcess(String name)
foreach (Process clsProcess in Process.GetProcesses())
if (clsProcess.ProcessName == name)
return true;
return false;

Create an XML Video Player Using ActionScript 3.0

This tutorial will teach you how to create a dynamic XML video player in Flash using AS3. This sort of player could be used in portfolio websites, product display websites, or any project that allows the user to select a video to play from a certain playlist. The player will of course be configured using XML – meaning that you can update the contents of the player without having to update your actual FLA.

This is an intermediate level tutorial that uses the FLVPlayback Component, the Loader Class, and various AS3 basic concepts such as Variables, the Display List, and Event Handling. Make sure you review all these other tutorials in order to fully understand how this tutorial works.

The backend concept of our player is simple: All the data of the player will be stored in an XML file that is loaded when the Flash movie starts. The thumbs are loaded instantly while the videos will only be loaded when a thumb is clicked. The description of the video, its URL, and its thumb URL are all stored in the XML file, the videos and thumbs are stored externally as separate files, so there is nothing left in the SWF other than ActionScript code and some component assets.

Our Video Player project is divided into the following sections:

  1. Preparing External Assets (XML, Videos, and Thumbs) and the FLA.
  2. Loading and processing the XML file.
  3. Creating the playlist container and loading all the thumbs.
  4. Positioning the thumbs and video description.
  5. Creating the FLVPlayback component and playing a video.
  6. Polishing the player and fixing bugs.

Preparing External Assets and the FLA

This tutorial requires you to have three videos in FLV format and three thumbnails of these videos. We are not going explain the basics on how to create an FLV video, if you would like to learn more about this please review our previous video on using the AS3 FLVPlayback Component. You can use your own videos for this tutorial, or alternatively you can download the videos we used in the example above to follow this tutorial from here.

Once you have your videos and thumbs ready I suggest that you start off by creating a folder for this project somewhere on your computer. In side this project folder we are going to have two folders, one will be used to host our videos while the other will be used to host our thumbnails. Start by creating the first folder, name it video.

Inside the video folder we will place our three FLV files. To make things easier and to minimize the risk of typos, I suggest that you rename your video files to video1, video2, and video3.

Our videos are now ready, we will create another folder for our thumbnails. Go up to the project folder and create a folder named thumbs for your thumbnails right next to your videos folder:

Inside the thumbs folder we will place our three thumbnails. Again, I suggest that you rename your thumbs to thumb1, thumb2 and thumb3 to correspond with the videos.

Our videos and thumbs are now ready, we will create our XML file next. The XML file will play the role of a playlist – it will have the details of the videos that we want to play.

An XML file is essentially a text file with user-defined structured coding. You can use any simple text editor to create your XML file, open the Notepad and save a blank file as playlist.xml in your project folder along with your video and thumbs folders:

Preparing the XML File

We are going to add to our XML file the information we need to run our video player. The XML file will have two types of information:

  1. General player details such as the position of the main video player, the position of the thumbnails list and the size of thumbs used.
  2. Video Specific details such as the title of the video, the URL of the video, and the URL of the thumbnail.

The general structure of our XML code is as shown in the code below, one <playlist> element will enclose several <video /> elements within it. The general player details will be set in parameters held within the <playlist> element while the video specific details will be set in parameters held within each of the <video /> elements.

<?xml version=”1.0″ encoding=”utf-8″?>
<playlist para1=”value” para2=”value” … >
<video para1=”value” … />
<video para1=”value” … />
<video para1=”value” … />

Our actual code will have the following parameters specified in the <playlist> element:

  1. The horizontal position of the thumb container.
  2. The vertical position of the thumb container.
  3. The width of thumbs used.
  4. The height of the thumbs used.
  5. The horizontal position of the video player.
  6. The vertical position of the video player.

Each of our <video /> elements will have the following parameters:

  1. Video title.
  2. Video URL.
  3. Thumb URL.

The values of all these parameters will be retrieved in Flash using the .attribute property of the XML element. The value of these parameters is specified in the code below, it is pretty self-explanatory, you can copy and paste it into your XML file. You may change any of these values as you please later on to configure your own video player:

<?xml version=”1.0″ encoding=”utf-8″?>
<VIDEO TITLE=”Whistle Stop Train Tour” THUMB=”thumbs/thumb1.jpg” URL=”video/video1.flv”/>
<VIDEO TITLE=”Obama Weekly Address” THUMB=”thumbs/thumb2.jpg” URL=”video/video2.flv”/>
<VIDEO TITLE=”Lincoln Memorial Concert” THUMB=”thumbs/thumb3.jpg” URL=”video/video3.flv”/>

You might have noticed that we did not specify the number of videos in our playlist, that is because the ActionScript XML Class can detect the number of child nodes within an element, and that in our case is the number of <video /> elements with the <playlist> element, i.e. the number of videos in our playlist.

Please refer to our AS3 XML tutorial to learn more about using XML in ActionScript 3.0.

Preparing the FLA

Our external assets are now ready, it is time to create the FLA. Create new Flash file in AS3 format, save it as My Video Player in the same folder as your XML file and your other two folders. Make sure the ActionScript version is set to 3.0 and the dimensions to 800×300px.

Our FLA is now set, our videos and thumbnails are in their appropriate folders, and we have our XML file ready as well. The rest of our video player project will be coded in ActionScript. In Flash, Right-Click the only frame you have on your timeline and select Action to open up the Action Panel.

Summary of this Page

  1. Put the videos and images in their specified folders.
  2. Created the XML playlist file.
  3. Create the FLA file.


Select data that is not match data in another table in MySQL

We have mock up data in both table as below:

ID Name
1 Mr. A
2 Ms. B
3 Mrs. C


ID Table1ID Name
1 3 ABC Beer
2 1 Tiger Beer

And we want to select data in table1 that is not avaiable in table2, so when you want to do as I said.

You should use:

SELECT table1.*

FORM table1 LEFT JOIN table2 ON table1.ID = table2.Table1ID

WHERE table2.Table1ID is null



ID Name
2 Ms. B

Get Users Account List in C# Application

DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName);
 DirectoryEntry admGroup = localMachine.Children.Find("Users", "group");
 object members = admGroup.Invoke("members", null);
 foreach (object groupMember in (IEnumerable)members)
 DirectoryEntry member = new DirectoryEntry(groupMember);
 if (member.Name == "eDocUser")
 return true;

Add Local User Account in C# Application

This step-by-step article shows you how to use the DirectoryServices namespace to add a user to the local system and a group.

  1. Start Microsoft Visual Studio .NET 2003, Microsoft Visual Studio 2005, or Microsoft Visual Studio 2008, and then create a new Visual C# Console Application project.
  2. In Solution Explorer, right-click References, and then click Add Reference.
  3. Add a reference to the System.DirectoryServices.dll assembly.
  4. Replace the code in the Class1.cs file with the following code.Note In Microsoft Visual C# 2005 or Microsoft Visual C# 2008, the Class1.cs file is replaced by the Program.cs file.
using System;
using System.DirectoryServices;

class Class1
    static void Main(string[] args)
	 DirectoryEntry AD = new DirectoryEntry("WinNT://" +
	                     Environment.MachineName + ",computer");
	 DirectoryEntry NewUser = AD.Children.Add("TestUser1", "user");
	 NewUser.Invoke("SetPassword", new object[] {"#12345Abc"});
	 NewUser.Invoke("Put", new object[] {"Description", "Test User from .NET"});
	 DirectoryEntry grp;

	 grp = AD.Children.Find("Guests", "group");
	 if (grp != null) {grp.Invoke("Add", new object[] {NewUser.Path.ToString()});}
	 Console.WriteLine("Account Created Successfully");
    catch (Exception ex)



Get Hardware Information in C# Application

Making sure your software is used by legal buyers is a concern for programmers around the world. My professor once said that we shouldn�t give 100% of our code to the users because there are people out there that are smart enough to decompile our programs and find the various verification algorithms used. He suggested that we give users 99% of our software, but keep the remaining 1% to ourselves. This 1% is the verification algorithm to confirm only valid users can use the program; this is commonly known as �activation.�

Activation is good, but it means our software users will need to have Internet access and that means small programmers like us have to set up a server that can validate users. Of course, only big companies with big clients can afford to do this. For the rest of us, we have to think of other ways.

One method programmers have used since the DOS era was to bind their software to the Hard Drive Volume Serial Number. This is not a good choice, as later we all find out that every time we format the same hard drive, a new Volume Serial Number is generated.

All bellow code, you need to add Window Reference :: Project -> Add References… and then select System.Management .  After that, you add import namespace into your source code by:

using System.Management;

Motherboard Serial Number

private string GetMotherboardSerialNumber()
 ManagementObjectSearcher searcher = new ManagementObjectSearcher
 ("SELECT SerialNumber, Product FROM Win32_BaseBoard");

 ManagementObjectCollection information = searcher.Get();
 string serialNumber = string.Empty;

 foreach (ManagementObject obj in information)
 if (obj.Properties["SerialNumber"].Value.ToString().Trim() != string.Empty)
 serialNumber = obj.Properties["SerialNumber"].Value.ToString().Trim();
 serialNumber = obj.Properties["Product"].Value.ToString().Trim();


 return serialNumber;

Reference by:

Hard Disk Drive Serial Number

private string GetHDDSerialNumber()
  string hdno = "";
  ArrayList hdCollection = new ArrayList();
  ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM   Win32_PhysicalMedia");
  int i = 0;
  foreach(ManagementObject wmi_HD in searcher.Get())
	// get the hard drive from collection
	// using index
	HardDrive hd = (HardDrive)hdCollection[i];

	// get the hardware serial no.
	if (wmi_HD["SerialNumber"] == null)
		hdno = "None";
		hdno = wmi_HD["SerialNumber"].ToString();

  return hdno;



Wraping field in crystal report

When you want to display long text in crystal report, and It won’t show you the whole text, you should wrap your text as below:

  2. Open The The Open The Report That You Want To Enable Word Wrap Report
  3. Right Click On The Field That You Want To Word Wrap.
  4. Select  Format Object
  5. Then Place A Check In The Box Can Grow and set the maximum line number.


Insert Watermark into Report Background

Text Watermark A common report request is the ability to add a watermark to a report indicating that it is a draft. This example will show you how to accomplish this. In order to create the watermark, create a new header section, add a text object for the watermark and select the “Underlay Following Sections” option. This allows for new header to be above the rest of the sections of the report.

  • Figure 14: The Section Expert

  • Figure 15: The watermark in the designer

  • Figure 16: Fulfillment report with draft watermark

Print Crystal Report with Khmer Unicode in C# Application

This step use to Microsoft Visual Studio.NET 2005, and it’s rendered well with Khmer Unicode.

  1. Copy usp10.dll into Business Object Location (ex: C:\Program Files\Common Files\Business Objects\2.7\Bin\)
  2. Go to Visual Studio.NET 2005 with Design View, and right click on ToolBox Panel -> Select Choose Items. After that    Select COM Components Tab -> Click on Browse Button and Select on crviewer.dll in Business Object Location
  3. Add Reference Project, You go into Business Object Location select craxddrt.dll .
  4. Create a new Crystal Report
  5. Go to Coding View and code like below:

Preview Crystal Report in Crystal ActiveX Report Viewer

CRAXDDRT.Application crxApp = new CRAXDDRT.Application();
CRAXDDRT.Report crxReport = new CRAXDDRT.Report();
crxReport = crxApp.OpenReport(Application.StartupPath
 + "/KhmerUnicodeTest.rpt", null);
CRAXDDRT.DatabaseTable crxdt = crxReport.Database.Tables[1];
crxdt.SetLogOnInfo("[Server Name]", "[Database Name]", "[User Name]", "[Password]");
crxReport.ParameterFields.GetItemByName("[ParameterName]", "[SubReportName]").AddCurrentValue(val);
crxReport.OpenSubreport("[SubReportName]").ParameterFields.GetItemByName("[ParameterName]", "").AddCurrentValue(val);

Auto Print with Default Printer

CRAXDDRT.Application crxApp = new CRAXDDRT.Application();
CRAXDDRT.Report crxReport = new CRAXDDRT.Report();
crxReport = crxApp.OpenReport(Application.StartupPath
 + "/KhmerUnicodeTest.rpt", null);
foreach (CRAXDDRT.DatabaseTable crxdt in crxReport.Database.Tables)
 crxdt.SetLogOnInfo("[Server Name]", "[Database Name]", "[User Name]", "[Password]");
crxReport.SelectPrinter("", "<Printer Name>", "");
crxReport.PrintOut(false, 1, true, 1, 200);

How to show “Printer Dialog”

CRAXDDRT.Application crxApp = new CRAXDDRT.Application();
CRAXDDRT.Report crxReport = new CRAXDDRT.Report();
crxReport = crxApp.OpenReport(Application.StartupPath
 + "/KhmerUnicodeTest.rpt", null);
foreach (CRAXDDRT.DatabaseTable crxdt in crxReport.Database.Tables)
 crxdt.SetLogOnInfo("[Server Name]", "[Database Name]", "[User Name]", "[Password]");

PrintDialog diag = new PrintDialog();
if (diag.ShowDialog() ==  DialogResult.OK)
   crxReport.SelectPrinter("", diag.PrinterSettings.PrinterName, "");
   crxReport.PrintOut(false, 1, true, 1, 200);

Notation: If you use Visual Studio 2008 for Project Development, you need Merge Module to install all client. It’s called (Crystal Report Basic 2008 Run Time Package)

Reference Code from