Jump to content

Recommended Posts

Posted

Hi

I hope this is the right forum section.

I have a vbs that queries the AD through an SQL linked server. The SQL is set to windows authentication so the script only works if run under a service account specifically made for this.

Now, if I open a cmd prompt with runas and launch the vbs it works. It also works from an SCCM task sequence with run as under specified user.

I am trying to do the same from an autoit script. I am using:

$_catch_error = RunAsWait("accountname", "domain", "password", $RUN_LOGON_NOPROFILE, "wscript " & @ScriptDir & "\vbscript.vbs " & $parameter)

The result is an error pop up from Windows Script Host saying:

Can't find script engine "VBSCRIPT" for script <path to script>

It is already running with admin privileges otherwise it returns access denied.

At first I thought it can't access system32 for wscript.exe but I tried launching a cmd and it works.

Anyway, has anybody else run into this, any solutions or workarounds ?

Thank you.

  • Developers
Posted

Does this need to run as x86 or x64 command? You likely compiled as x86.
Another thing to check is to actually use the commandprompt by using :

 @comspec & " /c wscript " & @ScriptDir & "\vbscript.vbs " & $parameter

And another thing that could cause issues are spaces so double quote your parameters:

 @comspec & ' /c wscript "' & @ScriptDir & '\vbscript.vbs" "' & $parameter & '"'

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
14 minutes ago, Jos said:

Does this need to run as x86 or x64 command? You likely compiled as x86.
Another thing to check is to actually use the commandprompt by using :


 @comspec & " /c wscript " & @ScriptDir & "\vbscript.vbs " & $parameter

And another thing that could cause issues are spaces so double quote your parameters:


 @comspec & ' /c wscript "' & @ScriptDir & '\vbscript.vbs" "' & $parameter & '"'

Jos

New code looks like this:

$_catch_error = RunAsWait("accountname", "domain", "password", $RUN_LOGON_NOPROFILE, @comspec & ' /c wscript "' & @ScriptDir & '\script.vbs" "' & $parameter & '"')

I compiled both x86 and x64 and ran both as admin.

A cmd window opens and then the same error occurs as it attempts to launch the script.

I've also tried RunAsWait with just "cmd" as the string to be launched. It launches the cmd. I write "whoami" in the cmd, it correctly shows the service account. I write the path to the script manually in the cmd and press enter, same issue occurs.

By contrast, a cmd that I launch "by hand" with runas can launch the script with no problem.

I'm thinking the autoit runas command can't replicate the OS's runas perfectly, maybe restricted functionality applies...

Posted

In case anyone else runs into this, the only workaround I found was to insert a powershell script as middle man.

So autoit code is like:

$_catch_error = RunWait("powershell -executionpolicy bypass " & @ScriptDir & "\launcher.ps1 -user " & $aux_input,"", @SW_HIDE)

Code for launcher.ps1:

param([string]$user="user")

$password = "password" | ConvertTo-SecureString -asPlainText -Force
$username = "domain\account_name"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)

$current_dir = [environment]::CurrentDirectory
$return = Start-Process -FilePath "wscript.exe" -ArgumentList "$current_dir\vbscript.vbs $user" -Credential $credential -PassThru -Wait -NoNewWindow
[System.Environment]::Exit($return.ExitCode)

 

This will do what the RunAsWait was supposed to do...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...