Sign in to follow this  
Followers 0
tlman12

Autoit not seeing [out] parameters

25 posts in this topic

so I'm trying to interface with a programs API and everything seems to work fine with autoit. i can create the object, initialize it, run the functions.

the problem comes when the function has an [out] parameter.

so like there's a function that is .GetLastError($errortext) but $errortext is an output and the function is supposed to write the results to that variable. instead of getting error text i get nothing.

the functions accept inputs just fine, and it works properly in vbscript. i'd like to use autoit though so i can create a gui wrapper for the api calls.

is there something i should be doing to get the info from the variables? or is there a special way to declare the variables? i've never had this problem before.

Share this post


Link to post
Share on other sites



Can you please give us more information?

Which program's API do you use?

What have you coded so far?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

sorry for the lack of info before, i was hopeing maybe i was doing something stupid and someone would key on on what it was.

it's for Sophos SafeGuard encryption

http://www.sophos.com/en-us/medialibrary/PDFs/documentation/sgn_60_m_eng_api.pdf

and basically all i did was convert this VBscript to AutoIT.

'----------------------------------------------------------------------------------------------------------
'Do a challenge/response by script
'
'Arguments: mode = 1: logon recovery
' mode = 2: bitLocker recovery
' mode = 3: suspension
'
' user: username (only needed if mode = 1 or mode 3)
'        challenge: the computer's challenge code (only needed if mode = 1 or mode 3)
' computer: computername (not needed for mode 3)
' drive: BitLocker drive letter (only needed if mode = 2)
'
'Call mode 1: e. g. cscript ChallengeResponsebyScript.vbs 1 computer user S9LWR99TKGZU8G115Z93C18C31JKSV
'Call mode 2: e. g. cscript ChallengeResponsebyScript.vbs 2 computer C
'Call mode 3: e. g. cscript ChallengeResponsebyScript.vbs 3 user 20 S9LWR99TKG
'----------------------------------------------------------------------------------------------------------
Option Explicit
On Error Resume Next
Dim Scripting
Dim ScriptingDirectory
Dim ScriptingCR
Dim adsDomain
Dim adsMachine
Dim adsUser
Dim challengeFlags
Dim response
Dim msoName
Dim sgnPassword
Dim opCode
Dim ret, result
Dim ErrorText
Dim adsType
Dim arg
Dim mode 'Bitlocker, SGN-Client Suspension
Set arg = wscript.arguments
msoName = "mso"
sgnPassword = "1234"
Set Scripting = WScript.CreateObject("Utimaco.SafeGuard.AdministrationConsole.Scripting.Base")
Set ScriptingDirectory = Scripting.CreateDirectoryClassInstance()
Set ScriptingCR = Scripting.CreateCRClassInstance()
result = Scripting.Initialize()
ret = Scripting.GetLastError(ErrorText)
wscript.echo("Init Scripting: " & ErrorText)
result = Scripting.AuthenticateOfficer(msoName, sgnPassword, "")
result = ScriptingDirectory.Initialize()
ret = Scripting.GetLastError(ErrorText)
wscript.echo("Init ScriptingDirectory: " + ErrorText)
result = ScriptingCR.Initialize()
ret = Scripting.GetLastError(ErrorText)
wscript.echo("Init ScriptingCR: " + ErrorText)
adsDomain = "DC=mydomain,dc=com"
mode = arg(0)
If (mode = 1 OR mode = 2) Then
result = ScriptingDirectory.GetOneObject(arg(1), adsDomain, 0, adsMachine, adsType)
ret = Scripting.GetLastError(ErrorText)
wscript.echo("GetOneObject Machine :" + ErrorText & " -> " & result)
End If
If mode = 1 Then ' logon recovery
result = ScriptingDirectory.GetOneObject(arg(2), adsDomain, 0, adsUser, adsType)
ret = Scripting.GetLastError(ErrorText)
WScript.echo("GetOneObject User :" + ErrorText & " -> " & result)

WScript.Echo("CR-Flag for User : " & " adsUser: " & arg(2) & " adsMachine: " & arg(1) & " " & arg(3))
result = ScriptingCR.GetChallengeFlags(adsMachine, arg(3), challengeFlags)
ret = Scripting.GetLastError(ErrorText)
wscript.echo("GetChallengeFlags :" & ErrorText & " -> " & result & " ChallangeFlags: " & challengeFlags)

result = ScriptingCR.ComputeResponse(adsUser, adsMachine, arg(3), 0, response)
ret = Scripting.GetLastError(ErrorText)
wscript.echo("ComputeResponse 1 :" & ErrorText & " -> " & result & " " & response)
ElseIf mode = 2 Then ' BitLocker recovery
result = ScriptingCR.BitLockerRecovery(adsMachine, arg(2), response)
ret = Scripting.GetLastError(ErrorText)
wscript.echo("ComputeResponse 1 :" & ErrorText & " -> " & result & " " & response)
ElseIf mode = 3 Then ' Suspension
result = ScriptingDirectory.GetOneObject(arg(1), adsDomain, 0, adsUser, adsType)
ret = Scripting.GetLastError(ErrorText)
wscript.echo("GetOneObject User :" + ErrorText & " -> " & result & " " & adsUser)
result = ScriptingCR.SuspensionComputeResponse(arg(3), adsUser, arg(2), opCode , response)
ret = Scripting.GetLastError(ErrorText)
wscript.echo("SuspendComputeResponse 3:" & ErrorText & " -> " & result & " " & " Suspend module " & opCode & " Response " & response)

Else
wscript.echo("unknown mode!")
End If
result = ScriptingCR.FreeResources()
result = ScriptingDirectory.FreeResources()
result = Scripting.FreeResources()
If Err.Number <> 0 Then
If Err.Number = 9 Then
     WScript.Echo("The syntax is incorrect for C/R: E.g. cscript ChallengeResponsebyScript.vbs 1 computer user challenge")
     WScript.Echo("The syntax is incorrect for Bitlocker: E.g. cscript ChallengeResponsebyScript.vbs 2 computer drive-letter")
     WScript.Echo("The syntax is incorrect for Suspension: E.g. cscript ChallengeResponsebyScript.vbs 3 user time_in_minutes challenge")
Else
     WScript.Echo("An error has occurred " & Err.Number)
End If
End If

like i said most of it works, just nothing where the parameter is an [out]

like this one ComputeResponse(string adsUser, string adsMachine, string challenge, int action, out string response)

the return funcions properly returning a good error code from the table in the document so i know the function is working properly but the outs are more important

OBJECT_OWN_MEMBER = -15 Object cannot be its own member.

For example: a group cannot be its own member.

ACTION_NOT_FINALIZED = -14 Action (e.g. wildcard search) not finalized.

ACTION_NOT_INITIALIZED = -13 Action (e.g. wildcard search) not initialized.

RESULT_NOT_UNIQUE = -12 Result set is not unique.

INVALID_CHALLENGE_CODE = -11 Wrong challenge code entered for Challenge/

Response.

NO_MORE_DATA = -10 End of data in any wildcard search method.

INSUFFICIENT_RIGHTS = -9 Current Security Officer has insufficient rights.

CONFIG_FILE_ERROR = -8 .conf file could not be found or is invalid.

TOKEN_INVALID_SLOT = -7 Invalid token slot ID.

NOT_AUTHENTICATED = -6 Security Officer has not authenticated.

OBJECT_NOT_FOUND = -5 Object not found in the database.

OBJECT_ALREADY_EXISTS = -4 Object already exists.

TOKEN_NOT_PRESENT = -3 No token in the slot.

NOT_INITIALIZED = -2 API was not initialized.

FAILURE = -1 General failure.

OK = 0 Success.

Edited by tlman12

Share this post


Link to post
Share on other sites

To help you with your AutoIt code we need to see your AutoIt code ...


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

To help you with your AutoIt code we need to see your AutoIt code ...

the autoit code is practically verbatim of the vbs code so i'm not sure how it's going to help, but imho this script is worthless to anyone trying to help me that doesn't have sophos safeguard encryption unless you know what the problem may be. it doesn't get past line 38 without the software installed. and on my computer everything works but the [out] variables in the functions.

;~ '----------------------------------------------------------------------------------------------------------
;~ 'Do a challenge/$response by script
;~ '
;~ 'Arguments: $mode = 1: logon recovery
;~ ' $mode = 2: bitLocker recovery
;~ ' $mode = 3: suspension
;~ '
;~ ' user: username (only needed if $mode = 1 or $mode 3)
;~ ' challenge: the computer's challenge code (only needed if $mode = 1 or $mode 3)
;~ ' computer: computername (not needed for $mode 3)
;~ ' drive: BitLocker drive letter (only needed if $mode = 2)
;~ '
;~ 'Call $mode 1: e. g. cscript Challenge$responsebyScript.vbs 1 computer user S9LWR99TKGZU8G115Z93C18C31JKSV
;~ 'Call $mode 2: e. g. cscript Challenge$responsebyScript.vbs 2 computer C
;~ 'Call $mode 3: e. g. cscript Challenge$responsebyScript.vbs 3 user 20 S9LWR99TKG
;~ '----------------------------------------------------------------------------------------------------------

Dim $Scripting
Dim $ScriptingDirectory
Dim $ScriptingCR
Dim $adsDomain
Dim $adsMachine
Dim $adsUser
Dim $challengeFlags
Dim $response
Dim $msoName
Dim $sgnPassword
Dim $opCode
Dim $ret
Dim $result
Dim $ErrorText
Dim $adsType
Dim $arg
Dim $mode ;'Bitlocker, SGN-Client Suspension
$arg = $cmdLine
$msoName = "mso"
$sgnPassword = "1234"
$Scripting = ObjCreate("Utimaco.SafeGuard.AdministrationConsole.$Scripting.Base")
$ScriptingDirectory = $Scripting.CreateDirectoryClassInstance()
$ScriptingCR = $Scripting.CreateCRClassInstance()
$result = $Scripting.Initialize()
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","Init $Scripting: " & $ErrorText)
$result = $Scripting.AuthenticateOfficer($msoName, $sgnPassword, "")
$result = $ScriptingDirectory.Initialize()
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","Init $ScriptingDirectory: " + $ErrorText)
$result = $ScriptingCR.Initialize()
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","Init $ScriptingCR: " + $ErrorText)
$adsDomain = "DC=mydomain,dc=com"
$mode = $arg[1]
If ($mode = 1 OR $mode = 2) Then
$result = $ScriptingDirectory.GetOneObject($arg[2], $adsDomain, 0, $adsMachine, $adsType)
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","GetOneObject Machine :" + $ErrorText & " -> " & $result)
EndIf
If $mode = 1 Then ;' logon recovery
$result = $ScriptingDirectory.GetOneObject($arg[3], $adsDomain, 0, $adsUser, $adsType)
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","GetOneObject User :" + $ErrorText & " -> " & $result)

msgbox(0,"","CR-Flag for User : " & " adsUser: " & $arg[3] & " adsMachine: " & $arg[2] & " " & $arg[4])
$result = $ScriptingCR.GetChallengeFlags($adsMachine, $arg[4], $challengeFlags)
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","GetChallengeFlags :" & $ErrorText & " -> " & $result & " ChallangeFlags: " & $challengeFlags)

$result = $ScriptingCR.Computeresponse($adsUser, $adsMachine, $arg[4], 0, $response)
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","Compute$response 1 :" & $ErrorText & " -> " & $result & " " & $response)
ElseIf $mode = 2 Then ;' BitLocker recovery
$result = $ScriptingCR.BitLockerRecovery($adsMachine, $arg[3], $response)
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","Compute$response 1 :" & $ErrorText & " -> " & $result & " " & $response)
ElseIf $mode = 3 Then ;' Suspension
$result = $ScriptingDirectory.GetOneObject($arg[2], $adsDomain, 0, $adsUser, $adsType)
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","GetOneObject User :" + $ErrorText & " -> " & $result & " " & $adsUser)
$result = $ScriptingCR.SuspensionComputeresponse($arg[4], $adsUser, $arg[3], $opCode , $response)
$ret = $Scripting.GetLastError($ErrorText)
msgbox(0,"","SuspendCompute$response 3:" & $ErrorText & " -> " & $result & " " & " Suspend module " & $opCode & " $response " & $response)

Else
msgbox(0,"","unknown $mode!")
EndIf
$result = $ScriptingCR.FreeResources()
$result = $ScriptingDirectory.FreeResources()
$result = $Scripting.FreeResources()
If @error <> 0 Then
If @error = 9 Then
msgbox(0,"","The syntax is incorrect for C/R: E.g. cscript Challenge$responsebyScript.vbs 1 computer user challenge")
msgbox(0,"","The syntax is incorrect for Bitlocker: E.g. cscript Challenge$responsebyScript.vbs 2 computer drive-letter")
msgbox(0,"","The syntax is incorrect for Suspension: E.g. cscript Challenge$responsebyScript.vbs 3 user time_in_minutes challenge")
Else
msgbox(0,"","An error has occurred " & @error)
EndIf
EndIf
Edited by tlman12

Share this post


Link to post
Share on other sites

... so like there's a function that is .GetLastError($errortext) but $errortext is an output and the function is supposed to write the results to that variable. instead of getting error text i get nothing. ...

Shouldn't the line
$ret = $Scripting.GetLastError($ErrorText)
then read sonmething like:
$ErrorText = $Scripting.GetLastError()
What is supposed to be in variable $ret?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

^^ tlman12 said the parameter is [out], he didn't say [retval]. That's big difference.

Unfortunately he failed to give more info about the version of AutoIt he's using, so my best guess is that he's using some buggy version. I would recommend trying newer.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Shouldn't the line

$ret = $Scripting.GetLastError($ErrorText)
then read sonmething like:
$ErrorText = $Scripting.GetLastError()
What is supposed to be in variable $ret?

$ret is set to the success/fail number value from my list above, so 0 means the function ran properly 1 means it failed. The API reference that i posted a link to has this as the description of that function

Uint32 Base::GetLastError(out string errorText)

Retrieves a textual representation of the last (internal) error occurred.

Note: In contrast to other API methods this method returns an unsigned integer which holds the

internal error code.

^^ tlman12 said the parameter is [out], he didn't say [retval]. That's big difference.

Unfortunately he failed to give more info about the version of AutoIt he's using, so my best guess is that he's using some buggy version. I would recommend trying newer.

i'm using the most current version 3.3.8.1

Share this post


Link to post
Share on other sites

Could you please set variable $ErrorText to a value (e.g. "**") before GetLastError is called? So we can see if the function touches the variable at all.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

i'm using the most current version 3.3.8.1

Try newer. Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Try newer.

beta? cause 3.3.8.1 is the current version

Share this post


Link to post
Share on other sites

On this page you'll find the link to the download section. Try 3.3.9.4


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

On this page you'll find the link to the download section. Try 3.3.9.4

didn't work with beta either. is there any reason this wouldn't be working? i would think that if it works in vbscript it should work in autoit. and like i said, based on the actual return values, i know the functions are working properly. i'm just not getting the info i need.

Share this post


Link to post
Share on other sites

... based on the actual return values, i know the functions are working properly.

If the function works properly why do you think GetLastError should return a value?

Have you tried my last suggestion?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

If the function works properly why do you think GetLastError should return a value?

Have you tried my last suggestion?

it's not just GetLastError. i only used that as an easy example

like i said most of it works, just nothing where the parameter is an [out]

like this one ComputeResponse(string adsUser, string adsMachine, string challenge, int action, out string response)

the return funcions properly returning a good error code from the table in the document so i know the function is working properly but the outs are more important

it is any function that returns its data with a byref or an [out] variable but based on the return values it is accepting the byval or [in] variables

also $ErrorText in the GetLastError us supposed to return "OK" on a good return.

Edited by tlman12

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

There are several reasons for your code not to work correctly. What you should do to determine the cause of failure is to run this code:

$Scripting = ObjCreate("Utimaco.SafeGuard.AdministrationConsole.Scripting.Base")

ConsoleWrite(@AutoItVersion & @CRLF)
ConsoleWrite(VarGetType($Scripting) & @CRLF)
ConsoleWrite(ObjName($Scripting, 4) & @CRLF)

...and then after you confirm correct version of AutoIt and object generation you should load with the file whose path will be printed as third line of the console output and then search for the method of the object that doesn't work like you expect it. When found, post the method definition here.

edit: reworded

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

There are several reasons for your code not to work correctly. What you should do to determine the cause of failure is to run this code:

$Scripting = ObjCreate("Utimaco.SafeGuard.AdministrationConsole.Scripting.Base")

ConsoleWrite(@AutoItVersion & @CRLF)
ConsoleWrite(VarGetType($Scripting) & @CRLF)
ConsoleWrite(ObjName($Scripting, 4) & @CRLF)

...and then after you confirm correct version of AutoIt and object generation you should load with the file whose path will be printed as third line of the console output and then search for the method of the object that doesn't work like you expect it. When found, post the method definition here.

edit: reworded

Ran that, didn't get a file path so i added the rest of the numbers in that objName() and got that console print.

Release:

+>15:50:41 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0409 Keyboard:00000409 OS:WIN_8/ CPU:X64 OS:X64)

>Running AU3Check (1.54.22.0) from:C:Program Files (x86)AutoIt3

+>15:50:41 AU3Check ended.rc:0

>Running:(3.3.8.1):C:Program Files (x86)AutoIt3autoit3.exe "10.65.19.2Laptop_ScriptSource_testing_partsTL_workspaceIn ProgressSGNtestobj.au3"

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop

3.3.8.1

Object

Object Name: Base

Description:

ProgID:

File:

Module: C:WindowsMicrosoft.NETFrameworkv4.0.30319clr.dll

CLSID: {80EECC7E-3861-3E69-AE2F-3369F1C9E1EA}

IID {B5B0629F-1BD3-3417-B4A0-C5CDE6A50150}

+>15:50:41 AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 2.013

Beta:

+>15:51:44 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0409 Keyboard:00000409 OS:WIN_8/ CPU:X64 OS:X64)

>Running AU3Check (3.3.9.4) from:C:Program Files (x86)AutoIt3beta

+>15:51:44 AU3Check ended.rc:0

>Running:(3.3.9.4):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "10.65.19.2Laptop_ScriptSource_testing_partsTL_workspaceIn ProgressSGNtestobj.au3"

--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop

3.3.9.4

Object

Object Name: Base

Description:

ProgID:

File:

Module: C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe

CLSID: {80EECC7E-3861-3E69-AE2F-3369F1C9E1EA}

IID {B5B0629F-1BD3-3417-B4A0-C5CDE6A50150}

+>15:51:44 AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 2.011

not sure where to go from here.

Edited by tlman12

Share this post


Link to post
Share on other sites

Update. I found a dll called Utimaco.SafeGuard.AdministrationConsole.Scripting.Base.dll but when i used your script to try to open it i got "No MSFT Typelib inside file!"

Share this post


Link to post
Share on other sites

How do you know it's [out]? Is there any documentation?

...I'm co-author of that part of AutoIt so I know what conditions need to be met to get the behavior you expect.


♡♡♡

.

eMyvnE

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  
Followers 0