1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Make symbolic link as admin with New-Item and subprocess

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024 às 08:22.

  1. Stack

    Stack Membro Participativo

    I got PS working CmdLet:

    New-Item -ItemType SymbolicLink -Path "C:\Users\user1\Saved Games\Scripts\BIOS" -Target "C:\Users\user1\Saved Games\bios\Scripts\BIOS"


    I need run as Admin (of course) so wrap around Start-Process and pass to Python's subprocess

    I image it can be something like:

    def run_cmd(*args):
    p = subprocess.Popen(*args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, error = p.communicate()
    return out, error

    cmd_symlink = '"New-Item -ItemType SymbolicLink -Path "C:\Users\user1\Saved Games\Scripts\BIOS" -Target "C:\Users\user1\Saved Games\bios\Scripts\BIOS"'
    ps_command = f"& {{Start-Process powershell.exe -argumentlist '-command {cmd_symlink}' -Verb RunAs}}"
    command = ['powershell.exe', '-command', ps_command]
    run_cmd(command)


    or????

    Continue reading...

Compartilhe esta Página