Function RunAsWait

  • Runs a program under a different user account and waits for it to close before continuing.

    Parameters

    • username: string

      The username to run the program as.

    • domain: string

      The domain of the user account.

    • password: string

      The password of the user account.

    • logonFlag: LogonFlag

      The logon flag to control the behavior of the logon.

    • program: string

      The name of the program to run.

    • directory: string = ''

      Optional working directory for the program.

    • showFlag: number = ShowWindowFlag.SHOWNORMAL

      Optional flag to control how the program's window is shown.

    Returns number

    The exit code of the program.

    import { RunAsWait, LogonFlag } from '@ahmic/autoit-js';

    const exitCode = RunAsWait('admin', 'DOMAIN', 'password', LogonFlag.Profile, 'notepad.exe');

    console.log(exitCode); // Output: 0