Advertisement
sohotcall

Python NSSM Windows Service Battery Logger

Jan 22nd, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. 1. Install nssm.exe
  2.  
  3. 2. Copy C:\Program Files\Python38\Lib\site-packages\pywin32_system32\pywintypes38.dll
  4. as C:\Program Files\Python36\Lib\site-packages\win32\pywintypes38.dll
  5.  
  6. 3. Create this file, "D:\scripts\gsBatteryLog.py"
  7. #################################################
  8. import os, re, datetime, time
  9. counter = 0
  10. while True:
  11. if counter % 60 == 0:
  12. file = open( "D:/scripts/.gsBatteryLog.txt", "a" );
  13. output = os.popen( "wmic Path Win32_Battery Get EstimatedChargeRemaining /Value" ).read()
  14. percent = re.compile( r"[^0-9]", re.MULTILINE ).sub( "", output )
  15. file.write( datetime.datetime.now().isoformat() )
  16. file.write( " " )
  17. file.write( percent )
  18. file.write( "\n" )
  19. file.close()
  20. time.sleep( 5 )
  21. counter = counter + 1
  22. #################################################
  23.  
  24. 4. Install and start service
  25. > nssm.exe install GSBatteryLog "C:\Program Files\Python38\python.exe" D:\scripts\gsBatteryLog.py
  26.  
  27. 5. Buka "services.msc" dan Start service "GSBaterryLog"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement