I need to run a .py at startup. the code works however the only way I can get it to start is to use this method-
import os
import subprocess
DIR = os.path.join('C:\\', 'Users', '7', 'Desktop', 'windowlessecclesiasticusworking.py')
subprocess.call(['python', DIR])
is there a way I can write a batch file that runs at startp that can run this method to start the .py file right after start up?
for some reason the .py no longer starts unless it is opened by opening a python shell and using the method stated above to start the file 'windowlessecclesiasticusworking.py'
heres how the windowlessecclesiasticusworking.py file looks in code.
import win32api, win32con, win32gui, win32ui, timer, threading
windowText = 'Ecclesiasticus'
hWindow = 0
def main():
hInstance = win32api.GetModuleHandle()
className = 'MyWindowClassName'
wndClass = win32gui.WNDCLASS()
wndClass.style = win32con.CS_HREDRAW | win32con.CS_VREDRAW
wndClass.lpfnWndProc = wndProc
wndClass.hInstance = hInstance
wndClass.hIcon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
wndClass.hCursor = win32gui.LoadCursor(None, win32con.IDC_ARROW)
wndClass.hbrBackground = win32gui.GetStockObject(win32con.WHITE_BRUSH)
wndClass.lpszClassName = className
wndClassAtom = win32gui.RegisterClass(wndClass)
exStyle = win32con.WS_EX_COMPOSITED | win32con.WS_EX_LAYERED | win32con.WS_EX_NOACTIVATE | win32con.WS_EX_TOPMOST | win32con.WS_EX_TRANSPARENT
style = win32con.WS_DISABLED | win32con.WS_POPUP | win32con.WS_VISIBLE
hWindow = win32gui.CreateWindowEx(
exStyle,
wndClassAtom,
None,
style,
0, # x
0, # y
win32api.GetSystemMetrics(win32con.SM_CXSCREEN), # width
win32api.GetSystemMetrics(win32con.SM_CYSCREEN), # height
None, # hWndParent
None, # hMenu
hInstance,
None # lpParam
)
win32gui.SetLayeredWindowAttributes(hWindow, 0x00ffffff, 255, win32con.LWA_COLORKEY | win32con.LWA_ALPHA) ####### COLOR
win32gui.SetWindowPos(hWindow, win32con.HWND_TOPMOST, 0, 0, 0, 0,
win32con.SWP_NOACTIVATE | win32con.SWP_NOMOVE | win32con.SWP_NOSIZE | win32con.SWP_SHOWWINDOW)
thr = threading.Thread(target=customDraw, args=(hWindow,))
thr.setDaemon(False)
thr.start()
win32gui.ShowWindow(hWindow, win32con.SW_SHOWNORMAL)
win32gui.UpdateWindow(hWindow)
timer.set_timer(10000, customDraw)
win32gui.PumpMessages()
counter = 0
def customDraw(timer_id, time):
global hWindow
global counter
global windowText
if counter > 40:
counter = 0
text = ["1:1 All wisdom is from the Lord God, and hath been always with him, and is before all time. ",
"1:2 Who hath numbered the sand of the sea, and the drops of rain, and the days of the world? Who hath measured the height of heaven, and the breadth of the earth, and the depth of the abyss? ",]
windowText = text[counter]
counter = counter + 1
win32gui.InvalidateRect(hWindow, None, True)
def wndProc(hWnd, message, wParam, lParam):
if message == win32con.WM_PAINT:
hdc, paintStruct = win32gui.BeginPaint(hWnd)
dpiScale = win32ui.GetDeviceCaps(hdc, win32con.LOGPIXELSX) / 60.0
fontSize = 18
lf = win32gui.LOGFONT()
lf.lfFaceName = "Comic Sans"
lf.lfHeight = int(round(dpiScale * fontSize))
hf = win32gui.CreateFontIndirect(lf)
win32gui.SelectObject(hdc, hf)
rect = win32gui.GetClientRect(hWnd)
win32gui.DrawText(hdc, windowText, -1, rect,
win32con.DT_LEFT | win32con.DT_BOTTOM | win32con.DT_SINGLELINE
)
win32gui.EndPaint(hWnd, paintStruct)
return 0
elif message == win32con.WM_DESTROY:
print('Being destroyed')
win32gui.PostQuitMessage(0)
return 0
else:
return win32gui.DefWindowProc(hWnd, message, wParam, lParam)
calrect = win32gui.DrawText(hdc, text, -1, rect, textformat | win32con.DT_CALCRECT);
rect.top = rect.bottom - calcrect.bottom;
win32gui.DrawText(hDC, text, -1, rect, textformat)
if __name__ == '__main__':
main()
originally when I was working on just trying to get the windowlessecclesiasticusworking.py python file to open and run after months of not touching it I ran into some errors with the win32api.. I updated python and used the first method talked about to start the .py file from python shell. now it is working, however I need it to start at startup so perhaps there is a way to run the 'import os import subprocess' snippet of shell code in a batch file. the solution can be anything I just think batch file for windows would be the easiest to run at startup. but I am not the expert obviously so any and all suggestions would help greatly. thanks.