Python Forum
wmi returns no data from an other pc
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wmi returns no data from an other pc
#1
I 'm trying to secure my program using the pc 'c data (disk drives and processor).
I use this code:

import wmi
c = wmi.WMI()
for item in c.Win32_PhysicalMedia():
    hdd = hdd + str(item)
for s in c.Win32_Processor():
    hdd = hdd + str(s)
 print(hdd)
It works fine in my pc, but in my client 's pc it returns nothing!
And no error is raised.
Isn't this the correct way to check for disks' and processor 's data?
Reply
#2
(May-29-2017, 12:15 PM)panoss Wrote: It works fine in my pc

If your code is as you've posted, I seriously doubt that it works on your computer or any one else's. It looks like either you trying to have a definition which is neither defined, nor called. If that is not the case, you're indentation is wrong and you have an unnecessary "return". Also, why are you calling "c" twice?. Finally, you are redefining "hdd" so you will not see the one related to PhysicalMedia, only the one related to Processor, which is also the only one that will be returned.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
So...the correct code...is?
With wmi?
With something else?
Reply
#4
I see you've edited your original code, it is better to post your corrected code in a new reply, allowing other members to follow along.  As it stands, the indentation is wrong on your final "print(hdd)" and once corrected it will still only print the last definition of "hdd".

Quote:So...the correct code...is?

I'm not going to write the code for you, what fun is that for you  Smile .  I would suggest that you visit the website for wmi, read the prerequisites, the tutorial and check out their examples to see if wmi fits your needs.  It's a bit unclear when you say you want to "secure" your program and how you hope to accomplish that by gathering information about the hard drive and processor.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
sparkz, thanks for no help man, I appreciate this.
Reply
#6
You are overwriting hdd variable in the loop.
import wmi

hdd = []
c = wmi.WMI()
for item in c.Win32_PhysicalMedia():
   hdd.append(item)

#print(hdd)
print(hdd[0])
Output:
instance of Win32_PhysicalMedia                 {                                                      SerialNumber = "S1ATNEAD7xxxxxx     ";          Tag = "\\\\.\\PHYSICALDRIVE1";           };                                              
Quote:It works fine in my pc, but in my client 's pc it returns nothing!
Pc most have Pytnhon and wmi installed.
It still can be problem on some pc,
because this is accessing at a low level that can restricted.
Reply
#7
Thank you very much snippsat!!!
In two lines you answered me to the point!
THANK YOU!

(truth is I define the variable hdd before the loops, so forgive me for not posting this part, so the whole code is:)

hdd = ""
c = wmi.WMI()
for item in c.Win32_PhysicalMedia():
   hdd = hdd + str(item)
c = wmi.WMI()
for s in c.Win32_Processor():
   hdd = hdd + str(s)
print("hdd=", hdd)

(May-29-2017, 03:19 PM)snippsat Wrote: Pc most have Pytnhon and wmi installed.
Pcs with windows installed, have Python?
I thought only linux has Python 'out of the box'.
Reply
#8
(May-29-2017, 03:33 PM)panoss Wrote: Pcs with windows installed, have Python?
No,i do no not say that.
I mean is that Python and wmi most be installed on client pc(Windows) for it to work.
I don't now how you call that script on client pc either.
Reply
#9
Well, any ideas why it works on my pc and not on my client 's?
He also has win 7.
Reply
#10
No, he has Windows 10 64 bit.
Maybe wmi is not working on Win10 64 bit?

I have Win7 32bit, this is where the program is made.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020