Impersonate Windows User

public class Impersonate
        [DllImport("advapi32.dll", SetLastError = true)]
        private static extern int LogonUser(string lpszUsername, string lpszDomain, string lpszPassword,
                                            int dwLogonType, int dwLogonProvider, out int phToken);

        private static extern int FormatMessage(int dwFlags, string lpSource, int dwMessageId, int dwLanguageId,
                                                StringBuilder lpBuffer, int nSize, string[] Arguments);

        private const int LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
        private const int LOGON32_PROVIDER_DEFAULT = 0;
        private const int FORMAT_MESSAGE_FROM_SYSTEM = 0x1000;

        private static WindowsImpersonationContext winImpersonationContext = null;

        public static void ImpersonateUser(string domain, string userName, string password)

            //Benutzer einloggen
            int userToken = 0;

            bool loggedOn = (LogonUser(userName, domain, password, LOGON32_LOGON_NETWORK_CLEARTEXT,
                                        LOGON32_PROVIDER_DEFAULT, out userToken) != 0);

            if (loggedOn == false)
                int apiError = Marshal.GetLastWin32Error();
                StringBuilder errorMessage = new StringBuilder(1024);
                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, null, apiError, 0, errorMessage, 1024, null);
                throw new Exception(errorMessage.ToString());

            WindowsIdentity identity = new WindowsIdentity((IntPtr)userToken);
            winImpersonationContext = identity.Impersonate();


        public static void UndoImpersonation()
            if (winImpersonationContext != null)

Call impersonate

Impersonate.ImpersonateUser("domain", "user name", "password");
            //Your Code as the new User
            DirectoryInfo _dirInfo = new DirectoryInfo(@"file path");
            FileInfo[] _files = FileExtension.GetFilesByExtensions(_dirInfo, ".xls", ".xlsx").ToArray();

Leave a comment

Filed under Technical Links

Microsoft Build 2017

  1. #MSBuild Day 1 Keynote: Satya Nadella, Scott Guthrie, and Harry Shum show us how software continues to transform the world in remarkable ways, with developers at the center of it:

[00:02] Satya Nadella Opening Statements
[07:39] Microsoft mission
[14:02] Intelligent Cloud and Intelligent Edge
[19:00] Sam George, Sandvik Windows IoT demonstration
[23:00] Azure IoT Edge Introduction
[27:52] Andrea Carl, AI for Workplace Safety demonstration
[37:59] The Edge and our Devices
[41:27] Laura Jones, Intelligent Meetings
[51:46] Satya Nadella Closing Statements
[52:50] Haiyan Zhang and Emma Lawton, Development and Inspiration
[56:41] Scott Guthrie Opening Statements
[1:00:20] Scott Hanselman Azure Management Stack demonstration
[1:01:59] Azure Cloud Shell Announcement
[1:04:25] Azure Management Mobile App on Android and iOS Announcement
[1:09:50] Visual Studio for Mac General Availability Announcement
[1:21:13] PostgreSQL as a Service, MySQL as a Service Announcement
[1:22:26] Azure Cosmos DB Introduction
[1:27:20] Rimma Nehme, Azure Cosmos DB demonstration
[1:39:43] Maria Naggaga, Cloud Native application development demonstration
[1:46:50] Scott Guthrie, Serverless Computing
[1:49:01] Visual Studio 2017 support for Azure Function and Logic Apps Announcement
[1:52:02] Scott Guthrie, Azure Stack
[1:56:59] Julia White Azure and Azure Stack demonstration
[2:01:05] Scott Guthrie and Abhay Parasnis, Adobe, SaaS on Azure
[2:11:51] Microsoft AppSource
[2:13:13] Harry Shum Opening Statements
[2:18:18] Cognitive Services – Video Index and Cognitive Services Labs Cognitive Services Announcement
[2:19:40] Cognitive Services, Custom Vision, LUIS, Speech, Search and Decision Services Announcement
[2:23:00] Cornelia Carapcea Custom Vision demonstration
[2:27:07] Bot Framework and Adaptive Cards demonstration
[2:33:27] Yina Arenas Presentation Translator Add-in demonstration
[2:37:44] HP and Intel Cortana Device Announcement
[2:39:12] Yina Arenas Tact and Microsoft Graph demonstration
[2:43:52] Harry Shum Closing Statements


  1. #MSBuild Day 2 Keynote: Terry Myerson, Joe Belfiore, and Alex Kipman show us how software continues to transform the world in remarkable ways, with developers at the center of it:

[01:21] Terry Myerson Opening Statements
[03:40] Focus on creativity
[05:36] Windows 10 Fall Creators Update Announcement
[06:21] Windows Story Remix Announcement
[08:49] Lorraine Bardeen demonstrates Story Remix
[20:54] Joe Belfiore Talks about features and technologies behind Story Remix
[23:22] Microsoft Fluent Design System
[31:36] Windows and Microsoft Graph
[33:34] Windows PCs Loves Devices via Microsoft Graph
[45:51] Cloud-powered Clipboard Announcement
[49:33] Abolade Gbadegesin Project Rome Architect
[52:02] Moldering Legacy Application demonstration
[53:02] .NET Standard 2.0 for UWP Announcement
[54:51] XAML Standard 1.0 Announcement
[1:02:03] Project Rome SDK For iOS Announcement
[1:07:48] Terry Myerson and Continuous Delivery to Windows Store
[1:08:18] Full UWP Capabilities in Visual Studio Mobile Center Announcement
[1:10:03] iTunes coming to Windows Store Announcement
[1:10:42] SAP Digital Boardroom coming to Windows Store Announcement
[1:11:26] Andy Mott, Autodesk’s Sketchbook as a UWP Application
[1:13:31] Autodesk’s Stingray
[1:14:38] Windows 10 as Development Box
[1:15:06] Ubuntu via Windows Store Announcement
[1:15:46] SUSE and Fedora via Windows Store Announcement
[1:16:24] Xamarin Live Player demonstration
[1:19:29] Windows Narrator Dev Mode demonstration
[1:21:38] Terry Myerson and Mixed Reality
[1:25:35] Alex Kipman on Mixed Reality
[1:34:59] Motion Controllers for Windows Mixed Reality Announcement
[1:37:30] Acer and Motion Controllers Holiday Package Announcement
[1:39:50] Cirque du Soleil HoloLens demonstration
[1:49:25] Acer and HP Mixed Reality Dev Kit now available via Microsoft Store Announcement


  1. #MSBuild Day 3 Keynote: Discussion and Demos around Visual Studio 2017, C#, Visual Studio Code, and debugging demos:

[C9L30] Build Day 3 Keynote: The Business of Code
[C9L27] Visual Studio Mobile Center
[C9L25] TypeScript with Anders Hejlsberg
[C9L24] Visual Studio for Mac and Xamarin Live Player
[C9L23] Microsoft Graph
[C9L22] Microsoft Fluent Design System
[C9L20] SQL Unplugged
[T6098-R3] Jig.Space: Using 3D game technology in progressive web apps with BabylonJS
[T6095-R3] Sketchable and Surface Dial Integration
[T6076] Microsoft Security Risk Detection – Artificial Intelligence Powered Risk Detection
[T6958] Diversity and Accessibility as Technical Differentiators
[B8077] Security testing in the cloud, at scale using Microsoft Security Risk Detection
[T6996] Workspace utilization with Azure IoT
[T6988] Guide Dogs: Improving speech recognition on iOS to help the blind navigate
[T6097-R1] Lessons learned developing for mixed reality
[T6108] Using Microsoft Graph to connect to Office 365 data
[T6069] Simplified app development with plug-ins for Xamarin and Windows
[T6068] Securely sign-in your customers with Azure Active Directory B2C
[T6055] Never break the build with live unit testing
[T6052] Virtual and mixed reality apps with C#
[T6032] Getting started with Aurelia and ASP.NET Core
[T6006-R2] Angular and TypeScript
[T6003] A day in the life of an Azure serverless developer
[B8104] The future of C#
[B8097] What’s new with the Microsoft Bot Framework
[B8083] The future of Visual Studio
[B8050] Entity Framework Core 2.0: data, mobile, server, IoT, and more
[B8038] Deep learning with Microsoft Cognitive Toolkit
[B8036] Supercharge your debugging in Visual Studio 2017
[B8035] XAML custom controls for UWP: Start to finish
[B8008] Big data workloads with Azure Blob Storage
[B8002] Introducing Adaptive Cards

Leave a comment

Filed under Technical Links

Arduino project

MCP23017 and ESP8266

Leave a comment

Filed under Technical Links

web.config Redirect http to https

		<rule name="Redirect to HTTPS" stopProcessing="true">
			<match url="(.*)" />
				<add input="{HTTPS}" pattern="^OFF$" />
			<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />

Leave a comment

Filed under Technical Links

Natural language toolkit

You should look into the following libraries:

Depending on what you need to get done, a mix between these two can get you a long way.

Also for an introduction into Natural Language Processing, I would recommend this book (free to read online).

Leave a comment

Filed under Technical Links

Sql Server linked server

EXEC sp_addlinkedserver 'myserver', '', 'SQLNCLI', 'xx.xx.xx.xx,8080'

EXEC sp_addlinkedsrvlogin 'myserver', 'FALSE', NULL, 'user', 'pwd'

Leave a comment

Filed under Technical Links

crontab solutions

make sure to enable write for the .sh file

chmod +x test.php

copy in /usr/local/sbin

crontab -l

crontab -e

Leave a comment

Filed under Technical Links