Hello,
I am facing with a Windows environment where I have an executable. This exe needs to be
I tried to do this using WMI, by importing winim/com. Below are some of my snippets.
import wmi, time
ip = 'xx.xx.xx.xxx'
username = "user"
password = "password!"
SW_SHOWNORMAL = 1
from socket import *
print "Establishing connection to %s" %ip
c = wmi.WMI(ip, user=username, password=password)
process_startup = c.Win32_ProcessStartup.new()
process_startup.ShowWindow = SW_SHOWNORMAL
process_id, result = c.Win32_Process.Create(CommandLine="C:\User\Administrator\Desktop\runIOX_auto.bat",ProcessStartupInformation=process_startup)
if result == 0:
print "Process started successfully: %d" % process_id
else:
raise RuntimeError, "Problem creating process: %d" % result
( (https://stackoverflow.com/questions/29659469/python-using-wmi-to-start-executable-remotely)
Although this is just one example, I have not been able to port this to wmi/nim.
2)
Same.
3)
I found this snippet:
$file = Get-WmiObject -Query "Select * from CIM_Datafile Where Name='c:\\Desktop\\a.txt'" -ComputerName 10.14.34.81 -Credential administrator
if($file)
{
$file.delete()|out-null
}
But I fail to translate this to nim, I get 'unsupported method detele [COMError].
import winim/com
var wmi = GetObject("winmgmts://.")
let file = wmi.ExecQuery("Select * from CIM_Datafile Where Name='c:\\Desktop\\Ana\\hello.txt'")
file.delete()
Could anyone give me some hints?
Haha, I thought of clarifying a bit when typing the question since it might sound like a virus. So not offended, I am actually happy that you ask. I am trying to maintain a couple (about 50-70) of systems and pushing drivers, updates, custom applications for some users, etc every now and then. Normally I use RDP, psexec, depending on the number of systems and how difficult the task is.
Since it's summer, I am trying to pick up a new language. I have been trying to get into nim for a while, and forcing my self this way: rewriting some of my steps in nim. I have been able to create some smaller applications now, and following tutorials. But I have not been able to understand how to do this with WMI.
So I thought of trying to do it this way.
The deleting part is not 100% necessary, but after installing for example Visio on a remote host, I'd like to be able to remove the installer. Does that clear up some of your questions? :)
Please do not hesitate to ask if you have more questions.
A bit more context: I manage about 65 systems on two locations, where I sometimes need to install (or remove) an executable from all the systems. In other situations I want to install an application on 2-3 remote hosts (RDP). I have been doing this for about 5 years now, where I started with 5 systems on one location and 2 on the other. At first I did everything manually, since SSH or SMB is not a possibility. Nowadays, I try to do everything with psexec (I have never been able to completely master WMI) and sometimes RDP and still learn some python and nim on the side. That's why I figured to kill two animals(?) with one stone: incorporate wmi in nim. But I got stuck during this process since I could not find any documentation how to do so, apart from 2 examples which did not tell me that much.
Hopefully that clears all suspicious. Again, I'd be happy to answer extra questions. But I am not writing a virus by any means :)
I think you might be better off filing an issue on the winim GitHub.
There are some examples under /khchen/winim/examples/com that might provide inspiration?
I've done this several times. I find just copying the files to a common place like \\device\c$\dir using the standard library (copyFile/etc..) and deleting in similar fashion works well. For running the file, I use psexec copied to the local directory and executed as a process. For us, it was the most reliable across different versions. Some are so simple that a batch file works. But with Nim one could make a type of "makefile" application that can be reused with different inputs given (I've never actually done that though).
The last use was a large Windows update that our patch management system would timeout trying to apply. We've never used WMI for copying/running programs though. Not to say it's not possible...