Home » c# » c# – wtsapi32.dll was not found from windows service (LOCALSYSTEM)

c# – wtsapi32.dll was not found from windows service (LOCALSYSTEM)

Posted by: admin February 21, 2020 Leave a comment


GetModuleHandle("wtsapi32.dll") always equals to zero.

But in a standalone app it has value

What i’m doing wrong?

Please note that I’ve tried LoadLibrary() as well.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace WindowsService1
    public partial class Service1 : ServiceBase
        public Service1()

        private static extern IntPtr GetModuleHandle(string lpModuleName);

        protected override void OnStart(string[] args)
            eventLog1.WriteEntry("TEST.WS STARTED");

            eventLog1.WriteEntry("GetModuleHandle(\"Wtsapi32.dll\") = " + GetModuleHandle("wtsapi32.dll").ToString());


        protected override void OnStop()
How to&Answers: