I have been studying for exams recently and the textbook I was reading told me that the command (in CMD) for getting a computers serial number is as follows - (as one method of lowering piracy).
wmic bios get serialnumber
I decided to try this for myself using python, where I wanted to get the serial number of my own computer, I created a batch file (.bat) and recorded the serial number to a txt file which I thought I could then read off in python, this created more questions if anything... here is the code I currently have:
SerialNumber.bat (new to bat files by the way)
SET num=wmic bios get serialnumber
%num% > serial.txt
What serial.txt looks like (modified slightly to not give away my serial number)
Readtxt.py
# Trying to read in two different ways
with open("serial.txt", "r") as file:
print(file.read())
lines = []
for line in open("serial.txt"):
lines.append(line)
print(lines)
which outputs: (not showing full image again)
the questions are:
- How would I store the serial number as some string?
- Why does each different method I use to read provide different outputs?
Thanks for any answers :)