Logoff interactive users in Windows from a service

You could use following P/Invoke calls to achieve this. Below sample works only with Admin Rights [DllImport(“wtsapi32.dll”, SetLastError = true)] static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, bool bWait); [DllImport(“Wtsapi32.dll”)] static extern bool WTSQuerySessionInformation( System.IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out System.IntPtr ppBuffer, out uint pBytesReturned); [DllImport(“wtsapi32.dll”, SetLastError = true)] static extern IntPtr WTSOpenServer([MarshalAs(UnmanagedType.LPStr)] String … Read more

Modifying the “Path to executable” of a windows service

There is also this approach seen on SuperUser which uses the sc command line instead of modifying the registry: sc config <service name> binPath= <binary path> Note: the space after binPath= is important. You can also query the current configuration using: sc qc <service name> This displays output similar to: [SC] QueryServiceConfig SUCCESS SERVICE_NAME: ServiceName … Read more

Redirect stdout+stderr on a C# Windows service

You can do this via PInvoke to SetStdHandle: [DllImport(“Kernel32.dll”, SetLastError = true) ] public static extern int SetStdHandle(int device, IntPtr handle); // in your service, dispose on shutdown.. FileStream filestream; StreamWriter streamwriter; void Redirect() { int status; IntPtr handle; filestream = new FileStream(“logfile.txt”, FileMode.Create); streamwriter = new StreamWriter(filestream); streamwriter.AutoFlush = true; Console.SetOut(streamwriter); Console.SetError(streamwriter); handle = … Read more

What are the specific differences between .msi and setup.exe file?

An MSI is a Windows Installer database. Windows Installer (a service installed with Windows) uses this to install software on your system (i.e. copy files, set registry values, etc…). A setup.exe may either be a bootstrapper or a non-msi installer. A non-msi installer will extract the installation resources from itself and manage their installation directly. … Read more