Reputation: 79
Im trying to connect to remote windows machine, using win32_process to count number of files on desktop via command line of remote machine and get output.
I use WMI,
c=wmi.WMI('machine name',user='username',password='password')
mycommand = c.Win32_Process.Create(CommandLine='cmd.exe /c dir /a:d /s /b "C:\User\Desktop" | find /c ":\"')
Is there any way how to get output of this command via python (number of files)
upd. Maybe you know ANY way how to connect to remote machine, ran any command via command line (or powershell) and get output? (except paramiko, it is not working for my server).
Upvotes: 0
Views: 788
Reputation: 36
There is no clear way to read the output from remote Windows machine through wmi. You can try to mount the drive and read the content. Change localhost with the remote machine IP. here D$ refers to D directory I want to mount
import os
filename = 'example.log'
for root, dirnames, filenames in
os.walk('\\\\localhost\\D$\\Testdir\\'):
for file in filenames:
if filename in file :
match=os.path.join(root, filename)
f = open(match).read()
print(f)
Can check more example on below URL:
https://ashishpython.blogspot.com/2013/11/how-to-read-files-of-computer-drive-in.html
Upvotes: 1