Re: What would be the best way to run python client in the background

2006-08-21 Thread gel
Tim Golden wrote:

> | Tim Golden wrote:
> |
> | > [gel]
> | >
> | > | I have written a python client server app [...]
> | > | I want to run the client end of the app more or less invisibly
> | > | (no console) on the XP clients when ever a users logs on.
>
> [Tim G]
> | > The normal way is to run a Win32 service. There are several
> | > posts on the subject around the Python and Python-Win32
> | > mailing lists / newsgroups. The alternative is to set something
> | > to run when any user logs in to run without a window. Again,
> | > there are posts on the subject, including one I seem to remember
> | > from Robin Becker, which tell how to do this kind of thing.
>
> [gel]
> | Yes running the client as a service seems to be the way to go.  I have
> | had a bit of a look at the py2exe way of doing it, but have not got my
> | head around it yet.  What would be your preferred way of creating a
> | service for an XP client?
>
> I've always coded pretty much from scratch, reusing a tried-and-trusted
> skeleton and fitting things in. That said, I've never had to put
> together
> a service that was anything more than lightweight. The attached template
> I
> culled from someone's webpage, can't remember where I'm afraid. I
> believe
> people have had success in using py2exe to create a service but I
> haven't
> tried it myself.
>
> Hopefully more experienced service-writers will chime in with coherent
> advice. You might also try the python-win32 mailing list, since not
> everyone who reads that reads this I imagine.
>
> TJG
>
Can I give you a look at the client side and ask for a suggestion as
how best to plug this into the template that you have supplied

The attempts that I made failed to start without much in the way of
error messages.

Any suggestion to do with my python style that you have would be
appreciated too.


# Import needed modules
import EasyDialogs
import wmi
import pythoncom
import threading
import time
import Pyro.core
import Pyro.naming, Pyro.core
from Pyro.errors import NamingError



# locate the NS
locator = Pyro.naming.NameServerLocator()
print 'Searching Name Server...',
ns = locator.getNS()

# resolve the Pyro object
print 'finding object'
try:
URI=ns.resolve('test')
print 'URI:',URI
except NamingError,x:
print 'Couldn\'t find object, nameserver says:',x
raise SystemExit

# make and instance of Pyro object
o = Pyro.core.getProxyForURI(URI)

#instance of wmi and get mac address of enabled NIC
c = wmi.WMI()
for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=1):
#  print interface.Description, interface.MACAddress
  for ip_address in interface.IPAddress:
 mac = interface.MACAddress
# put current time into var current_time
colItems = c.ExecQuery("SELECT UserName FROM Win32_ComputerSystem")
for objItem in colItems:

if objItem.UserName != None:
usr_name = str(objItem.UserName)
print "UserName: " + usr_name


# assign the dictionary object that o.r_l() returns to
d_licence_numbers
d_licence_numbers = o.r_l()
# So I can see how many licences are available for each piece of
software print d_licence_numbers
print d_licence_numbers

# Define the create class that watches for new processes to start
def diag(mesg):
EasyDialogs.Message(mesg)

def create():
global usr_name
pythoncom.CoInitialize()
c = wmi.WMI()
while 1 :
current_time = time.time()
d_clnt = {'MAC':mac, 'time':current_time, 'usr_name':
usr_name}
print d_clnt
print "watching creation"
watcher = c.watch_for(notification_type="Creation",
  wmi_class="Win32_Process",
   delay_secs=1)

proc = watcher()
name = proc.Name
if d_licence_numbers.has_key(name):
print "Process being watched = " + name

if len(o.r_d()[name]) != 0:
li = o.r_d()[name]
registered = False
for i in li:
print usr_name
print i['usr_name']
if mac == i['MAC'] or i['usr_name'] ==
usr_name:
print "Already in there"
registered = True
if registered != True:
for i in li:
#ps_id = ps_li.index(sw)
if len(o.r_d()[name]) < o.r_l()[name]:

o.a_d(name, d_clnt)
print "There is a license avialable for
" + name
print o.r_d()

else:
print "There are no licenses avialable
for " + name


for process in c.Win32_Process ():
if process.Name == name:
print process.ProcessId,
pro

Re: What would be the best way to run python client in the background

2006-08-21 Thread Ravi Teja
> The reason for the a seperate persistant check is because it will be
> used to enable software to be installed in whole lab of PCs but only
> allow a predifined number to run the software at any time one time.
> And then when a user stop using the software a licence will become
> available to for someone else on the same or another PC to use the
> software.  The reason that the process of the software being check is
> not used is because it will be used for software written by other
> people.  I hope this makes what and why a little clearer.  Let me know
> if you think that I have misunderstoood you.

Hmm... I don't have experience with such architecture personally. The
software being managed must have some sort of dependency on the license
manager if the manager is to be external. I don't know how you can
reliably manage external programs that are decoupled from the license
manager. You can however create a plug-in of sorts if the other authors
would be willing to incorporate it without much work to them.

I mostly explored license management in Delphi apps. Since Delphi
is/was a Shareware favorite, it has quite a few open source /
commercial components available to manage such licensing, usually with
trivial effort from the component user. You could take a look at them
(http://www.torry.net/quicksearchd.php?String=shareware&Title=No). Some
of them might even compile on Lazarus to expose them to Python. By
large, the culture of Python is open source and such expertise may not
be common place here.

You might want to subscribe to the mailing lists of "Association of
Shareware Professionals" (http://www.asp-shareware.org/). I have not
been on this path in 5 years and so am out of touch.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What would be the best way to run python client in the background

2006-08-21 Thread gel

Tim Golden wrote:

> | > [gel]
> | >
> | > | I have written a python client server app [...]
> | > | I want to run the client end of the app more or less invisibly
> | > | (no console) on the XP clients when ever a users logs on.
>
> While this isn't answering the question you first
> asked, might I suggest an alternative approach?
> Obviously, I'm working from no more than the sketch
> you gave of your app and its requirements, but might
> it be worth turning the problem on its head, and
> using WMI?
>
> Advantages:
>
> 1) WMI will -- almost certainly -- already be running on your
> target machines. No need to install your own service.
>
> 2) WMI has a fair range of mechanisms for determining
> what processes are starting, stopping, etc. and for
> manipulating them remotely.
>
> 3) You can, at least in theory, access any number of machines
> from a central server, and with a bit of judicious threading
> or looping, you should be able to generate a fair bit of resilience
> to machine dropouts etc.
>
> Disadvantages:
>
> 1) What you're doing may be far more complex than you've
> outlined, requiring a local service per target machine
> for other reasons.
>
> 2) You may have already invested some amount of time and
> effort in developing an app which does what you want.
>
> 3) I may have entirely misunderstood what you're trying
> to do in any case.
>
> If you're interested and want a code sample, let me know.
> If you're not, that's fine.
>
> TJG
>
Yes Tim I would be interested in seeing a code sample of how you would
approach this using a central server using wmi.

I am using wmi at the moment too, but on the client side, then pyro to
keep a central record of what was being run where.  So the client side
watches for starting praocesses, when one is found it checks the pyro
object on the server to see if the process is one that is being watched
and if it is, check to see if the allowed limit of PCs running that
process has ben reached.  If the limit has not been reached the client
marks the pyro object on the server to indicate that another PC is
running that piece of software.  If the limit has been reached the
client side kills the process and pops a dialogue box up stating that
there are no more licences available for that piece of software and to
try again later.  The reverse happens when a process is stopped.  If
the process is one that is being watched  and that client has a licence
book out for that software (checked with the MAC address) the number of
PCs running that pieces of software, which is stored in the pyro object
on the server decreased by one.

The thing that springs to mind with using a method where a central
server is using wmi, is the question of  if a lot of polling of the
remote client would be needed to know when a new process starts or
stops and if this would be heavy on the network and server?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What would be the best way to run python client in the background

2006-08-20 Thread gel

Ravi Teja wrote:

> gel wrote:
> > Hi
> > I have written a python client server app that keeps an eye on
> > processes starting and ending on a client and makes decision on what to
> > do based on information from the server end.  I want to run the client
> > end of the app more or less invisibly (no console) on the XP clients
> > when ever a users logs on.  What would be the best way to get this
> > done?  A bit more info on the purpose of the app... it is to act as a
> > licence server, where we have a limited number of licences for software
> > and the software installed on all PCs.  The app will only allow a pre
> > defined number of clients to run the software at any one time.
>
> To run a python script without a console - use *.pyw extension.
>
> But from what you stated you perhaps don't want to do this. Whether you
> deploy this check as a service (through py2exe for example) or a
> straight script, the users may simply kill it if they want to bypass
> the check. Plus it is not common to use a seperate persistant process
> to check for licenses. A better way is to incorporate the check
> directly into the process of the software.

The reason for the a seperate persistant check is because it will be
used to enable software to be installed in whole lab of PCs but only
allow a predifined number to run the software at any time one time.
And then when a user stop using the software a licence will become
available to for someone else on the same or another PC to use the
software.  The reason that the process of the software being check is
not used is because it will be used for software written by other
people.  I hope this makes what and why a little clearer.  Let me know
if you think that I have misunderstoood you.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What would be the best way to run python client in the background

2006-08-20 Thread Ravi Teja

gel wrote:
> Hi
> I have written a python client server app that keeps an eye on
> processes starting and ending on a client and makes decision on what to
> do based on information from the server end.  I want to run the client
> end of the app more or less invisibly (no console) on the XP clients
> when ever a users logs on.  What would be the best way to get this
> done?  A bit more info on the purpose of the app... it is to act as a
> licence server, where we have a limited number of licences for software
> and the software installed on all PCs.  The app will only allow a pre
> defined number of clients to run the software at any one time.

To run a python script without a console - use *.pyw extension.

But from what you stated you perhaps don't want to do this. Whether you
deploy this check as a service (through py2exe for example) or a
straight script, the users may simply kill it if they want to bypass
the check. Plus it is not common to use a seperate persistant process
to check for licenses. A better way is to incorporate the check
directly into the process of the software.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What would be the best way to run python client in the background

2006-08-20 Thread gel

Roger Upole wrote:

> You can use the Task Scheduler to run a script at login.
> It's not as robust as creating a service, but it's much less
> work.
>
>   Roger
>
OK thanks Roger I will have a bit a look at that option.  It is fairly
important for the solution to be robust, but this maybe enough.

Cheers

> "gel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> > Hi
> > I have written a python client server app that keeps an eye on
> > processes starting and ending on a client and makes decision on what to
> > do based on information from the server end.  I want to run the client
> > end of the app more or less invisibly (no console) on the XP clients
> > when ever a users logs on.  What would be the best way to get this
> > done?  A bit more info on the purpose of the app... it is to act as a
> > licence server, where we have a limited number of licences for software
> > and the software installed on all PCs.  The app will only allow a pre
> > defined number of clients to run the software at any one time.
> >

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What would be the best way to run python client in the background

2006-08-20 Thread gel
Tim Golden wrote:

> | > [gel]
> | >
> | > | I have written a python client server app [...]
> | > | I want to run the client end of the app more or less invisibly
> | > | (no console) on the XP clients when ever a users logs on.
>
> While this isn't answering the question you first
> asked, might I suggest an alternative approach?
> Obviously, I'm working from no more than the sketch
> you gave of your app and its requirements, but might
> it be worth turning the problem on its head, and
> using WMI?
>
> Advantages:
>
> 1) WMI will -- almost certainly -- already be running on your
> target machines. No need to install your own service.
>
> 2) WMI has a fair range of mechanisms for determining
> what processes are starting, stopping, etc. and for
> manipulating them remotely.
>
> 3) You can, at least in theory, access any number of machines
> from a central server, and with a bit of judicious threading
> or looping, you should be able to generate a fair bit of resilience
> to machine dropouts etc.
>
> Disadvantages:
>
> 1) What you're doing may be far more complex than you've
> outlined, requiring a local service per target machine
> for other reasons.
>
> 2) You may have already invested some amount of time and
> effort in developing an app which does what you want.
>
> 3) I may have entirely misunderstood what you're trying
> to do in any case.
>
> If you're interested and want a code sample, let me know.
> If you're not, that's fine.
>
> TJG
>

Hi Tim

Thanks for your suggestion, I have just got to read the post now and
appolagise to you and the others who have replied to my post for the
big gap.  I will have a read today and get back to you.

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: What would be the best way to run python client in the background

2006-08-16 Thread Tim Golden
| > [gel]
| >
| > | I have written a python client server app [...]
| > | I want to run the client end of the app more or less invisibly
| > | (no console) on the XP clients when ever a users logs on.

While this isn't answering the question you first
asked, might I suggest an alternative approach?
Obviously, I'm working from no more than the sketch
you gave of your app and its requirements, but might
it be worth turning the problem on its head, and
using WMI?

Advantages:

1) WMI will -- almost certainly -- already be running on your
target machines. No need to install your own service.

2) WMI has a fair range of mechanisms for determining
what processes are starting, stopping, etc. and for
manipulating them remotely.

3) You can, at least in theory, access any number of machines
from a central server, and with a bit of judicious threading
or looping, you should be able to generate a fair bit of resilience
to machine dropouts etc.

Disadvantages:

1) What you're doing may be far more complex than you've
outlined, requiring a local service per target machine
for other reasons.

2) You may have already invested some amount of time and
effort in developing an app which does what you want.

3) I may have entirely misunderstood what you're trying
to do in any case.

If you're interested and want a code sample, let me know.
If you're not, that's fine.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What would be the best way to run python client in the background

2006-08-16 Thread Roger Upole
You can use the Task Scheduler to run a script at login.
It's not as robust as creating a service, but it's much less
work.

  Roger

"gel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Hi
> I have written a python client server app that keeps an eye on
> processes starting and ending on a client and makes decision on what to
> do based on information from the server end.  I want to run the client
> end of the app more or less invisibly (no console) on the XP clients
> when ever a users logs on.  What would be the best way to get this
> done?  A bit more info on the purpose of the app... it is to act as a
> licence server, where we have a limited number of licences for software
> and the software installed on all PCs.  The app will only allow a pre
> defined number of clients to run the software at any one time.
> 


-- 
http://mail.python.org/mailman/listinfo/python-list


RE: What would be the best way to run python client in the background

2006-08-16 Thread Tim Golden
| Tim Golden wrote:
| 
| > [gel]
| >
| > | I have written a python client server app [...]
| > | I want to run the client end of the app more or less invisibly
| > | (no console) on the XP clients when ever a users logs on.

[Tim G]
| > The normal way is to run a Win32 service. There are several
| > posts on the subject around the Python and Python-Win32
| > mailing lists / newsgroups. The alternative is to set something
| > to run when any user logs in to run without a window. Again,
| > there are posts on the subject, including one I seem to remember
| > from Robin Becker, which tell how to do this kind of thing.

[gel]
| Yes running the client as a service seems to be the way to go.  I have
| had a bit of a look at the py2exe way of doing it, but have not got my
| head around it yet.  What would be your preferred way of creating a
| service for an XP client?

I've always coded pretty much from scratch, reusing a tried-and-trusted
skeleton and fitting things in. That said, I've never had to put
together
a service that was anything more than lightweight. The attached template
I
culled from someone's webpage, can't remember where I'm afraid. I
believe
people have had success in using py2exe to create a service but I
haven't
tried it myself.

Hopefully more experienced service-writers will chime in with coherent
advice. You might also try the python-win32 mailing list, since not
everyone who reads that reads this I imagine.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk


service_template.py
Description: service_template.py
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What would be the best way to run python client in the background

2006-08-15 Thread gel

Tim Golden wrote:

> [gel]
>
> | I have written a python client server app [...]
> | I want to run the client end of the app more or less invisibly
> | (no console) on the XP clients when ever a users logs on.
>
> You say "when[]ever a user logs on" but does this app
> need to be run on a per-user basis? Or could it run all
> the time -- ie as a Windows Service -- and do enough to
> determine which user is logged on when it needed to?
Yes at the moment the user name is set when the program starts, but it
is no problem to stick that further down program in the loop that
watches processes start and finish.
>
> The normal way is to run a Win32 service. There are several
> posts on the subject around the Python and Python-Win32
> mailing lists / newsgroups. The alternative is to set something
> to run when any user logs in to run without a window. Again,
> there are posts on the subject, including one I seem to remember
> from Robin Becker, which tell how to do this kind of thing.
Yes running the client as a service seems to be the way to go.  I have
had a bit of a look at the py2exe way of doing it, but have not got my
head around it yet.  What would be your preferred way of creating a
service for an XP client?

>
> Let us know if you can't find anything which seems to
> fit the bill.
>
> TJG
>
>



> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: What would be the best way to run python client in the background

2006-08-15 Thread Tim Golden
[gel]

| I have written a python client server app [...]
| I want to run the client end of the app more or less invisibly 
| (no console) on the XP clients when ever a users logs on.  

You say "when[]ever a user logs on" but does this app
need to be run on a per-user basis? Or could it run all
the time -- ie as a Windows Service -- and do enough to
determine which user is logged on when it needed to?

The normal way is to run a Win32 service. There are several
posts on the subject around the Python and Python-Win32
mailing lists / newsgroups. The alternative is to set something
to run when any user logs in to run without a window. Again,
there are posts on the subject, including one I seem to remember
from Robin Becker, which tell how to do this kind of thing.

Let us know if you can't find anything which seems to
fit the bill.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

-- 
http://mail.python.org/mailman/listinfo/python-list


What would be the best way to run python client in the background

2006-08-15 Thread gel
Hi
I have written a python client server app that keeps an eye on
processes starting and ending on a client and makes decision on what to
do based on information from the server end.  I want to run the client
end of the app more or less invisibly (no console) on the XP clients
when ever a users logs on.  What would be the best way to get this
done?  A bit more info on the purpose of the app... it is to act as a
licence server, where we have a limited number of licences for software
and the software installed on all PCs.  The app will only allow a pre
defined number of clients to run the software at any one time.

-- 
http://mail.python.org/mailman/listinfo/python-list