0

I am writing a program that needs to know whether or not it's in a virtual machine, a neat way I found was to check the system information in the cmd, however, I can't find a way to write in the cmd and read what the cmd replies.

I would like something that can write "WMIC COMPUTERSYSTEM GET MANUFACTURER" to the cmd and also check what the results are.

Some_dude
  • 139
  • 1
  • 8
  • Programmers don't call user commands. If a user can do it a program has a programming way of doing it. See http://timgolden.me.uk/python/wmi/tutorial.html – Noodles Apr 25 '19 at 01:49

1 Answers1

2

You want to use the subprocess module

import subprocess

proc = subprocess.Popen(
    [
        'WMIC',
        'COMPUTERSYSTEM',
        'GET',
        'MANUFACTURER'
    ],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE
)

out, err = proc.communicate()
print(out.decode().strip())
James
  • 32,991
  • 4
  • 47
  • 70