Sunday 5 August 2018

How To Allow Multiple Concurrent Remote Desktop Sessions in Windows 10


By default, multiple concurrent remote desktop sessions are not allowed on any of Windows desktop systems, including Windows 10. Here is what you will get when you are trying to log in 2 or more accounts simultaneously on a Windows 10 computer.

Remote Desktop Connection - 2015-12-23 23_18_19
Another user is signed in. If you continue, they will be disconnected. Do you want to continue?
If you click Yes, the current session will be disconnected to make the room for your connection. It doesn’t log off but rather switches to the account you logged in.
Just like on Windows 7, and 8, there are ways to work around it. And here is one of them.
Warning: before you start, create a system restore point or back up termsrv.dll file in c:\windows\system32 folder, just in case something goes wrong along the way.
First of all, download the zipped file below and extract the termsrv.dll file to a convenient location such as Desktop.
Note that the revised version of termsrv.dll is compatible on Windows 10 build 11085.
Then, stop Remote Desktop Service by running the following command on an elevated Command Prompt.
net stop termservice
Now, open File Explorer, navigator to c:\windows\system32 folder and locate the termsrv.dllfile. Since only TrustedInstaller account can get access to the file, you will need to change its ownership and give the full control permission to Administrators group before you can make changes to this DLL file.
Right-click termsrv.dll file, and choose Properties. Go to Security tab and click Advancedbutton.
termsrv.dll Properties
Then click Change link next to Owner: TrustedInstaller and select an account that has local administrator rights. Click OK and OK to close the Properties dialog box.
Advanced Security Settings for termsrv.dll
Right-click termsrv.dll file again, and choose Properties. Go to Security tab and give the local administrators group the full control rights.
Local admin group with full access
Local admin group with full access
Once it’s all set, copy the termsrv.dll you downloaded earlier into c:\windows\system32 folder to replace the default one that comes with the system.
Restart Remote Desktop Service by
net start termservice
And let’s give it a try to see if it works. As you can see from the screenshot below, I successfully log in 2 accounts to the same Windows 10 computer at the same time. Hooray.
Multiple Concurrent RDP sessions in Windows 10
If you are looking for doing the same thing on Windows 7 or Windows 8, check out the following posts.

Saturday 14 July 2018

Change Windows Password Policy - Windows 7/8/10

Using Local Security Policy.
Type Local Security Policy in the start menu search and press Enter. The LSP window will open. Now from the left pane, choose Password Policy from under Account Policies. Now on the right side six options will be listed.
img1
Details of each of those options are listed below.
Enforce Password history: This security setting determines the number of unique new passwords that have to be associated with a user account before an old password can be reused. The value must be between 0 and 24 passwords. This policy enables administrators to enhance security by ensuring that old passwords are not reused continually.
Maximum password age: This security setting determines the period of time (in days) that a password can be used before the system requires the user to change it. You can set passwords to expire after a number of days between 1 and 999, or you can specify that passwords never expire by setting the number of days to 0. If the maximum password age is between 1 and 999 days, the Minimum password age must be less than the maximum password age. If the maximum password age is set to 0, the minimum password age can be any value between 0 and 998 days.
Minimum password age: This security setting determines the period of time (in days) that a password must be used before the user can change it. You can set a value between 1 and 998 days, or you can allow changes immediately by setting the number of days to 0. The minimum password age must be less than the Maximum password age, unless the maximum password age is set to 0, indicating that passwords will never expire. If the maximum password age is set to 0, the minimum password age can be set to any value between 0 and 998.
Minimum password length: This security setting determines the least number of characters that a password for a user account may contain. You can set a value of between 1 and 14 characters, or you can establish that no password is required by setting the number of characters to 0.
Password must meet complexity requirements: This security setting determines whether passwords must meet complexity requirements. If this policy is enabled, passwords must meet the following minimum requirements:
– Not contain the user’s account name or parts of the user’s full name that exceed two consecutive characters
– Be at least six characters in length
– Contain characters from three of the following four categories:
  • English uppercase characters (A through Z)
  • English lowercase characters (a through z)
  • Base 10 digits (0 through 9)
  • Non-alphabetic characters (for example, !, $, #, %)
Complexity requirements are enforced when passwords are changed or created.

-------------------------------
From: https://www.thewindowsclub.com/customizing-the-password-policy-in-windows-7

Thursday 6 April 2017

SQL: Break single records into multiple records based on a value from one of the columns



declare @t table (name varchar(10), items varchar(10))
insert @t 
select 'AAA', '1' union all
select 'BBB', '2,' union all
select 'CCC', '3'

select t.name
       ,'1' + substring(items, 2, 1000) as Items
from   @t t
join   master..spt_values n
       on n.type = 'P'
       and n.number < convert(int, left(items,1))

Wednesday 18 May 2016

Open a WPF Window from WinForms

You will want to open the win-forms project you are currently working on. Then you will want to go to Solution Explorer and right-click the SOLUTION, not the project, go to "Add" and select "New Project".
In the add new Project go to Visual C# and then Windows in the tree on the left hand side. They should be located in the installed sub menu. In the main section you should see "WPF Custom Control Library" click on it and then name it what you would like and click ok.
Add a Window(WPF) control to the project, this window would be the WPF window that you want to open.
Then from the WinForm, open it like so:
var wpfwindow = new WPFWindow.Window1();
ElementHost.EnableModelessKeyboardInterop(wpfwindow);
wpfwindow.Show();
However ensure you have the following using statements:
using System; //Given 
using System.Windows.Forms; //Given
using System.Windows.Forms.Integration; //Not so Given.
You will need to add some references as well to make this work correctly, here is the list which should be all you need to add to a win-forms:
 PresentationCore
 PresentationFramework
 WindowsFormsIntegration
 System.Xaml
 YourWpfControlProjectName
You should add these to your Win-forms project using the reference picker in VS by right-clicking the reference folder in the solution explorer and adding a new reference. All of the references are located in the Framework tab, sans your WPF control which is in the solution tab.

Thursday 21 April 2016

Execute Stored Procedure On a Linked Server

What is the RPC and RPC Out option on a SQL Server linked-server?

Someone asked me this week – what are the relevance of the RPC and RPC Out settings on a linked server? Do you need both of them or only one of them set to True?
The documentation is online in this article, but it doesn’t clearly show examples or provide enough context, so I will try to do that here.http://technet.microsoft.com/en-us/library/ms186839(v=SQL.105).aspx

1. The first RPC setting is mainly for a legacy feature called Remote Server, which is documented here. http://msdn.microsoft.com/en-us/library/ms190187.aspx
You probably will not be using remote servers in SQL Server 2005 -SQL Server 2014 versions.
If you do happen to use “remote servers”, the RPC setting enables a certain security feature. If it is turned off, when the second server (the one receiving the login attempt from the first server to which the client connected) tries to validate the remote login, it fails with error
18482 “Could not connect to server ‘%.*ls’ because ‘%.*ls’ is not defined as a remote server. Verify that you have specified the correct server name. %.*ls.”
EXEC master.dbo.sp_serveroption @server=N’MYREMOTESERVER’, @optname=N’rpc’, @optvalue=N’true’ 
 
Kudos to my peer Ignacio Alonso Portillo for helping figure out this legacy option.


2. The RPC OUT  setting is very pertinent to linked servers on SQL Server 2005 -SQL Server 2014 versions.
Think about an RPC (Remote Procedure Call) as being a stored procedure being run remotely from Server 1 to linked Server 2 “myserver”.
There are various syntaxes, the first using 4 part naming servername.databasename.schemaname.procedurename , the second here using EXECUTE(databasename.schemaname.procedurename ) AT servername convention.
We can test with a simple procedure sp_helpdb that lives in master database, and will list out the databases and some of their key properties.
  • EXEC [myserver].master.dbo.sp_helpdb
  • EXEC (‘master.dbo.sp_helpdb’) AT myserver
These kind of remote stored procedure calls will be blocked unless RPC OUT is set to True.
Msg 7411, Level 16, State 1, Line 1  Server ‘myserver’ is not configured for RPC.

You can set it to True or False in the linked server’s properties (a right click menu in from the Linked Server Name in SQL Server Management Studio) .

Or you can set it by calling the stored procedure to set the server options like this test:
 – Test RPC OUT as false and get the error
EXEC master.dbo.sp_serveroption @server=N’MYSERVER’, @optname=N’rpc out’, @optvalue=N’false’
GO
EXEC [myserver].master.dbo.sp_helpdb
– Msg 7411, Level 16, State 1, Line 1
– Server ‘myserver’ is not configured for RPC.
GO
 — Test RPC OUT as true and see success
EXEC master.dbo.sp_serveroption @server=N’MYSERVER’, @optname=N’rpc out’, @optvalue=N’true’
GO
EXEC [myserver].master.dbo.sp_helpdb
– Command(s) completed successfully.

-------------------------------------------------------------------------------------------------------------------
This article is from:
https://blogs.msdn.microsoft.com/jason_howell/2014/10/01/what-is-the-rpc-and-rpc-out-option-on-a-sql-server-linked-server/

Monday 4 April 2016

Support for DB functions in Code first (Entity Framework 6.1)

Install-Package EntityFramework.CodeFirstStoreFunctions -Pre

After the package has been installed copy and paste the code snippet from below to your project. This code demonstrates how to enable store functions in Code First.
public class Customer
{
    public int Id { get; set; }
 
    public string Name { get; set; }
 
    public string ZipCode { get; set; }
}
 
public class MyContext : DbContext
{
    static MyContext()
    {
        Database.SetInitializer(new MyContextInitializer());
    }
 
    public DbSet<Customer> Customers { get; set; }
 
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Add(new FunctionsConvention<MyContext>("dbo"));
    }
 
    [DbFunction("MyContext", "CustomersByZipCode")]
    public IQueryable<Customer> CustomersByZipCode(string zipCode)
    {
        var zipCodeParameter = zipCode != null ?
            new ObjectParameter("ZipCode", zipCode) :
            new ObjectParameter("ZipCode", typeof(string));
 
        return ((IObjectContextAdapter)this).ObjectContext
            .CreateQuery<Customer>(
                string.Format("[{0}].{1}", GetType().Name,
                    "[CustomersByZipCode](@ZipCode)"), zipCodeParameter);
    }
 
    public ObjectResult<Customer> GetCustomersByName(string name)
    {
        var nameParameter = name != null ?
            new ObjectParameter("Name", name) :
            new ObjectParameter("Name", typeof(string));
 
        return ((IObjectContextAdapter)this).ObjectContext.
            ExecuteFunction<Customer>("GetCustomersByName", nameParameter);
    }
}
 
public class MyContextInitializer : DropCreateDatabaseAlways<MyContext>
{
    public override void InitializeDatabase(MyContext context)
    {
        base.InitializeDatabase(context);
 
        context.Database.ExecuteSqlCommand(
            "CREATE PROCEDURE [dbo].[GetCustomersByName] @Name nvarchar(max) AS " +
            "SELECT [Id], [Name], [ZipCode] " +
            "FROM [dbo].[Customers] " +
            "WHERE [Name] LIKE (@Name)");
 
        context.Database.ExecuteSqlCommand(
            "CREATE FUNCTION [dbo].[CustomersByZipCode](@ZipCode nchar(5)) " +
            "RETURNS TABLE " +
            "RETURN " +
            "SELECT [Id], [Name], [ZipCode] " +
            "FROM [dbo].[Customers] " +
            "WHERE [ZipCode] = @ZipCode");
    }
 
    protected override void Seed(MyContext context)
    {
        context.Customers.Add(new Customer {Name = "John", ZipCode = "98052"});
        context.Customers.Add(new Customer { Name = "Natasha", ZipCode = "98210" });
        context.Customers.Add(new Customer { Name = "Lin", ZipCode = "98052" });
        context.Customers.Add(new Customer { Name = "Josh", ZipCode = "90210" });
        context.Customers.Add(new Customer { Name = "Maria", ZipCode = "98074" });
        context.SaveChanges();
    }
}
 
class Program
{
    static void Main()
    {
        using (var ctx = new MyContext())
        {
            const string zipCode = "98052";
            var q = ctx.CustomersByZipCode(zipCode)
                .Where(c => c.Name.Length > 3);
            //Console.WriteLine(((ObjectQuery)q).ToTraceString());
            Console.WriteLine("TVF: CustomersByZipCode('{0}')", zipCode);
            foreach (var customer in q)
            {
                Console.WriteLine("Id: {0}, Name: {1}, ZipCode: {2}",
                    customer.Id, customer.Name, customer.ZipCode);
            }
 
            const string name = "Jo%";
            Console.WriteLine("\nStored procedure: GetCustomersByName '{0}'", name);
            foreach (var customer in ctx.GetCustomersByName(name))
            {
                Console.WriteLine("Id: {0}, Name: {1}, ZipCode: {2}",
                    customer.Id, customer.Name, customer.ZipCode);  
            }
        }
    }

------------------------------------------------------------------------------------------------------------------------------------
This article is from: http://blog.3d-logic.com/2014/04/09/support-for-store-functions-tvfs-and-stored-procs-in-entity-framework-6-1/

}