Enabling and Disabling Windows Services automagically.

I got tired of enabling/disabling VMware services every time, so I wrote a little PowerShell script for this:

Change services mode to manual initialization and start them:

foreach ($service in $services) {
    gwmi win32_service|?{$_.name -like $service}|%{$_.changestartmode("Manual")}
    gwmi win32_service|?{$_.name -like $service}|%{$_.startservice()}

Stop services and disable their initialization settings:

foreach ($service in $services) {
    gwmi win32_service|?{$_.name -like $service}|%{$_.stopservice()}
    gwmi win32_service|?{$_.name -like $service}|%{$_.changestartmode("Disabled")}

Attention: You need to run the scripts in administrator mode.


EDIT: Lately I couldn’t  launch VMWARE on Windows 10 anymore, due to Device Guard being active. What I do to disable it (temporarily):

1) Open Local Group Policy Editor and change:
   1.1) Computer configuration -> Administrative Templates -> System -> Device Guard -> Turn On Virtualization Base Security (on the right side) from "Not Configured" to Disabled.
2) Open Powershell (as admin) and run:
   2.1) bcdedit /set hypervisorlaunchtype off


ANSI colors in Windows terminal

In case you are wondering how to get your ANSI colored strings into windows terminal, the following snippet might help you (from C):

#include <stdio.h>
#include <windows.h>


int main(int argc, char** argv) {
  DWORD dwMode = 0;

  GetConsoleMode(hOut, &dwMode);

  SetConsoleMode(hOut, dwMode);

  printf("\x1b[101;93m Testing\x1b[0m\n");
  return 0;

More info on escape sequences can be found on https://en.wikipedia.org/wiki/ANSI_escape_code