I want add a folder to the Quick Access in Windows via Python.
Python itself can not do that, however Powershell can.
Said folder changes on each run, so I need to pass it as a variable.
To minimize the imports I want to use os.system.
(Opposed to subprocess.run() and subprocess.popen(), as I had to import system already anyways.)
If its possible, I would also like to keep the code "inline", without having to store and reference a .ps1 file somewhere on my harddrive.
I cobbled together something that does not work via a Google search:
import os
myfolder = "C:/Windows"
os.system("powershell.exe [$qa = New-Object -ComObject shell.application && $qa.NameSpace('%s').Self.InvokeVerb('pintohome')]" % (myfolder))
I get the following error message:
In Zeile:1 Zeichen:2
+ [$qa = New-Object -ComObject shell.application
+ ~
Der Typname nach "[" fehlt.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingTypename
1.) How to properly tell Python to call powershell?
2.) How to add multiline code so it executes in the same environment?
3.) How to properly pass the folder variable?
As an added bonus, how would I hide the powershell window while executing the code?