Sunday, February 26, 2017

Start/Stop/Get details for Windows Services

If you are busy with multiple assignments and cater needs from multiple projects, or may be own a laptop with very little resources, you may want to manipulate windows services active on your laptop by Windows PowerShell.
For example, you may keep handy a .csv targeting one assignment, when you start working on that assignment simply stop other bulky windows services and activate the one you are interested in.

Some helpful commands:

#Get-Service | select-object  status  -unique
#Get-Service | where {$_.status -eq "Running"} 

# get all windows services running:
Get-Service | select Name, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, MachineName, ServiceName, ServiceHandle, Status, ServiceType, StartType, Site, Container, @{Name=’RequiredServices’;Expression={[string]::join(“;”, ($_.RequiredServices.Name))}} ,  @{Name=’DependentServices’;Expression={[string]::join(“;”, ($_.DependentServices.Name))}} ,    @{Name=’ServicesDependedOn’;Expression={[string]::join(“;”, ($_.ServicesDependedOn.Name))}} | Export-Csv c:\gm\servs.csv;

#After analysis of output say, you want to start 3 of them and stop 2, but leave one untouched still be in the csv, create a csv something like:
#(consider the dependencies listed in output above to decide order)

import-csv "C:\gm\input.csv" | foreach-object { write-host $_.Name; if([bool]::Parse($_.Start)){ Start-Service $_.Name}; if([bool]::Parse($_.Stop)){ Stop-Service $_.Name};}

sample commands at :

But if you are more into security and want control over what is happening over your laptop above mentioned might not be sufficient.
You might need to to deep dive into processes like :

Get-Process | Export-csv "c:\gm\pr.csv"

Friday, February 17, 2017

LLBLGenPro Lite with PostgreSQL and .Net

In this example I used:

LLBLGenPro Lite Version 5.1 (5.1.2) RTM - LITE  Build Date 24-Jan-2017, Licensee: LITE user
Npgsql -Version 3.1.10
CsvHelper -Version 2.16.3
log4net -Version 2.0.7
Visual Studio 2012 with Package Manager Console Host Version 2.8.60318.667

Few tips:

1. Generic part of adapter source code and DB Specific part ( Projects LLBLGenProLite51DBSpecific & LLBLGenProLite51Generic) were created following "LLBLGen Pro Runtime Framework v5.1 Documentation" documentation at is the saved project of LLBLGenPro.exe which may be used to regenerate the classes later, if need be.

2. The only tweak I had to do to generate the source code (on the top the instructions as mentioned in online help guide "LLBLGen Pro Runtime Framework v5.1 Documentation):
a) Put Npgsql.dll in C:\Program Files (x86)\Solutions Design\LLBLGen Pro v5.1\
b) Some of you might also have to put DbProviderFactories entry under LLBLGenPro_x86.exe.config.
Otherwise you may get error:
Exception details:
Message: Failed to find or load the registered .Net Framework Data Provider.
Source: System.Data
Stack trace: 
   at System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow)
   at SD.LLBLGen.Pro.DBDriverCore.DBDriverBase.GetDbProviderFactory()
   at SD.LLBLGen.Pro.DBDriverCore.ConnectionDataBase.get_FactoryName()
   at SD.LLBLGen.Pro.Gui.Controls.WizardPages.MetaDataRetrievalWizard_Step_ConnectionData.<LoadDriverAndConnectionControl>b__16_1()
   at SD.LLBLGen.Pro.Gui.Classes.ApplicationIdleDispatcher.PerformWork()
   at SD.LLBLGen.Pro.Gui.Classes.ApplicationIdleDispatcherSingleton.Application_Idle(Object sender, EventArgs e)
   at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at SD.LLBLGen.Pro.Gui.Classes.GuiController.PerformAddMetaDataFromDatabaseAction()
   at SD.LLBLGen.Pro.Gui.Controls.ProjectExplorer._mainBarManager_ItemClick(Object sender, ItemClickEventArgs e)
   at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarButtonItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarItemLink.OnLinkClick()
   at DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
   at DevExpress.XtraBars.Controls.CustomLinksControl.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.XtraBars.Controls.CustomControl.WndProc(Message& msg)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Inner exception: <null>

3. In the Console project I created, I had to make DbProviderFactories entry in app.config in addition to installing Npgsql.

For other details, you may refer to comments in in sample code.

Working sample code is available at

This post is related to

Thursday, February 16, 2017

Symbiotic_Data_Provider_PostgreSql_x64 with PostgreSQL and .Net

In this example I used:
Symbiotic_x64 -Version
Symbiotic_Data_Provider_PostgreSql_x64 -Version 2.0.0
Npgsql -Version 3.1.10
CsvHelper -Version 2.16.3
log4net -Version 2.0.7
test_table.cs using Symbiotic Code Generator

Working sample code is available at

Wednesday, February 15, 2017

Uni.ORM with PostgreSQL and .Net

Uni.ORM with PostgreSQL and .Net

In this example I used:

Npgsql -Version 3.1.10

CsvHelper -Version 2.16.3

log4net -Version 2.0.7

Uni.Extensions -Version 1.1.8 (  if you use Uni.Extensions 1.1.9, along with Uni.ORM 1.4.4, it will give error Field not found: 'Uni.Extensions.UniExtensions.stringType'.)

Uni.ORM -Version 1.4.4

Working sample code is available at

Probably you need to be careful about the active sessions with this ORM:

I got below mentioned error, if used more than 20 execution cycles with above said custom utility

Npgsql.NpgsqlException was unhandled
  Message=The connection pool has been exhausted, either raise MaxPoolSize (currently 100) or Timeout (currently 15 seconds)
       at Npgsql.ConnectorPool.WaitForTask(Task task, NpgsqlTimeout timeout)
       at Npgsql.ConnectorPool.Allocate(NpgsqlConnection conn, NpgsqlTimeout timeout)
       at Npgsql.NpgsqlConnection.OpenInternal()
       at Npgsql.NpgsqlConnection.Open()
       at Uni.Orm.UniOrm.NewConnection()
       at Uni.Orm.UniOrm.ExecuteScalar(CommandType commandType, String schema, String package, String commandText, Options options, Object[] args)
       at Uni.Orm.UniOrm.ExecuteScalar[T](CommandType commandType, String schema, String package, String commandText, Options options, Object[] args)
       at Uni.Orm.UniOrm.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
       at CallSite.Target(Closure , CallSite , Object , String , String , String , Options , Object[] )
       at Uni.Orm.UniOrm.Count(String schema, String table, String where, Options options, Object[] args)
       at UniORM144.UniORM144Test.Main(String[] args) in c:\891\orm\orm\UniORM144\Program.cs:line 114
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

This post is related to

Tuesday, February 14, 2017

i-nercya EntityLite with PostgreSQL and .Net

In this example I used:
Npgsql -Version 3.1.10
EntityLite -Version 1.12.1
DataLayer.cs  from
CsvHelper -Version 2.16.3
log4net -Version 2.0.7

Working sample code is available at

This is related to

Generate datalayer for i-nercya EntityLite 1.12.1 with PostgreSQL and .Net

I tried to install EntityLite 1.12.1 and Npgsql 3.1.9 for this. [ in .Net 4.5 targeted console app] But ended up with error:
Error 2 Running transformation: System.ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.
   at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
   at Microsoft.VisualStudio.TextTemplatingC12866A572DD11EF15A986313BFF838D4E56BEC87A6A4FDE0CFFA72BBCA7470835F0A9B363151B6BF2A47F79BBBA8A3506666063B8252F87E39E5DFC255B20C6.GeneratedTextTransformation.DataLayerGeneration.get_Factory()
   at Microsoft.VisualStudio.TextTemplatingC12866A572DD11EF15A986313BFF838D4E56BEC87A6A4FDE0CFFA72BBCA7470835F0A9B363151B6BF2A47F79BBBA8A3506666063B8252F87E39E5DFC255B20C6.GeneratedTextTransformation.DataLayerGeneration.OpenConnection()
   at Microsoft.VisualStudio.TextTemplatingC12866A572DD11EF15A986313BFF838D4E56BEC87A6A4FDE0CFFA72BBCA7470835F0A9B363151B6BF2A47F79BBBA8A3506666063B8252F87E39E5DFC255B20C6.GeneratedTextTransformation.DataLayerGeneration.SetViewsByEntity()
   at Microsoft.VisualStudio.TextTemplatingC12866A572DD11EF15A986313BFF838D4E56BEC87A6A4FDE0CFFA72BBCA7470835F0A9B363151B6BF2A47F79BBBA8A3506666063B8252F87E39E5DFC255B20C6.GeneratedTextTransformation.DataLayerGeneration.Initialize()
   at Microsoft.VisualStudio.TextTemplatingC12866A572DD11EF15A986313BFF838D4E56BEC87A6A4FDE0CFFA72BBCA7470835F0A9B363151B6BF2A47F79BBBA8A3506666063B8252F87E39E5DFC255B20C6.GeneratedTextTransformation.Render(DataLayerGeneration generation)
   at Microsoft.VisualStudio.TextTemplatingC12866A572DD11EF15A986313BFF838D4E56BEC87A6A4FDE0CFFA72BBCA7470835F0A9B363151B6BF2A47F79BBBA8A3506666063B8252F87E39E5DFC255B20C6.GeneratedTextTransformation.TransformText() C:\891\i_nercya_EntityLite_1121_generate\ 1 1 i_nercya_EntityLite_1121_generate

In case of other ORM's similar error was resolved by DbProviderFactories entry in app.config of the same project. But in case of  EntityLite 1.12.1, I had to put   Npgsql 3.1.9 dll in gac and make DbProviderFactories entry in devenv.exe.config.

But still my datalayer was not generated. Now I got the error:

Error 2 Running transformation: System.InvalidCastException: Specified cast is not valid.
at Microsoft.VisualStudio.TextTemplating7F3203888EE90D7643162256DEB8BCA2F8341541B1C705EDCF3B6214F0C0F85E31AB17E0A0D48688C13A80D08802FC9F390D40D33018DFC341958870E4AB73A1.GeneratedTextTransformation.DataLayerGeneration.GetSchema(String tableOrView, DbConnection cn)
at Microsoft.VisualStudio.TextTemplating7F3203888EE90D7643162256DEB8BCA2F8341541B1C705EDCF3B6214F0C0F85E31AB17E0A0D48688C13A80D08802FC9F390D40D33018DFC341958870E4AB73A1.GeneratedTextTransformation.DataLayerGeneration.GetSchemaUnion(EntitySetting entitySetting, DbConnection cn)
at Microsoft.VisualStudio.TextTemplating7F3203888EE90D7643162256DEB8BCA2F8341541B1C705EDCF3B6214F0C0F85E31AB17E0A0D48688C13A80D08802FC9F390D40D33018DFC341958870E4AB73A1.GeneratedTextTransformation.DataLayerGeneration.SetFieldsMetadataByEntity()
at Microsoft.VisualStudio.TextTemplating7F3203888EE90D7643162256DEB8BCA2F8341541B1C705EDCF3B6214F0C0F85E31AB17E0A0D48688C13A80D08802FC9F390D40D33018DFC341958870E4AB73A1.GeneratedTextTransformation.DataLayerGeneration.Initialize()
at Microsoft.VisualStudio.TextTemplating7F3203888EE90D7643162256DEB8BCA2F8341541B1C705EDCF3B6214F0C0F85E31AB17E0A0D48688C13A80D08802FC9F390D40D33018DFC341958870E4AB73A1.GeneratedTextTransformation.Render(DataLayerGeneration generation)
at Microsoft.VisualStudio.TextTemplating7F3203888EE90D7643162256DEB8BCA2F8341541B1C705EDCF3B6214F0C0F85E31AB17E0A0D48688C13A80D08802FC9F390D40D33018DFC341958870E4AB73A1.GeneratedTextTransformation.TransformText() C:\891\inercyaEntityLite1121\ 1 1 inercyaEntityLite1121

EntityLite 1.12.1 was released back in September 15, 2015 and targeting .NETFramework 3.5 Client. This could have been the culprit for Specified cast is not valid. So I removed previously installed dll's in GAC and DbProviderFactories entries in devenv.exe.config. If you follow step by step actions mentioned below, you may avoid such errors I faced as mentioned above:

0. create a database ,a table as mentioned in comment section of

1. Create a project targeting .Net 3.5:

2. In this project if you try to install npgsql anything above 2.2.7, you get error like as mentioned below:

PM> Install-Package Npgsql -Version 3.0.0-beta0001 -Pre
Installing 'Npgsql 3.0.0-beta0001'.
Successfully installed 'Npgsql 3.0.0-beta0001'.
Adding 'Npgsql 3.0.0-beta0001' to i_nercya_EntityLite_1121_generate.
Uninstalling 'Npgsql 3.0.0-beta0001'.
Successfully uninstalled 'Npgsql 3.0.0-beta0001'.
Install failed. Rolling back...
Install-Package : Could not install package 'Npgsql 3.0.0-beta0001'. You are trying to install this package into a project that targets '.NETFramework,Version=v3.5', but the package does not
contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.At line:1 char:1
+ Install-Package Npgsql -Version 3.0.0-beta0001 -Pre
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

So you have to go for Npgsql 2.2.7

PM> Install-Package Npgsql -Version 2.2.7
Installing 'Npgsql 2.2.7'.
Successfully installed 'Npgsql 2.2.7'.
Adding 'Npgsql 2.2.7' to i_nercya_EntityLite_1121_generate.
Successfully added 'Npgsql 2.2.7' to i_nercya_EntityLite_1121_generate.

3. Now go for EntityLite 1.12.1 ( dependencies are resolved here):

PM> install-Package EntityLite -Version 1.12.1
Attempting to resolve dependency 'EntityLite.Core (= 1.12.1)'.
Attempting to resolve dependency 'NLog (= 2.1.0)'.
Attempting to resolve dependency 'Microsoft.SqlServer.Types (= 10.50.1600.1)'.
Installing 'NLog 2.1.0'.
Successfully installed 'NLog 2.1.0'.
Installing 'Microsoft.SqlServer.Types 10.50.1600.1'.
Successfully installed 'Microsoft.SqlServer.Types 10.50.1600.1'.
Installing 'EntityLite.Core 1.12.1'.
Successfully installed 'EntityLite.Core 1.12.1'.
Installing 'EntityLite 1.12.1'.
Successfully installed 'EntityLite 1.12.1'.
Adding 'NLog 2.1.0' to i_nercya_EntityLite_1121_generate.
Successfully added 'NLog 2.1.0' to i_nercya_EntityLite_1121_generate.
Adding 'Microsoft.SqlServer.Types 10.50.1600.1' to i_nercya_EntityLite_1121_generate.
Successfully added 'Microsoft.SqlServer.Types 10.50.1600.1' to i_nercya_EntityLite_1121_generate.
Adding 'EntityLite.Core 1.12.1' to i_nercya_EntityLite_1121_generate.
Successfully added 'EntityLite.Core 1.12.1' to i_nercya_EntityLite_1121_generate.
Adding 'EntityLite 1.12.1' to i_nercya_EntityLite_1121_generate.
Successfully added 'EntityLite 1.12.1' to i_nercya_EntityLite_1121_generate.

4. Retrieve the full name of dll's:
Code for retrieving name is in

5. Install these two dll's in gac:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>gacutil -i "C:\YourProjectPath\packages\Npgsql.2.2.7\lib\net35\Mono.Security.dll"
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>gacutil -i "C:\YourProjectPath\packages\Npgsql.2.2.7\lib\net35\Npgsql.dll"

6.1 In C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe.config ( or the respective config of devenv.exe, as per your installation, you may get path for devenv.exe by viewing the properties of VS shortcut.) make DbProviderFactories entry like:
<remove invariant="Npgsql" />
 <add name="PostgreSQL Data Provider"
           description=".Net Data Provider for PostgreSQL"
           type="Npgsql.NpgsqlFactory, Npgsql, Version=, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />

Just make sure you use correct assembly fullname as retrieved in step 4
6.2 Restart Visual studio

7. Copy paste code similar to as mentioned in the attached code's Right click on this tt file and click "Run Custom Tool".
Save DataLayer.cs generated for later use in a separate folder for future use.
8.1 Close Visual studio.
8.2 Remove DbProviderFactories customization you did in 6.1
8.3 Remve the two dll's as in step 5, from gac
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>Gacutil -u "Npgsql, Version=, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>Gacutil -u "Mono.Security, Version=, Culture=neutral, PublicKeyToken=0738eb9f132ed756"

 So, generated in step 7 is your output of this activity.

Full code available at:

Sunday, February 12, 2017

LINQ to PostgreSQL with PostgreSQL and .Net

n this example I used,
(in order)
Npgsql -Version 3.1.10
linq2db.PostgreSQL -Version 1.7.6
log4net -Version 2.0.7
CsvHelper -Version 2.16.3

Working sample code is available at

This post is related to :

Saturday, February 11, 2017

MicroLite with PostgreSQL and .Net

In this example I used,

MicroLite -Version 6.3.2
Npgsql -Version 3.1.10
log4net -Version 2.0.7
CsvHelper -Version 2.16.3

Working sample code is available at

This post is linked to

Friday, February 10, 2017

FluentData with PostgreSQL 9.6 and .Net 4.5

In this example I used,

Npgsql -Version 3.1.10
log4net -Version 2.0.7
CsvHelper -Version 2.16.3
FluentData -Version

Working sample code is available at:

This post is related to

Thursday, February 9, 2017

NHibernate with PostgreSQL and .Net

In this example I used,

NHibernate -Version
Npgsql -Version 3.1.10
log4net -Version 2.0.7
CsvHelper -Version 2.16.3

1. Since I am using Sequence for Id, its worth noting that even though insert doesn't fire query to insert record immediately, but retrieves sequence.
2. Also, transaction will not be able to control rollback for sequences.
3. Actual SQL queries fired are available for review only in debug mode: setings.LogSqlInConsole = true;

For full version of code please visit:

This post is related to

Wednesday, February 8, 2017

EntityFramework6.Npgsql with with PostgreSQL 9.6 and .Net 4.5

In this example I used,

Npgsql -Version 3.1.10
log4net -Version 2.0.7
CsvHelper -Version 2.16.3
EntityFramework6.Npgsql -Version 3.1.1

Two things worth noting here,
1. If I would have installed directly EntityFramework6.Npgsql -Version 3.1.1, it resolve dependency to  Npgsql -Version 3.1.0, which didn't work in my case, so I chose to go with Npgsql -Version 3.1.10

2. I had to make manual entry for DbProviderFactories in app.config to get it work.

If you get stuck somewhere, delete your bin, obj and packages folder . Then try the sample code mentioned below again.

Working sample code is available at:

Tuesday, February 7, 2017

OrmLite with PostgreSQL and .Net

In this example I used:
Npgsql -Version 3.1.10
ServiceStack.OrmLite.PostgreSQL -Version 4.5.6
CsvHelper -Version 2.16.3
log4net -Version 2.0.7

Sample code below gives an idea how to use OrmLite with PostgreSQL and .Net. PostgreSQL server is installed on localhost in the example below:
Visual Studio Project along with full version of code:

This post is related to

Thursday, February 2, 2017

Does Anti-virus software slow down your machine ?

If you are about to disable your Anti-virus and other security related plugins/software on your machine because it slows down your machine, this post is for you. is the The Browser Exploitation Framework(BeEF) available with default installation of Kali Linux. A black hat hacker could refer it's hook.js JavaScript file in any page, which if opened on victim's browser, hacker has the full control on victim's browser to execute commands beyond imagination e.g. getting all the browser cookies, extensions information, control web cam, pop-ups to enter passwords while browsing legitimate websites and so on. For complete list refer to

How BeEF tool works:
 It keeps on hitting BeEF server from victim's client browser to get updated version of hook.js (interval defined by Config yaml at server) and execute it, when server side Utility of BeEF server attacks, say attacker run command give me webcam, a different version of hook.js is fetched to victim in next periodic call from browser to BeEF server: in this example. And victim client post results to attacker as per new hook.js given to it.

 You may verify such actions on client machine using F12 ( Developer Tool) > Network tab in most of the browsers like chrome,IE, Mozilla etc or using fiddler.

How to defeat this tool:

1. If this hook.js periodic hit is blocked on victim's browser and notify victim in popup, its a temporary fix. The best place for this stuff to do could have been a utility running on client machine/browser code itself/extension to browser.

2. You may use unhook code in your browser extension very similar to ( The tool use the code mentioned to stop watching (unhook) the victim.
3. Another method could be blocking the Attacker's domain altogether as done by (Vegan Chrome extension)

4. "utility running on client machine" called anti-virus have updated definition to let the system aware of these type of attacks. For example
Windows default anti-virus is aware of many attack vectors BeEF tool uses like Exploit: JS/Aimesu.A, Trojan: Win32/Spursint.F!cl , Exploit: JS/ShellCode.gen

Bottom line is you must not disable your Anti-virus software, just because it slows down your machine. Above all, you must not open malicious websites which may have been using hooks from plenty of such exploitation tools. Might be, the tool they are using is custom made and no anti-virus software is yet aware of attack vectors and how it works!! Typically, websites which offer you pirated content cost you much more than you could think of.

When it comes to government organizations and financial institutes, there is a reason they block everything else than trusted web addresses and domains. Even the most sophisticated technologies may be vulnerable to Cross-Site Scripting (XSS) attacks and attacker could inject just hooks in supposedly secured websites.