Re: Using Python with COM to communicate with proprietary Windows software

2005-09-21 Thread Paul Casteels
Joakim Persson wrote:
> On Tue, 13 Sep 2005 10:15:18 +0200, Thomas Heller <[EMAIL PROTECTED]>
> wrote:
> 
> 
>>>This _shouldn't_ be too difficult -- I know which methods must be
>>>implemented (basically just some kind of event handling to deal with
>>>randomly arriving log points, should be implemented as "onMsg()" on my
>>>COM server side, and some other similar methods), but I don't really
>>>know how. I have tried doing simple COM servers using win32com, but is
>>>it equally possible to implement such a simple thing in comtypes? I
>>>didn't find any server side examples in comtypes, but perhaps there is
>>>a way?
>>
>>There is not yet any server support in comtypes, but it will be added.
>>In the meantime you could use the ctypes.com package that is included in
>>ctypes itself, there are even samples.
>>
>>Thomas
> 
> 
> Thank you, I will try that. Right now I've been trying to use win32com
> for the server creation, but I haven't been successful yet (have not
> explored it that much yet though). 
> 
> I have registered a COM server (it should only implement two methods,
> "onMsg()" and "onNotify()", which should print whatever is sent to
> them directly to stdout), but I need to create an interface which is
> not an IDispatch interface and pass it on to the proprietary COM
> server. This connection is needed so that the proprietary COM server
> knows where to send the log and control data. 
> 
> Registering the COM object in the registry works fine, but how do I
> make it look like a custom interface from the proprietary COM servers
> point of view? Oh well, I will look at it some more tomorrow and
> hopefully come up with a solution...
> 
Hi Joakim,

  This server I wrote for the Palm Desktop with win32com, it creates a none 
IDispatch COMserver.
  Maybe it can be of help. I am interested in what you find out on this.

Regards,

Paul Casteels


import pythoncom
import pywintypes
import winerror
import types,time,string
import win32com
import win32ui,win32con
import rfc822
import XmlWriter

from win32com.server.exception import COMException
from win32com.server.util import wrap
from win32com.client import gencache,Dispatch,constants
from win32com import universal



# The following 3 lines may need tweaking for the particular server
# Candidates are pythoncom.Missing and pythoncom.Empty
defaultNamedOptArg=pythoncom.Missing
defaultNamedNotOptArg=pythoncom.Missing
defaultUnnamedArg=pythoncom.Missing

palmApp = 0
outfileName = r'c:\Documents And Settings\paul\My Documents\Python\PDA\cal2.xml'

universal.RegisterInterfaces('{C9B354D8-4A1C-11D5-81D2-00C04FA03755}', 0, 1, 0, 
["IDesktopAddin"])
universal.RegisterInterfaces('{C9B354D8-4A1C-11D5-81D2-00C04FA03755}', 0, 1, 0, 
["IDesktopCommand"])

def d2s(inDate):
 return rfc822.mktime_tz(rfc822.parsedate_tz(inDate))
def s2d(inDate):
 return time.asctime(time.localtime(inDate))



class DesktopCommand:
 global palmApp

 _public_methods_ = ['OnCommand']
 _com_interfaces_ = ['IDesktopCommand']

 def OnCommand(self):
 print "Hello, command"
 print palmApp
 win32ui.MessageBox("PC-Hello","PC-Title",win32con.MB_OK )

class DesktopAddin:
 _public_methods_ = ['GetFrameworkVersion',
 'OnInitialize',
 'OnUninitialize',
 'ShowAboutBox',
 'ShowProperties']
 _reg_progid_ = "PythonPalm.DesktopAddin"
 _reg_clsid_ = "{6F36C1D4-571C-484E-B47B-61297761B3D1}"
 _com_interfaces_ = ['IDesktopAddin']

 def GetFrameworkVersion(self, plVersion=defaultNamedNotOptArg):
 """method GetFrameworkVersion"""
 return 2

 def OnInitialize(self, pUnk=defaultNamedNotOptArg, 
dwCookie=defaultNamedNotOptArg, \
  dwDesktopVersion=defaultNamedNotOptArg, 
lParam=defaultNamedNotOptArg, \
  pbSuccess=defaultNamedNotOptArg):
 """method OnInitialize"""
 global palmApp
 self.cookie = dwCookie
 palmApp = Dispatch(pUnk)
 # add a command
 self.cmd = wrap(DesktopCommand())
 addinMgr = palmApp.AddinManager
 cmdId = 0
 cmdId = addinMgr.AddAddinCommand(self.cookie, "AddressCommand", \
 self.cmd, cmdId)
 cmdDesc = "&Address Command"
#& vbTab & _
#  "Displays a list of 10 contacts." & vbTab & _
#  "Displays 10 conta

Re: logging as root using python script

2005-04-08 Thread Paul Casteels
Raghul wrote:
Hi
   Is it possible to login as a root in linux using python script?
What I need is when I execute a script it should login as root and
execute my command and logout from root to my existing account. IS is
possible?
Thanx in advance.
Hi,
 You can compile the small .c program and setuid it's executable.
 Change the path to your .py script of course.
#include 
#include 
int main(int argc,char **argv)
{
char *c1[]={"/tmp/Chg.py\0",'\0'};
setuid(0);
seteuid(0);
execv(c1[0],c1);
return 1;
}
--
http://mail.python.org/mailman/listinfo/python-list