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:

$services="vmauthd*","VMnetDHCP*","vmware*","VMUSBArbService*"
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:

$services="vmauthd*","VMnetDHCP*","vmware*","VMUSBArbService*"
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.

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>

#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
# define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif

int main(int argc, char** argv) {
  HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  DWORD dwMode = 0;

  GetConsoleMode(hOut, &dwMode);
  dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;

  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