Python脚本,介绍如何在windows服务器上启用设置



我有一个带有flask API的python脚本。我在命令行python scriptname.py中运行代码,并进行POST调用,它就工作了。

但如何在windows服务器上实时启用此设置,以便脚本随时运行并可供第三方进行HTTP发布。有什么建议吗。

class Impersonate:
def __init__(self,login,password):
self.domain='<domain>'
self.login=login
self.password=password
def logon(self):
self.handel=win32security.LogonUser(self.login,self.domain,self.password,win32con.LOGON32_LOGON_INTERACTIVE,win32con.LOGON32_PROVIDER_DEFAULT)
win32security.ImpersonateLoggedOnUser(self.handel)
def logoff(self):
win32security.RevertToSelf() #terminates impersonation
self.handel.Close() #guarantees cleanup

a=Impersonate('testuser','password]')
try:
a.logon() #become the user
print(a.login)
a.logoff() #return to normal
except:
pass


app = Flask(__name__)
api = Api(app)

class Hellow(Resource):
def post(self):
path = os.path.join(parentdir, dirname)
try:
os.makedirs(path)
resp = Response('{} successfully created.)


api.add_resource(Hellow, '/test')

if __name__ == "__main__":
app.run(port=5000, host="<hostname>" use_reloader=True)

您要么需要在服务器上部署flask后端,要么需要在您可以使用的窗口上部署"start/b python xyz.py";。或者也可以看看https://www.howtogeek.com/50786/using-srvstart-to-run-any-application-as-a-windows-service/

最新更新