473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Executing a remote process via WMI in Win32.

I can connect to a machine remotely with no problems but I'm having trouble
trying to create a process remotely. Initially this was a perl and VB
script which I'm converting to python. Its entire purpose is to start a
process remotely. The problem initially was that the perl script could not
'see' any mapped drives as it would alway return 'access denied' so I'm
trying to not only rewrite the script but fix this problem and my idea was
to connect with the Administrator account.

Now the following script sort of works. I can get the set of running
processes but it dies out when I try to create one.

## being ##
import win32com.client
wmi = win32com.client.Dispatch('wbemscripting.swbemlocat or')
remote_machine =
wmi.ConnectServer('<MACHINE>','root\\cimv2',Admini strator','<PASSWORD>')

process = remote_machine.InstancesOf("Win32_Process")
for proc in process:
size = int(proc.WorkingSetSize)/1024
print proc.Caption, size,"kb"
# test to see if we can 'see' what's on a mapped drive.
# doesn't seem to go.
process.Create("cmd.exe /K dir w:\\")
## END ##

The script will print out all the processes fine but once it get's to
'Create' it dies out with and error message I don't understand.

NOTEPAD.EXE 80 kb
Traceback (most recent call last):
File "C:\Documents and Settings\scody\test.py", line 14, in ?
process.Create("cmd.exe /K dir w:\\")
File "C:\Python23\lib\site-packages\win32com\client\dynamic.py", line 460,
in
__getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: InstancesOf.Create

The process method should only have the one parameter as defined at:
http://userpages.umbc.edu/~kbradl1/w...f.html#process

I just tried using the 'Terminate' process but that didn't work either....

So I'm going to assume that the WMI objects are not instantiated as python
classes (hence why the methods are not working). Am I completely off base
here (meaning it is a syntax problem)?

Any suggestions or pointers to the right direction would be creately
appriciated...

--
Sean
(ps. remove -spam to email me).
Jul 18 '05 #1
1 27418
"Sean" <nu*******@tfh.ca> wrote in message news:<be**********@canopus.cc.umanitoba.ca>...
I can connect to a machine remotely with no problems but I'm having trouble
trying to create a process remotely. Initially this was a perl and VB
script which I'm converting to python. Its entire purpose is to start a
process remotely. The problem initially was that the perl script could not
'see' any mapped drives as it would alway return 'access denied' so I'm
trying to not only rewrite the script but fix this problem and my idea was
to connect with the Administrator account.

Now the following script sort of works. I can get the set of running
processes but it dies out when I try to create one.

## being ##
import win32com.client
wmi = win32com.client.Dispatch('wbemscripting.swbemlocat or')
remote_machine =
wmi.ConnectServer('<MACHINE>','root\\cimv2',Admini strator','<PASSWORD>')

process = remote_machine.InstancesOf("Win32_Process")
for proc in process:
size = int(proc.WorkingSetSize)/1024
print proc.Caption, size,"kb"
# test to see if we can 'see' what's on a mapped drive.
# doesn't seem to go.
process.Create("cmd.exe /K dir w:\\")
## END ##

The script will print out all the processes fine but once it get's to
'Create' it dies out with and error message I don't understand.

NOTEPAD.EXE 80 kb
Traceback (most recent call last):
File "C:\Documents and Settings\scody\test.py", line 14, in ?
process.Create("cmd.exe /K dir w:\\")
File "C:\Python23\lib\site-packages\win32com\client\dynamic.py", line 460,
in
__getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: InstancesOf.Create

The process method should only have the one parameter as defined at:
http://userpages.umbc.edu/~kbradl1/w...f.html#process

I just tried using the 'Terminate' process but that didn't work either....

So I'm going to assume that the WMI objects are not instantiated as python
classes (hence why the methods are not working). Am I completely off base
here (meaning it is a syntax problem)?

Any suggestions or pointers to the right direction would be creately
appriciated...


Hi Sean I´m now work in a module that create several kind of methods
to manage process using wmi take one example:

I´m use ActiveState Python 2.2.1 firts you have it´s that python know
of existencie of WMI for instance you must use COMMakepy utility now
Python *knows* about the 'WMI Scripting' typelibrary.

Note:this part of script its tested in windows 2000 and its functional
except in windows 2000 with SP2 that failed and I don´t know why

Example create process:
(After Use Makepy)
import win32com.client
wmi = win32com.client.Dispatch('wbemscripting.swbemlocat or')
remote_machine =
wmi.ConnectServer('<MACHINE>','root\\cimv2',Admini strator','<PASSWORD>')
strProcess=("cmd.exe /K & dir w:\\") #this is very important you must
put &
objprocess = remote_machine.Get('Win32_Process')
Method = objProcess.Methods_('Create')
InParameters = Method.InParameters.SpawnInstance_()
InParameters.Properties_.Item('CommandLine').Value =strProcess
try:
OutParameters = objProcess.ExecMethod_ ('Create',InParameters)
ReturnValue = OutParameters.Properties_.Item('ReturnValue').Valu e
ProcessID = OutParameters.Properties_.Item('ProcessId').Value
except pythoncom.com_error, (hr,msg,exc,arg):
ExceptionHandler(hr,msg,exc,arg)

def ExceptionHandler (self,hr,msg,exc,arg):
print 'COM call failed: %s' % msg
if exc is not None:
wcode, source, text, helpFile, helpID, scode = exc
print 'Error source:',source
print text
print 'See also: %s (id=%d)' % (helpFile,helpID)
Example kill process:

strPid="'yourpid'" # In this form else not work
sql="SELECT * FROM Win32_Process WHERE ProcessId=%s" %strPid
objProc=objprocess.ExecQuery(sql)
if objProc.Count==0:
print "Pid strPid Not Found"
else:
for process in objProc:
strmeth = process.Methods_('Terminate')
strparms=strmeth.InParameters
strparms.Properties_('Reason').Value=0
process.ExecMethod_('Terminate',strparms)

Sorry Sean for my bad Enghlis I hope help you
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark Elley | last post by:
I am using the following code to start a process on a networked XP machine. This all works really well but the process created is invisible to the user (only visible in the Task Manager -...
0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool including SourceOffSite, SourceAnyWhere and VSS Remoting This article makes a detailed...
15
by: Chakkaradeep | last post by:
Hi all, i have written a Service,now i want to execute another application (for eg;calc.exe) in the service....how will i perform it??... i tried using this.... /**************Executing a...
3
by: blakecaraway | last post by:
Hi there. I have a C# console application that extracts data to flat files. Some of my business partners begin consuming these extract files before I've had a chance to write the newest ones (I...
0
by: Peter Strøiman | last post by:
Hi I have a windows 2003 test server. I installed a web application on it, including the debug symbol files. I also installed the remote debugger from the Visual Studio 2003 DVD. My client is...
0
by: =?Utf-8?B?Vmlua2k=?= | last post by:
hello Everyone, I created this batch file that executes the taskKill command to kill the process on the remote server. When I call this batch file from the console applications, it runs fine and...
1
shrek123
by: shrek123 | last post by:
I want to kill some process on remote machine which is on some other domain. I am using Win32::OLE GetObject to do that. But I am getting following error Error1: When my remote machine is on...
3
by: somuchh8 | last post by:
Hi, I'm having a lot of trouble with the Win32::Spawn module in perl. Here is my situation, I have a Win32::Spawn call which looks like this: my $success = undef; my $cmdline =...
3
by: jim3371 | last post by:
Using wxPython, I'm looking to build a GUI app for a daemon-based app, on Win32 platform, how would I go about executing the daemon app so it stays in the background when the Py app is running?...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.