Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Difference between Line Termination or Endings in Windows '/r/n' and UNIX '/n'. Different types of Line systems.

Hi Everyone in todays post, I will explore the Line Endings or End of Line (EOL) in different system and how to identify them -

First thing to note is -
0d stands for Carriage Return - CR
0a stands for Line Feed - LF

In Windows System when we press ENTER KEY a new line is represented with Hex control character of 0d and 0a.

In UNIX system, when we press ENTER KEY a new line is represented with Hex control character of 0a.

OS X also uses a single LF character, and classic Mac operating system used a single CR character for line breaks

Here (in Windows) we will use the below Text to create a file
First Line then Enter Key pressed
Second Line then Enter Key pressed


HEXADECIMAL View of Text File Created in WINDOWS system 

HEXADECIMAL View of Text File Created in WINDOWS system
 As we can see, for the file created in Windows system new line is represented by the characters 0d and 0a which is Carriage return and Line Feed

A problem occurred while installing selected Windows SDK components.


Hi Everyone, Sometimes when we are installing Windows SDK in the system we get the below error, In this post I will give the solution to fix it

A problem occurred while installing selected Windows SDK components.
Installation of the "Microsoft Windows SDK for Windows 7" product has reported the following error: Please refer to Samples\Setup\HTML\ConfigDetails.htm document for further information.
Please attempt to resolve the problem and then start Windows SDK setup again. If you continue to have problems with this issue, please visit the SDK team support page at http://go.microsoft.com/fwlink/?LinkId=130245.
Click the View Log button to review the installation log.


Solution –
Uninstall any Visual C++ components that’s already installed and try installing it.


Note - You can check the installed components by opening Add or Remove Softwares by Win Key + R and typing appwiz.cpl

C# program to Create a Unix style Text File with Line Termination of LineFeed 0a only How to

To Create a Unix style text file in C# we use the NewLine Property of the TextWriter class to set the line termination format to UNIX type.

For More information of different types of line Termination refer to my earlier post –

Syntax of NewLine property of TextWriter
public virtual string NewLine { get; set; }

If we need to create a file with Windows type of line termination, we set the NewLine property to "\r\n".
If we need to create a file with UNIX type of line termination, then we set the property to "\n"
If the NewLine property is not set, the default newline character("\r\n") is used.

Sample Code to Write Unix Type File in C#
using System;
using System.Text;
using System.IO;

namespace UnixFile
{
    class Program
    {
        static void Main(string[] args)
        {
            //Data for the text file, is stored inside a string array
            string[] lines = { "First Line", "Second Line" };

            //Variable fileDetails contains the file name and path
            String fileNameAndPath = "C:\\Sample Text File.txt";

            //Below line of code will delete the file if it already exists (OPTIONAL)
            if (File.Exists(fileNameAndPath)) { File.Delete(fileNameAndPath); }

            //Create a StreamWriter object
            using (TextWriter objFile = new StreamWriter(fileNameAndPath))
            {
                //Set the New line Property to Unix type of New line
                objFile.NewLine = "\n";
                objFile.WriteLine(lines[0]);
                objFile.WriteLine(lines[1]);
            }
        }
    }
}

Important commands in Windows for Professionals (Part – 1)

Hi everyone, in this post I will explore some important commands in windows., so let’s start the journey.
The reason that I have written this post is to get familiarity about the important commands that can be used to automate tasks.

The commands that i will be exploring in this post are
1) taskkill
2) net stop | net start
3) appcmd start sites | appcmd stop sites
4) hostname
5) shutdown

Note – We can get help about the commands directly from the command prompt itself by typing
command_name -? .

1) taskkill

This command is used to terminate tasks either by name (image name) or process id (PID).

Syntax:  taskkill {–PID Process_ID | -IM image_name}

When we open a notepad application a process is started the image name is usually "notepad.exe" and the process id is some number.
If we open the notepad application again a new process is started with the same image name “notepad.exe”, here the image name is same as the previous image name but for this instance the process id will be different.

Creating a custom view in windows event viewer to show system turn on time and turn off time.

Hi, In this post familiarizes to use the windows event viewer  that is inbuilt into the Windows OS.

Event Viewer - Event Viewer is an application that captures all the events that occurs in the Windows OS In simple words it provides the logging functionality.

Eg - Shutting down is an event in Windows and is captured with the event id 6005

Here we shall create a custom view that captures the time of logins and logouts on the Windows OS.
The same method can be used to capture other events also

Note - 
The event id for system turn on is 6005
The event id for system turn off is 6006