Thursday, February 21, 2019

How to install a .Net based Windows Service using InstallUtil.exe, see its status, start/stop it



How to Install a Windows Service Using InstallUtil and command prompt from Naeem Akram on Vimeo.




A demo day be really frustrating or it can be the happiest day of an IT professional's life.
Now I'm going to demonstrate the stuff which we've created so far in this course

You may join my course with special discount using the link given below.

https://www.udemy.com/tcpip-socket-programming-for-coders-using-csharp-net/?couponCode=HALF


The windows service solution is already open
I'll go and click build and build solution
Now I'm going to expand solution explorer
And click the button , "Show all Files"
Next I'm going to expand the "bin" folder
 then I'll right click the "debug" folder and select "open folder
 location"
 Take a brief look at the contents of this folder
The file Udemy Windows Service dot exe is going to run as our service.
For this purpose, we're going to use installutil.exe
It is shipped along with Microsoft .Net framework.
For this purpose I'm going to launch the developer command prompt
I'll click the Windows Button and type "Developer command prompt"
The developer command prompt for vs is showing on top
I'll right click this shortcut and select menu option "Run as
administrator"
Now I'm going to type the command installutil.exe space -i space
And then the path of the file which we want to install as a service.
I'll go back to the debug folder and shift right click the Udemy
Windows Service .exe file
I'll select the context menu option "Copy as path"
Now I'll go back to the command prompt windows
I'll right click it and select context menu option edit
And then select Paste

The full command is installtuil.exe pace minus i space path of
our windows service exe file
I will hit enter key on command prmopt

The system shows that the commit phase completed successfuly

Let us see if the service is showing up service control managter
or not
I'll open the SCM by pressing Windows R and typing services.msc
Inside the name column, I'll look for Udemy Demo Service
We can click inside the name column and press Udemy
You can see our very own Windows Service named "Udemy Windows Service"
 along with the descritpion
"My hello world servoce" right here
And it has got logon as "Local System"
You'll see that status of the service will change to "Running"
The actions button on top right will also change from start to stop
 and restart
I'm now going to click the stop link and that should stop the service
without any fuss
You see a progress bar popup
And the service status is changed to stopped.
That is it for this video
In the next one we'll take a look at the event log



Wednesday, February 6, 2019

Difference between a Windows Service Solution and a Console Application By Example


Windows Services are the engine that most people never see, these are entirely different beasts. Common differences between Windows Services & Console/Windows/Web applications shown in this image. Learn Windows Service Programming with C# in my Udemy course, here's 50% off discount.

Learn Windows Service Programming on Udemy Message Box

There are some major differences between a Windows Service executable and simple exe files. This difference is also present in Visual Studio Solution. 
Learn Windows Service Programming in C# .Net by enrolling in my Udemy course now, here's a discount coupon code. 


Let’s open a console application project in Visual Studio.
First of all I will press ‘Control + F5’
You will see the console application starts working right away
Now let’s go to a Windows Service project and try the same, when I press F5 the exe does not start to run.


Let me explain a couple short things first.

OnStart method of a windows service is being shown on the screen

Learn Windows Service Programming on Udemy Message Box


The OnStart method of the service is called by Windows when a user clicks “Start” link on the Service Control Manager
In our demo code, we are writing some text to the debugging console in this method
Let me press ‘Control+F5’ keyboard shortcut once again
Learn Windows Service Programming on Udemy Message Box
Boom! a message box says you can’t run a Windows Service from debugger baby.

This is the first difference

You can't just hit Ctrl+F5 to run a Windows Service Solution. 


Now let’s head back to the console application project
Inside the main method, I will place a breakpoint on a Console.WriteLine which prints Hello World!

And I will click ‘Debug’ menu and select the menu item ‘Start Debugging’
You see, the breakpoint is hit instantly

I’ll press F5 so that the application continues execution
Let’s try to do the same with the Windows Service project
I will place a on Debugger dot writeline
Go to ‘Debug’ menu and click ‘Start Debugging’

The same error shows up again

Learn Windows Service Programming on Udemy Message Box


This is difference number two


Finally, let us go to the output directory of our console application(any console application)

Double click HelloWorld.exe file
You see, the application starts working right away
Let’s go to the output directory of the service project and try to run it by double clicking the .exe file in a similar fashion
Oops! It won’t start dancing to your tunes
This is the third difference

We need to install the a Windows Service before we can run it

You will learn how to install a Windows Service in next section of my course. Please sign up here. 



MPORTANT: The source code for section 1 can be downloaded from my Windows Service Course .

Monday, February 4, 2019

What is socket programming?


Socket programming is, first of all, a means of boosting ego among the geeks and nerds who know it.
There are two types of programmers, one who has done socket programming and one who has not.

You may learn socket through the discounted links below; I teach two courses about socket programming on Udemy.

https://www.udemy.com/tcpip-socket-programming-for-coders-using-csharp-net/?couponCode=HALF

https://www.udemy.com/course/udpsocketprogramming/?referralCode=9A39D0BAEBF79DBDE6A3


Aside from this difference, the term "socket" is referred to a software-level construct that can be used to access a computer network. The term "access" encompasses two things:

  1. A computer reading data from the network sent by another computer
  2. A computer writes data to the network to send it to another computer

It appears simple when we send a message over a computer network using an app like Whatsapp. But there's a lot of complexity going on underneath it. Even the programmers must be shielded from the radiation of things like the OSI model and BGP. That's where sockets come in. Let me give you the simple definition of a socket.

Socket: 
A socket is a variable you can create in a high-level programming level, such as C#, Java, or C++. Once you have the socket, you can send and receive data using the computer network.
A socket is like an abstraction. It hides a lot of complexity under it and lets the coders write code that results in transmitting their data through WiFi, Ethernet, or any other means.
Sockets are often exposed through various APIs.

A few examples of socket APIs are given below, along with their mother languages.

  1. Java - java.net.*
  2. C# - System.Net.*
  3. C++ - socket.h

Windows provides an implementation of sockets through WinSock2 API. This is, in turn, used by runtimes like JVM(Java Virtual Machine) and .Net CLR(Common Language Runtime).
You don't need to learn C to work on this course.