By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,995 Members | 1,217 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,995 IT Pros & Developers. It's quick & easy.

WMI Python, writing remotely and retrieving env variables values

P: n/a
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

Jan 12 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Thierry Lam wrote:
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

Jan 13 '07 #2

P: n/a
On 13 Jan 2007 02:01:11 -0800, Tim Golden <tj******@gmail.comwrote:
Thierry Lam wrote:
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.
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 :)
Jan 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.