0

I am attempting to create a password manager that runs on startup and autofills passwords using a certain keybind.

Currently, when running on startup the application creates a window and I researched ways to make the window hidden and I have found a VBScript example that allows for this to happen.

The script I found goes as following:

Dim WShell
Set WShell = CreateObject("WScript.Shell")
WShell.Run "c:\x\myapp.exe", 0
Set WShell = Nothing

I have added code to detect if my program is being ran out of the Startup directory.

I am working on creating code to execute the VBScript in the Python file yet my function returns quite a meaningless exception I cannot understand.

My python function goes as following:

def run_vbscript(script:str):
    shell = win32com.client.Dispatch("WScript.Shell")
    shell.Run(script)

The exception I currently am recieving goes as following:

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024894), None)

Have I made any obvious mistake in my Python function which is preventing the VBScript from executing?

0

1 Answer 1

2

VBScript are run using wscript. So just call it passing your script as argument.

So your function would look like:

import subprocess

def run_vbscript(script:str):
    subprocess.run(['wscript', script])

But...

WShell.Run is just running WinExec function from Windows API. You can pass to it the flag SW_HIDE that does the same your VBScript is doing.

Even better, you can use CreateProcess, that also provides this feature, since WinExec is deprecated.

Check Python for Win32 Extensions for a way to call this function directly from Python code. You're after CreateProcess function and the parameter that holds the SW_HIDE flag is startupinfo.wShowWindow.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.