As per MSDN, In C++/C time(NULL) function returns the time elapsed in seconds since midnight, January 1, 1970, which is Coordinated Universal Time (UTC) according to the system clock - is the current time, precisely. To achieve the same in C#, code should look something similar like as below:
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Sunday, April 10, 2011
Friday, October 8, 2010
Saturday, September 25, 2010
Windows Installer Information | C#
When you are working with Installer applications. At times, you may have to find properties of underlying components inside Installer (.msi) packages. MSI does maintain a database of all the properties of underlying items.
Windowsinstaller can be used to find this information. Usage of the WindowInstaller has already been published in another post.
The below C# method helps you to find a property of an underlying component:
The above method takes two parameters sMsiFilePath - indicates the exact path of the .msi file and sProperty is the name of the property(e.g. Version) to find and returns the the property value as a string.
e.g. GetMSIProperty("C:\Test\Setup.msi", "DisplayVersion"); // to make a call to the above method
e.g. GetMSIProperty("C:\Test\Setup.msi", "DisplayVersion"); // to make a call to the above method
Friday, September 24, 2010
x32 Or x64? | C#
Developers more often, want to know the processor type (32 bit or 64 bit) to make some programming decisions. It usually happens, when you write applications for 64 bit machine. Registry entries are also added on different paths for 32 bit and 64 bit Applications.
When you install a 64 bit application, the entry in the registry will be made under the below path: And a 32 bit application will make an entry under the following path: The below C# code detects the processor type of the machine, where your application is running:
In the above code, PROCESSOR_ARCHITECTURE is the environment variable, which carries the information of the system type. Environment is the class (part of the System namespace) to expand the environment variable to extract the machine architecture.
Monday, September 20, 2010
Make Your Bitmaps Transparent | C#
Scenario #1: Comparing with Visual C++, It is easy to make a bitmap (.jpeg, .bmp and .png) in C#. Code to make a bitmap back ground transparent on a picture control:
Two things here, picBox (Picture Box control instance) back(ground) color is setting to Transparent. And Making the BmpOne (Bitmap object) transparent.
Scenario #2: Code to make the ImageList images transparent:
iconsList (Of type ImageList) contains two icons here. This iconsList can be leveraged to set images on ListView controls, Radio Buttons and Labels etc.
Thursday, September 9, 2010
Is patch'ed? | C#
Patches are usually being applied to all the products/softwares to come around various issues that the end users do face over the period of time while using any software. These are also called with other names as Hot or Quick fixes, which are normally being identified by a number prefixed with KB (e.g KB2508987).
While creating setup (or InstallShield) applications, It is usually a case of detecting whether or not a specific patch is installed?. Knowing that, the installer can prompt the user to add it first before moving on with the installation. The below is a C# code that will detect whether a particular patch has been applied for particular product.
Follow the below 3 easy steps:
1) Add msi.dll to the project.

While creating setup (or InstallShield) applications, It is usually a case of detecting whether or not a specific patch is installed?. Knowing that, the installer can prompt the user to add it first before moving on with the installation. The below is a C# code that will detect whether a particular patch has been applied for particular product.
Follow the below 3 easy steps:
1) Add msi.dll to the project.

2) Add WindowsInstaller namespace.
using WindowsInstaller;
3) Add the below code to detect the patch.
Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer", true);
if (type != null)
{
WindowsInstaller.Installer installer = (WindowsInstaller.Installer) Activator.CreateInstance(type);
if (installer != null)
{
WindowsInstaller.StringList patches = installer.get_Patches("{049DB35D-4A8B-4DFF-A9EF-D7142186BDFD}");
foreach (string patch in patches)
{
if (patch == "{011FF98E-2A9E-1AEE-D2DE-F2135786CDEF}")
{
// found
break;
}
}
}
}
Wednesday, September 1, 2010
Registry Access | C#
Registry class (which is part of the namespace Microsoft.Win32) in .NET exposes CurrentUser, Local Machine etc.. keys by default and so it is not needed to mention the keys beginning with the following:
For instance use the the below code to access the keys from the path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\System Center Essentials\2.0\Setup\Components\Server-Version
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("\\SOFTWARE\\Microsoft\\System Center Essentials\\2.0\\Setup\\Components");
if (registryKey != null)
{
string serverVersion = Convert.ToString(registryKey.GetValue("Server-Version"));
}
