0

I want to add my program to registry automatic when user open program , i found some video and used a module "rayanoos" but dose not working

My code:

import rayanoos
import sys
tool = rayanoos.tools()
tool.reg_add_to_startup("win" , sys.argv[0] )

and erorr:

Traceback (most recent call last):
  File "e:\code\lock\main.py", line 3, in <module>
    tool = rayanoos.tools()
  File "C:\Users\81332668\AppData\Local\Programs\Python\Python39\lib\site-packages\rayanoos.py", line 32, in __init__
    self.__dll = CDLL('C:\\ProgramData\\rns.rx')
  File "C:\Users\81332668\AppData\Local\Programs\Python\Python39\lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

what should i do to improve my bug !!

m7.arman
  • 71
  • 1
  • 11

1 Answers1

0

Add the following code to your script:

import getpass
USER_NAME = getpass.getuser()


def add_to_startup(file_path=""):
    if file_path == "":
        file_path = os.path.dirname(os.path.realpath(__file__))
    bat_path = r'C:\Users\%s\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup' % USER_NAME
    with open(bat_path + '\\' + "open.bat", "w+") as bat_file:
        bat_file.write(r'start "" %s' % file_path)

It will create a .BAT file in the startup folder that will run your script whenever you run windows.

Other options: Create a batch file containing your script and put it in the autostart folder -> "C:\Users{username}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"

Configure a runonce task or just run.

Insula
  • 999
  • 4
  • 10
  • dear i have a problem i want to exe my file then send to my friend and for first time run my program make .bat in start up , then .bat file always run automatic after restart pc???? – m7.arman Feb 02 '21 at 11:35
  • that should work, what exactly is the problem? – Insula Feb 02 '21 at 11:37
  • ohh no dude there is no exit problem i just want to ask and be sure – m7.arman Feb 02 '21 at 11:42
  • oh okay, yes it should work on another machine. You can test it on a virtual machine if you want to see how it will perform. – Insula Feb 02 '21 at 11:45
  • HI again , i test it on virtual machine and i got some error , when user open my program .bat file make in startup but in Task Manager my program dose not working , actually my program dose not work in background – m7.arman Feb 02 '21 at 17:03
  • try to the other things i mentioned. here are some useful links you can try: [first](https://stackoverflow.com/questions/4438020/how-to-start-a-python-file-while-windows-starts), [second](https://www.geeksforgeeks.org/autorun-a-python-script-on-windows-startup/) – Insula Feb 02 '21 at 17:47