This blog is a knowledge base...where I clip cool tricks and urls

UDP Client Server

//Create an instance of UdpClient.
UdpClient udpClient = new UdpClient(serverName, SAMPLEUDPPORT);
Byte[] inputToBeSent =
new Byte[256];
inputToBeSent = System.Text.Encoding.ASCII.GetBytes(whatEver.ToCharArray());
IPHostEntry remoteHostEntry = Dns.GetHostByName(serverName);
IPEndPoint remoteIpEndPoint =
new IPEndPoint(remoteHostEntry.AddressList[0], SAMPLEUDPPORT);
int nBytesSent = udpClient.Send(inputToBeSent, inputToBeSent.Length);
Byte[] received =
new Byte[512];
received = udpClient.Receive(
ref remoteIpEndPoint);
String dataReceived = System.Text.Encoding.ASCII.GetString(received);
Console.WriteLine(dataReceived);
udpClient.Close();
 blog it

UDP packet - Ask DNS

clipped from www.codeproject.com
Test Application
 blog it

MIB Overview

 blog it

SNMP Library Free Project (Mono)

I started this project because of the lack of resources for the older, but still highly
used SNMP protocol. The SNMP protocol still remains the de facto standard when it comes
to network monitoring and management.

 blog it

IDataProvider - Implement Provider Model C#

In the CreateDataAdapter method you will have to do a couple of things to create an instance of a specific data adapter. First you will need to initialize the appropriate provider based on the information in the configuration file. The InitProvider method is responsible for this and will be shown in the next section. After the appropriate DataProvider class is loaded the CreateDataAdapter method on that specific provider will be called. This is where the SqlDataAdapter or the OleDbDataAdapter or the OracleDataAdapter is created.
public static IDbDataAdapter CreateDataAdapter(
 string SQL, string ConnectString)
{
  IDbDataAdapter da;

  // Make sure provider is created
  InitProvider();

  da = DataProvider.CreateDataAdapter();

  da.SelectCommand = CreateCommand(SQL, 
   ConnectString, false);

  return da;
}

In Visual Basic

 blog it

tcp

clipped from en.wikipedia.org

A TCP segment consists of two sections:


  • header

  • data


The TCP header[2] consists of 11 fields, of which only 10 are required. The eleventh field is optional (pink background in table) and aptly named "options".


TCP Header
Bit offsetBits 0–34–78–1516–31
0Source portDestination port
32Sequence number
64Acknowledgment number
96Data offsetReservedCWRECEURGACKPSHRSTSYNFINWindow
128ChecksumUrgent pointer
160Options (optional)
160/192+ 
Data

  • Source port (16 bits) – identifies the sending port
 blog it

TCP diagram

clipped from freebie.fatpipe.org
http://freebie.fatpipe.org/~mjb/Drawings/TCP_Header.png
 blog it

MSI parameter driven

clipped from blogs.msdn.com

Adding msi parameters in Visual Studio Setup Project



I can’t find how and where to add the parameter list of the msi.

I had to modify a setup project of which creates an msi for an application.

During modification I had to add an extra parameter that should be given to the msi during installation.

While I searched I found only how to read the parameters supplied from command line using Context.Parameters.

But I can’t find at any place where to specify the parameters those can be supplied with msi. Finally I found it and so I am writing here as it may be useful to others.

In property Pages of Install, in the option CustomEvents, we can specify the arguments.

 

For example if for our msi, we have to add 2 parameters INSTLOG & X

Then in the CustomEvents, we have to specify it as:

            /INSTLOG=”[INSTLOG]” /X=”[X]”

 blog it

Simple SNMP

From Richard Blum
clipped from www.java2s.com
// Send sysName SNMP request
      response = conn.get("get", argv[0], argv[1]"1.3.6.1.2.1.1.5.0");
      if (response[0== 0xff)
      {
         Console.WriteLine("No response from {0}", argv[0]);
         return;
      }

      // If response, get the community name and MIB lengths
      commlength = Convert.ToInt16(response[6]);
      miblength = Convert.ToInt16(response[23 + commlength]);

      // Extract the MIB data from the SNMP response
      datatype = Convert.ToInt16(response[24 + commlength + miblength]);
      datalength = Convert.ToInt16(response[25 + commlength + miblength]);
      datastart = 26 + commlength + miblength;
      output = Encoding.ASCII.GetString(response, datastart, datalength);
      Console.WriteLine("  sysName - Datatype: {0}, Value: {1}",
              datatype, output);

      // Send a sysLocation SNMP request
      response = conn.get("get", argv[0], argv[1]"1.3.6.1.2.1.1.6.0");
      if (response[0== 0xff)
      {
         Console.WriteLine("No response from {0}", argv[0]);
         return;
      }
 blog it

SNMP C#

snmputil get ict-main-s.msroot.student.paisley.ac.uk public system.sysContact.0
To do this programmatically, proceed as follows:
RFC1157.Mgmt mib = new RFC1157.Mgmt();
ManagerSession sess=new ManagerSession(localhost,public);
ManagerItem mi=new ManagerItem(sess,mib.OID(mgmt.mib-2.system.sysContact.0));
Console.WriteLine(mi.Value.ToString());

An SNMP Library for .NET Framework
Mib.dll is a C# class library that handles the translation of MIB object identifiers (OID) sch as 1.3.6.1.2.1.1.4.0 to readable names such as system.sysContact.0. It also collects the help strings from the system mib files (on windows systems these are in the system folder, usually c:\windows\system32.) It contains one namespace, RFC1157.
 blog it

C# Wmi change start mode of service

clipped from www.thescripts.com

public void RestartService(string ServiceName)
{
ManagementPath myPath = new ManagementPath();
ManagementBaseObject outParams = null;
myPath.Server = System.Environment.MachineName;
myPath.NamespacePath = @"root\CIMV2";
myPath.RelativePath = "Win32_Service.Name='" + ServiceName + "'";
using (ManagementObject service = new ManagementObject(myPath))
{
// Set startmode to Automatic (auto start at boot )
ManagementBaseObject inputArgs =
service.GetMethodParameters("ChangeStartMode");
inputArgs["startmode"] = "Automatic";
outParams = service.InvokeMethod("ChangeStartMode", inputArgs, null);
// return check ignored for brevity
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret == 0)
 blog it

WMI Security Rights

clipped from msdn2.microsoft.com
Win32_Service Class

The
Win32_ServiceWMI class represents a service on a computer system running Windows. A service application conforms to the interface rules of the Service Control Manager (SCM), and can be started by a user automatically at system start through the Services control panel utility, or by an application that uses the service functions included in the Windows API. Services can start when there are no users logged on to the computer.

A user connecting from a remote computer must have the SC_MANAGER_CONNECT privilege enabled to be able to enumerate this class. For more information, see Service Security and Access Rights.

 blog it

WMI namespaces

 blog it

Impersonate User in Windows Forms

clipped from www.codeproject.com
// create new identity using new primary token

WindowsIdentity newId = new WindowsIdentity
(pDuplicateTokenHandle);
WindowsImpersonationContext impersonatedUser =
newId.Impersonate();
// check the identity after impersonation

sResult += "After impersonation: " +
WindowsIdentity.GetCurrent().Name + "\r\n";
MessageBox.Show(this, sResult, "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return impersonatedUser;
 blog it

Remoting Sample

clipped from www.eggheadcafe.com
In simplistic terms, remoting in this scenario happens by proxy.  The developer must create an interface class containing all properties and methods minus the actual code that will reside in each.  The interface class must exist on both the client and server.  Remember, this is only the public interface definition.  The client will utilize the interface class to instantiate a proxy to the object locally.  Via the proxy, anytime a property is referenced with a Get or Set statement or a method is called, .NET handles the communication to and from the client to the server over an http channel and the port designated by the developer.
 blog it

Remoting Overview C#

clipped from www.eggheadcafe.com
How does it work?
In simplistic terms, remoting in this scenario happens by proxy.  The developer must create an interface class containing all properties and methods minus the actual code that will reside in each.  The interface class must exist on both the client and server.  Remember, this is only the public interface definition.  The client will utilize the interface class to instantiate a proxy to the object locally.  Via the proxy, anytime a property is referenced with a Get or Set statement or a method is called, .NET handles the communication to and from the client to the server over an http channel and the port designated by the developer.
 blog it

GAC Util - Best practices

clipped from blogs.msdn.com

You should use Windows Installer to install your application.  Starting with version 2.0, Windows Installer has built-in functionality to install assemblies to the GAC - the MsiAssembly and MsiAssemblyName tables in particular.  You can refer to this MSDN document for an overview of how to add assemblies to an MSI package and this MSDN document for a description of how to add Win32 assemblies to an MSI package.  Therefore you should use this built-in functionality to handle GAC installation and uninstallation for you.

 blog it

Register DLL to GAC - programmatically

clipped from www.codeguru.com

The .NET Configuration Utility requires administrative privileges to add an assembly to the GAC, and the GACUTIL is available only when the Framework SDK is installed. A machine with the .NET Framework but without the SDK won't have GACUTIL. Based on the advice in the MSDN article, a developer would have to make every potential user of a VSTO application into a local administrator (at least temporarily) or get the Framework SDK installed so GACUTIL can be called from an MSI package, which runs under the privileges of an administrator. Thankfully, the C++ developer has a third option: programmatically modifying the GAC with the Fusion APIs.

typedef HRESULT (__stdcall *CreateAsmCache)(IAssemblyCache
**ppAsmCache, DWORD dwReserved);
HMODULE g_FusionDll;
CreateAsmCache g_pfnCreateAssemblyCache;
 blog it

Google Docs

clipped from www.youtube.com
Google Docs in Plain English

You can share this video in three ways:



 blog it

Db Mirroring

clipped from www.microsoft.com
Figure 2
 blog it

How do users think?

Screenshot
Screenshot
Screenshot

1. Don’t make users think

How do users think?

 blog it

Blog Archive