Jump to content
Sign in to follow this  
qwerty

Problem with RunAsWait

Recommended Posts

qwerty

Hello Forums,

I am trying to write a script to uninstall our old antivirus so I can install the new one. I am having a problem getting the uninstaller to run, I have confirmed that I can uninstall it if I run the script manually but it doesnt work in my script and I can't quite work out why. Any help would be great.

Dim $UserName, $DomainName, $Password, $RunProgram, $RunPath, $pid

$UserName = "user"
$DomainName = "domain"
$Password = "something"

$RunProgram = "ntrmv.exe"
$RunPath = "%ProgramFiles%\Trend Micro\Client Server Security Agent"

$pid = RunAsWait($UserName, $DomainName, $Password, 0, $RunProgram, $RunPath)
ProcessWaitClose($pid)

MsgBox(0, "Exit Code:", $pid)

I get an exit code of 0 in the msgbox so I am a little confused. I have tried multiple combinations for the $RunProgram but all have given the same results.

Edited by qwerty

Share this post


Link to post
Share on other sites
whim

Hi, welcome to the forum.

According to the help file, RunAsWait returns the program's exit code, not the PID

HTH,

whim

Share this post


Link to post
Share on other sites
SKlocke

1)

You have to resolve the ProgramFiles variable.

Either by telling Autoit to expand environment variables in strings:

Opt("ExpandVarStrings")

But I do not like it, as sometimes you might want to pass something without expanding and I find it easier to read if I build the string manually.

Local $path= EnvGet("ProgramFiles")
Local $programPath = $path & "\myProgramFolder\myProgram.exe"

2)

Also, you have to give the filename with complete path to the executable as Parameter filename. Workingdir affects any file read/write and similar operations that might get called, but Autoit needs the path to the executable and does not look in workingdir.

3)

With using a domain account or calling an AntiVir uninstaller with Windows 7 UAC there might be more challenges.

If you run into problems with that, let us know the specifics if you need further help.

4) Whim is right about exit code as return value. Unfortunately, if e.g. you pass an invalid string to execute and Windows only gets a folder, not an executable that it shall run, you will get 0 as exit code.

Hope I got all that right, I'll try to read results or further questions later today.

Share this post


Link to post
Share on other sites
qwerty

Thanks guys all working now thanks to your suggestions.

Share this post


Link to post
Share on other sites
nergmlam

Hi

When using RunAs and RunAsWait you need to make sure, that the secondary logon service is running, and if you run your script from your own computer using e.g. pseexec.exe to get access to a remote computer, both computers must run the secondary logon service. And the secondary logon service needs the workstation service and netlogon service. The netlogon service only runs on domain computers, not on workgroup computers.

You also needs to select a "@workingDir" for the functions, that the end user have write access to.

Sincerely

Jorgen Malmgren

IT-Programmer

Denmark - UTC+1

www.tryware.dk

;o) Your brain is like a parachute. It works best when it's


Sincerely

J. Malmgren

IT-Programmer

http://www.tryware.dk

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×