Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run py-kms as windows 2008R2 service #2

Closed
ghost opened this issue Feb 17, 2018 · 1 comment
Closed

Run py-kms as windows 2008R2 service #2

ghost opened this issue Feb 17, 2018 · 1 comment
Labels

Comments

@ghost
Copy link

ghost commented Feb 17, 2018

Download and install:
https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi (into C:\Windows\Python27)
https://github.com/mhammond/pywin32/releases/download/b222/pywin32-222.win-amd64-py2.7.exe

Download and extract py-kms-master.zip into C:\Windows\Python27\py-kms
cd C:\Windows\Python27\py-kms\

Create file kms-winservice.py and put into file this code:

import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import subprocess

class AppServerSvc (win32serviceutil.ServiceFramework):
    _svc_name_ = "py-kms"
    _svc_display_name_ = "py-kms"
    _proc = None
    _cmd = ["C:\Windows\Python27\python.exe", "C:\Windows\Python27\py-kms\server.py"]

    def __init__(self,args):
        win32serviceutil.ServiceFramework.__init__(self,args)
        self.hWaitStop = win32event.CreateEvent(None,0,0,None)
        socket.setdefaulttimeout(60)

    def SvcStop(self):
        self.killproc()
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_,''))
        self.main()

    def main(self):
        self._proc = subprocess.Popen(self._cmd)
        self._proc.wait()

    def killproc(self):
        self._proc.kill()

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(AppServerSvc)

C:\Windows\Python27\python.exe kms-winservice.py install
services.msc

Find "py-kms" service and change startup type from manual to auto.
Try to start the py-kms service.
Try activate Windows Server 2008 R2 VL:
slmgr.vbs /skms 127.0.0.1
slmgr.vbs /ato

@SystemRage
Copy link
Owner

Approach that should go, so added to wiki.
If fails, a more universal solution is to use Non-Sucking Service Manager.

rekkun pushed a commit to rekkun/py-kms that referenced this issue Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant