0

OS: Windows 10

I have this python script that asks the user if he/she would like to print a file. While running this python script manually it works fine. However, when installing the Python script as an NSSM service, it skips over the message box part. The following is not the complete program, but a section of it. The rest of the python script (not included bellow) performs as it should win it is running as a service.

#!/usr/bin/python3
import os ,sys
import time
import ctypes  

def SomeProgram():
    if SomeCondition:
        return True, FilePath

def Mbox(title, text, style):
    return ctypes.windll.user32.MessageBoxW(0, text, title, style)

if __name__ == '__main__':
    while True:
        WriteToPdf, FilePath = SomeProgram()
        if WriteToPdf:
            MboxResult = Mbox('Print?', 'Would you like to print the the file?', 4)
            if MboxResult==6:
                #Yes was selected. Thus print the document
                os.startfile(FilePath, "print")
        time.sleep(4) 

How do I get a message box wit a script installed as a NSSM service?

EDIT:

NSSM has the following ERROR output to the log file

Traceback (most recent call last):
  File "C:\temp\FATs\populate_template.py", line 181, in <module>
    MboxResult = Mbox('Print protocoll?', 'Would you like to print the recently saved protocoll', 4)
  File "C:\temp\FATs\populate_template.py", line 168, in Mbox
    return ctypes.windll.user32.MessageBoxW(0, text, title, style)
KeyboardInterrupt
3
  • Services are not typically meant to be interactive and are generally run as different (non interactive) users in order to separate them from users or run at a different privilege level. Does your program need to run as a service or would it be better installed as a normal program and have a link run from one of the system user program startup areas?
    – Mokubai
    Apr 16 '20 at 8:03
  • The service detects newly created .CSV files and converts it to a .PDF. Once the file is converted, the popup dialog ask the user if they want to print the .PDF. Thanks for the documentation. I will have to evaluate what would be the best option. Apr 16 '20 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.