Click here for important information about

Python - get computer name

Dell Precision m65 notebook
February 11, 2010 at 23:38:51
Specs: Windows XP
I am trying to return the host name for a computer given a directory path.

I know how to return the computer that my script is executing on,

print os.getenv('COMPUTERNAME')

but I want to determine the name of a computer give a path like "Z:\"

Any ideas?


See More: Python - get computer name

February 13, 2010 at 14:08:20
since no one else has responded...
i don't know python well enough to know if there's a "built-in"
command for that, but you can always fall back to piping:

net use > test

or: net use | find " $drivelettr:" > test
then you have to open/read/parse test and get the data, which should not be hard for Python to do.

Report •

February 15, 2010 at 13:45:54
If you have the pywin32 modules, you can use WNetOpenEnum and WNetEnumResource to enumerate your network disks. There's even a C example on MS Support.

Report •
Related Solutions

Ask Question