Jump to content

Getting Returncode from runwait and sending it to MsgBox


Recommended Posts

What is the best way I could get the Output of an Errorlevel/returncode if the return code is anything other than a 0 and send the output of what is displays to a msgbox? I have a few commands I am running from a command line via RunWait like below. If there is an error when processing the bwlow commands I was hoping I could see the actual error without setting @SW_SHOW.

Rather than just getting the Return Code I was hoping to get an actual Error message that the RunWait line may give sent to a MSGBOX.

This is what I have been able to come up with.

Opt("RunErrorsFatal", 0)

; Adds User to the local copmuters Account NT database
RunWait('net user /add Support /comment:"Built-in account so IT can administer the computer" /fullname:"Local IT Administrator" /times:all /expires:never /active:yes /workstations:*',"",@SW_HIDE)
if @error <> 0 Then
    MsgBox(1024,"Error Creating Account","There was an Error creating the new User Account." & @CRLF & "The error code returned was : " & @error )

; Adds user to Local Administrators Account
RunWait("net localgroup administrators /add Support","",@SW_HIDE)
if @error <> 0 Then
    MsgBox(1024,"Error Setting Permissions","There was an Error setting the user permissions." & @CRLF & "The error code returned was : " & @error )


Thanks for any help,


Edited by MrChris
Link to comment
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

  • Recently Browsing   0 members

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