title: Another How to start Python file at Windows Startup but
body: <p>I fount a lot of <strong>How to start Python at Windows Startup</strong> but maybe I have something different here...</p>
  <p>I made a Task Schedulation at Windows Startup (I want it before User loggin in) with a .vbs
  The VBS run correctly, but the .py file doesn't run.
  The VBS log to FILE.log correctly, but the Python script doesn't log anything (now I removed log).
  It isn't called...</p>
  <p>I tried to modify the VBS to have full path to python and to my script, but notting changed... the python script look like is not executed.</p>
  <p>Why?</p>
  <p><strong>VBS file:</strong></p>
  <pre><code>MyLog = &quot;C:\Users\myUser\Desktop\FILE.log&quot;
  
  Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
  
  if fso.FileExists(MyLog) = false then
     Set MyOutputLog = FSO.CreateTextFile(MyLog)
  else
     Set MyOutputLog = FSO.OpenTextFile(MyLog, 8, True)
  end if 
  
  MyOutputLog.writeline Cstr(now()) &amp; &quot; - VBS is ok&quot;
  
  MyOutputLog.close()
  
  Set oShell = CreateObject (&quot;WScript.Shell&quot;) 
  oShell.run &quot;python.exe ./myScript.py&quot;
  </code></pre>
  <p><strong>alternative bat file:</strong></p>
  <pre><code>cd C:\Users\myUser\Desktop\
  C:\Users\myUser\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbxxxxxx8p0\python.exe &quot;C:/Users/myUser/Desktop/myscript.py&quot;
  </code></pre>
  <p><strong>Python file:</strong></p>
  <pre><code>import socket
  import time
  import json 
  import requests
  
  TOKEN = &quot;&lt;my-bot-token&gt;&quot;
  URL = &quot;https://api.telegram.org/bot{}/&quot;.format(TOKEN)
  CHAT = 111111111 # my chat ID
  TEXT = &quot;my message&quot;
  
  
  def get_IPpubl():
      endpoint = 'https://ipinfo.io/json'
      response = requests.get(endpoint, verify = True)
  
      if response.status_code != 200:
          print('Status:', response.status_code, 'Problem with the request. Exiting.')
          exit()
  
      data = response.json()
  
      return(data['ip'])
  
  #check if DDNS is updated
  def check_ddns():
      IPddns = socket.gethostbyname('my.dynamic.dns')
      IPpubl = get_IPpubl()
      if IPddns == IPpubl:
          return True
      return False
  
  #check if I'm online
  def test_connection():
      try:
          socket.create_connection(('google.com', 80))
          return True
      except OSError:
          return False
  
  #functions for Telegram Bot
  def get_url(url):
      response = requests.get(url)
      content = response.content.decode(&quot;utf8&quot;)
      return content
  
  def get_json_from_url(url):
      content = get_url(url)
      js = json.loads(content)
      return js
  
  def get_updates():
      url = URL + &quot;getUpdates&quot;
      js = get_json_from_url(url)
      return js
  
  def get_last_chat_id_and_text(updates):
      num_updates = len(updates[&quot;result&quot;])
      last_update = num_updates - 1
      text = updates[&quot;result&quot;][last_update][&quot;message&quot;][&quot;text&quot;]
      chat_id = updates[&quot;result&quot;][last_update][&quot;message&quot;][&quot;chat&quot;][&quot;id&quot;]
      return (text, chat_id)
  
  def send_message(text, chat_id):
      url = URL + &quot;sendMessage?text={}&amp;chat_id={}&amp;parse_mode={}&quot;.format(text, chat_id, 'html')
      get_url(url)
  
  #try connection 300 times, after check DDNS and send message to Telegram
  for _ in range(300):
      if(test_connection()):
          if(check_ddns()):
              TEXT = TEXT + &quot;DDNS OK&quot;
          else:
              TEXT = TEXT + &quot;DDNS need an update&quot;
          send_message(TEXT, CHAT)
          break
      time.sleep(5)
  </code></pre>
  <p>Task scheduler is enabled, because the VBS run...
  However what I list what I select:</p>
  <p>[General]</p>
  <ul>
  <li>Account: myuser</li>
  <li>Run whether user is logged on or not</li>
  <li>Run with highest
  privileges</li>
  </ul>
  <p>[Triggers]</p>
  <ul>
  <li>At Windows Startup</li>
  </ul>
  <p>[Actions]</p>
  <ul>
  <li>Start a program: myVBS.vbs (try also with /c start &quot;C:\path_of_vbs_and_py&quot;</li>
  </ul>