WMI Python, writing remotely and retrieving env variables values

T

Thierry Lam

I'm using the WMI library for python and I was able to connect to
another computer on the network with the following line:

c = wmi.WMI(computer="the-network-computer", user="hello",
password="hello")

Is there a way to write information to a file on that computer?

How do I read environment variables, for example SystemDrive?

Thierry
 
T

Tim Golden

Thierry said:
I'm using the WMI library for python and I was able to connect to
another computer on the network with the following line:

c = wmi.WMI(computer="the-network-computer", user="hello",
password="hello")

Is there a way to write information to a file on that computer?

How do I read environment variables, for example SystemDrive?

Questions of this sort are really Win32 questions rather than Python
questions. That's not to say we can't help, but rather that you can
probably find an answer by going to a search engine of your choice
and typing in, say, "WMI SystemDrive". I did that, and the first hit
(from Google) was:

http://msdn2.microsoft.com/en-us/library/aa394239.aspx

which indicates that it's available from the Win32_OperatingSystem
WMI class. So, in Python:

<code>
import wmi
c = wmi.WMI () # optionally on another computer
for os in c.Win32_OperatingSystem ():
print os # show the whole thing
print os.SystemDrive # get only what you want

</code>

If you were after Environment Variables, then search again,
this time for "WMI Environment Variables". Third hit:

http://msdn2.microsoft.com/en-us/library/aa394143.aspx

pointing to the Win32_Environment class. And so on.

Your first question: can I write into a file? is a little
more tricky. As far as I know, there's no way even to
*create* a file with WMI, let alone write information into
it. It's not really a file-manipulation technology. You can
get hold of the name of a remote file and other of its
properties via the CIM_DataFile class, but you'd have
to translate that into an accessible UNC to be able to
access it.

TJG
 
T

Tim Williams

Questions of this sort are really Win32 questions rather than Python
questions. That's not to say we can't help, but rather that you can
probably find an answer by going to a search engine of your choice
and typing in, say, "WMI SystemDrive". I did that, and the first hit
(from Google) was:

http://msdn2.microsoft.com/en-us/library/aa394239.aspx

which indicates that it's available from the Win32_OperatingSystem
WMI class. So, in Python:

<code>
import wmi
c = wmi.WMI () # optionally on another computer
for os in c.Win32_OperatingSystem ():
print os # show the whole thing
print os.SystemDrive # get only what you want

</code>

If you were after Environment Variables, then search again,
this time for "WMI Environment Variables". Third hit:

http://msdn2.microsoft.com/en-us/library/aa394143.aspx

pointing to the Win32_Environment class. And so on.

Your first question: can I write into a file? is a little
more tricky. As far as I know, there's no way even to
*create* a file with WMI, let alone write information into
it. It's not really a file-manipulation technology. You can
get hold of the name of a remote file and other of its
properties via the CIM_DataFile class, but you'd have
to translate that into an accessible UNC to be able to
access it.

One possibility is to create a hidden share on the remote computer and
write to a file on it.

Shares ending in $ are hidden, the unc path would be \\machinename\share$

According to http://msdn2.microsoft.com/en-us/library/aa394594.aspx
you need the WMI Win32_Share class and the Create method.

HTH :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top