Can an application started by a windows service connect to internet - python

I have a script in python whose purpose is to make sure that a particular application that continuously download data from internet stays up all the time. If the application crashes, the script brings it back up.
Since the system is in Windows, I modified the script into a service, so that even if windows restarts itself, the service will ensure that the application is up even if the user is not logged in.
The service was installed using an account that has admin permissions. The system seems to work fine except that the application that is successfully brought up is not connecting to internet (The application writes log file, so we can be sure that it started fine). Faces the same issue if the user is changed to Network Service or Local System
So I was wondering if there are any permissions required to help it connect to internet (or is this not possible at all).

You probably need to specify an account that can run the application normally on the service's Log On tab (of the Services.msc control panel application):
Additional details in the Windows Services FAQ.

Related

Run executable in Desktop mode with Django / Python on IIS / Windows

The idea:
There is a Node.JS server which sends a request to the IIS server which is running Django / Python. It will send two files to the server which need to be converted with a program which needs to be run in the foreground mode.
So I already looked around in pretty much everything related to IIS and the running of executables here on SO, but still haven't got it working.
I got the following code to run the application from Django:
subprocess.call("C:\example.exe")
There will be probably be some serious security issues (although the server is only reachable from the local network) with the following setup, but here it is:
I'm running a Django application on IIS.
I've set the Application Pool Identity to my local user
I've given "Full Control" permission to "Everyone"
When the subprocess call gets executed it will add the program to my Background Processes with the USER being set to my local user.
Questions:
How do I make the program start in Desktop Mode?
Should I perhaps add another step (start another service) which will then start the program?
Edit:
Could I perhaps make a file watcher which watches if files get stored on the Windows Server and then triggers an executable based on that?

Python Script doesn't work properly as Geoprocessing Service

I have banged my head against the wall on this for days now, I need help.
I’m trying to create a geoprocessing service (which will be used via a flex viewer) that takes permit information from a GDB, writes it to a file, and then opens it on the user’s computer.
The script I have written works perfectly on local computers and when run from the server itself.
However, as soon as the script has been published as a geoprocessing service, it stops opening the file.
The file is created out on a webserver, and then opened via url so that the user can then make a local copy, print out for signature, etc. The file is still being created, named, and placed in the proper folder, it just isn’t being opened at end of the process. (The GP Service views as completed though, it doesn’t fail)
Here is the end of the code, which is the part relevant to my issue:
f = open(r'\\MyWebAddressHere\\Reports\\Permit' + str(PermitNumber) +'.html','w')
f.write(permitStart)
if (BasePermitFee > 0):
f.write(permitBaseFee)
if (PlumbingFee > 0):
f.write(permitPlumbingFee)
if (ElectricFee > 0):
f.write(permitElectricFee)
if (TotalFees > 0):
f.write(permitTotalFee)
f.write(permitEnd)
f.close()
webbrowser.open('MyWebAddressHere/Reports/Permit' + str(PermitNumber) +'.html')
Does anyone have a suggestion on why the open is failing once the GP service is published?
I don't see this as a bug - the webbrowser command makes no sense in the context of a GP Service. Think about what's being executed where.
If you run the code locally, Python is running on your actual computer - that computer has a login, a display, a set of installed programs. Telling it to open a web browser makes sense because you have one or more browsers installed on that computer.
Run it on the server, while logged into the server, and same thing - you still have a login, a set of installed programs. While you might lock down a server to reduce its vulnerability, it probably still has at least one program installed that is capable of browsing the internet.
But when you run a script as a GP Tool, you're in a different world. You're not running the code locally, and you're not logged into the server. If you execute the webbrowser command, where should it open the browser window?
On your PC? It can't - the server's GP environment can't execute random programs on your PC, that would be a massive security hole. Hey, I'll write a script that deletes everything in C:\Windows and publish it on ArcGIS Online!
On the server? Who would see it? No one's logged in.
Turns out that the webbrowser command flat out does not work in a server environment.
I managed to confuse the heck out of an ESRI server analyst with this one, because there is apparently no documentation saying this won't work in a server environment, it just doesn't. So it has been logged as a bug.

How to expose part of Python program as COM server

I have python application (bundled using py2exe) that runs as background system-tray application which monitor specific folder (like Dropbox) for any file add/create and backup that file into the cloud.
I want one feature added to that application i.e. expose API as COM server so another application can use it by passing the file path and get that file backed-up into cloud.
I have gone through this link on how to create COM server and I feel I'm close to get this things happen with following issue:
Every time I run my application it register the COM and hence ask Administrator's permission
What is the way to register COM without asking Administrator permission. My application distributed as installer made by Inno setup.
I need my application open automatically (if it is closed) when other application access COM object (registered by my application)

UI Automation Windows User login

I have a test case where i have to automate user action on windows UI,
The scenario is that windows password has expired, and when user tries to login to the
system, the reset password page appears and user inputs new password and login succeeds.
Now i have to do this through a script,
Good thing is i have a python service running on the machine to which i can pass commands if required prior to login.
I have Googled a lot but could not find anything similar.
Would be very glad if anyone can point me to anything specific to my problem,
What should be my reference point for this UI automation??
If you're trying to automate the Windows logon UI, I believe it's possible, but it requires that you use a Windows service to run your test code. Sounds like you may already be doing that, since you mentioned a Python service you can use to run commands while no user is logged in to Windows.
Anyway, Windows services are the only way I know to do this (without disabling UAC or otherwise modifying the default Windows security configuration).
See my answer to this question for some pointers:
UAC and remote control
If your Python code is running with the privileges of a Windows service, it should be able to interact with any UI on the system (or at least launch other processes that can interact with secure UI), including the Windows logon desktop.
The only headache may be that in order to interact with the Winlogon desktop, your test code may need to launch a separate program with the CreateProcessAsUser function (and pass "Winsta0\Winlogon" as the desktop param). Not sure, though.
This answer also looks like it might be helpful in your situation:
Running a process at the Windows 7 Welcome Screen

Cannot access Python server running as Windows service

I have written a Python TCP/IP server for internal use, using win32serviceutil/py2exe to create a Windows service.
I installed it on a computer running Windows XP Pro SP3. However, I can't connect to it when it's running as a service. I can confirm that it's binding to the address/port, because I get a conflict when I try to bind to that address/port with another application. Further, I have checked the Windows Firewall settings and have added appropriate exceptions. If I run the server as a simple console application, everything works as expected. However, when I run it as a service, it doesn't work.
I vaguely remember running into this problem before, but for the life of me can't remember any of the details.
Suggestions, anyone?
Possibly the program may be terminated just after initialization. Please check whether it is continuously listening to the requests.
netstat -an |find /i "listening"
And analyze the command line parsed to the programs. You may use procexp to do that.
First of all, whenever you implement a Windows service, be sure to add proper logging.
My worker threads were terminating because of the exception, "The socket operation could not complete without blocking."
The solution was to simply call sock.setblocking(1) after accepting the connection.
Check to see that the service is running under the Nertwork Service account and not the Local System account. The later doesn't have network access and is the default user to run services under. You can check this by going to the services app under administrative tool in the start menu and looking for your service. If you right-click the service you can go to properties and change the user that it is run under.

Categories

Resources