Jump to content

Noob help: return value from compiled script


Recommended Posts

All -

Pardon my noobness... but I'm having problems getting the return value from a compiled script. Here's the script:

-------------

$var = FileSelectFolder("Choose a folder.", "")

-------------

Simple, one-line browse dialog that I got from the help file. When compiled, it works perfectly.

However, I'm using this as a workaround to a WinPE limitation and am incorporating this compiled exe into another script. I am calling this compiled exe as so:

---------------------

Sub runBrowseFolder

dim strExeLoc

dim strFolderLoc

strExeLoc = """" & oUtility.ScriptDir & "\browseFolder.exe"""

MsgBox strExeLoc

strFolderLoc = oShell.Run(strExeLoc, 1, true)

MsgBox strFolderLoc

End Sub

---------------------

Everything works fine, except for the return value. "strFolderLoc" returns 0... which of course is the success return code. However, I would like to get the full path of the folder as the return value.

I'm new to AutoIt, so I'm not sure how to do this. Obviously this would work if the AutoIt code was embedded in my script. The compiled exe is throwing me for a loop.

If this is possible, please help. And again, pardon my noobness.

~AngloTom

Link to comment
Share on other sites

Probably have to write the return value somewhere, whether that be a console, file, registry value or even the clipboard.

Look at runwait to make sure the external exe you ran has completed its task.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi AngloTom

Sorry for my bad english but why don't you use autoit like this to to get the full path of the folder ?

$strExeLoc=@ScriptDir & "\browseFolder.exe"""
$strFolderLoc=FileSelectFolder("Choose a folder.", "")
MsgBox(0,"Result", "strExeLoc is : "&$strExeLoc&@CRLF&"strFolderLoc is : "&$strFolderLoc)

That script worked great, but remember I'm trying to get a value from a compiled exe. If I compile the above script, the return value is still 0.

I've tried this:

---------

browseFolder()

Func browseFolder()

$var = FileSelectFolder("Choose a folder.", "")

Return $var

EndFunc

---------

But it doesn't return a value, only 0.

~AngloTom

Link to comment
Share on other sites

Probably have to write the return value somewhere, whether that be a console, file, registry value or even the clipboard.

Look at runwait to make sure the external exe you ran has completed its task.

John -

I will give that a try. Writing to the clipboard would be the cleanest, but I'm not sure how to get the clipboard value in a VBS script. I will look into it.

Thanks.

~AngloTom

Link to comment
Share on other sites

Heres a quick and remarkably dirty example using the clipboard.

There will be better ways.

compile this name it Test1.exe

ClipPut("250")

Run this script from same dir

RunWait("Test1.exe")
$var = ClipGet()
MsgBox(0,"",$var)

EDIT: sorry never seen reply about vbs, have no idea about that im afraid.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

That script worked great, but remember I'm trying to get a value from a compiled exe. If I compile the above script, the return value is still 0.

I've tried this:

---------

browseFolder()

Func browseFolder()

$var = FileSelectFolder("Choose a folder.", "")

Return $var

EndFunc

---------

But it doesn't return a value, only 0.

~AngloTom

Sorry if i don't have a good english, I hope to have understood but why don't you do all you want in VBS ?

Link to comment
Share on other sites

Sorry if i don't have a good english, I hope to have understood but why don't you do all you want in VBS ?

The reason I can't use the VBS function BrowseForFolder() is because of a limitation in WinPE. Because WinPE is such a "streamlined" OS, some of the binaries and registry entries are missing for the function to work correctly. In WinPE, the browse dialog comes up, but is completely blank. That's why I had to go the AutoIt route... because it's all self contained.

~AngloTom

Link to comment
Share on other sites

Heres a quick and remarkably dirty example using the clipboard.

There will be better ways.

compile this name it Test1.exe

ClipPut("250")

Run this script from same dir

RunWait("Test1.exe")
$var = ClipGet()
MsgBox(0,"",$var)

EDIT: sorry never seen reply about vbs, have no idea about that im afraid.

Got that to work. Now to find out how to read the clipboard in VBS. I don't think it's going to be a direct route... in VB it would be. VBS, I don't think so.

~AngloTom

Link to comment
Share on other sites

You should look in the helpfile regarding the parameters for the Return (for functions) and Exit (for scripts) statements. You can return whatever value you like with something like Exit($returncode).

Link to comment
Share on other sites

You should look in the helpfile regarding the parameters for the Return (for functions) and Exit (for scripts) statements. You can return whatever value you like with something like Exit($returncode).

The exit code can only be a simple integer.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Got that to work. Now to find out how to read the clipboard in VBS. I don't think it's going to be a direct route... in VB it would be. VBS, I don't think so.

~AngloTom

Just use a tempfile then or registry, or even an ini.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

You should look in the helpfile regarding the parameters for the Return (for functions) and Exit (for scripts) statements. You can return whatever value you like with something like Exit($returncode).

But is this value returned from a compiled exe? From my example above, I am using "Return $var" to return the folder location. However, when I set a variable to the value of the compiled exe, I get "0". Here's how I'm calling it again:

Sub runBrowseFolder

dim strExeLoc

dim strFolderLoc

strExeLoc = """" & oUtility.ScriptDir & "\browseFolder.exe""" <!---- COMPILED AUTOIT SCRIPT -->

MsgBox strExeLoc

strFolderLoc = oShell.Run(strExeLoc, 1, true)

MsgBox strFolderLoc

End Sub

"strFolderLoc" returns a "0" in this case.

~AngloTom

Link to comment
Share on other sites

After glancing over this real quick...why not just make it completely in AutoIt? Anything you want done in VB can be done in AutoIt as far as I know.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

After glancing over this real quick...why not just make it completely in AutoIt? Anything you want done in VB can be done in AutoIt as far as I know.

Hi All,

A brief de-lurk!

Why not all in Autoit? good Q, but just in case....

from top reprise: getting a folder in the exe:

AutoIt , but Compile this with the Au2Exe prog ("Compile Script to .exe"), using the 'Console app' switch.

HotKeySet("{END}", "Escape")

$var = FileSelectFolder("Choose a folder.", "")
ConsoleWrite($var)

Func Escape()
    Exit
EndFunc

Our vbscript now that works is:

exestr = "C:\ConsoleTestExe.exe"

Dim WshShell, oExec

Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec(exestr)

Do While not oExec.StdOut.AtEndOfStream

strLineRead = oExec.StdOut.ReadLine()

WScript.Echo strLineRead

Loop

Set oExec = nothing

Set WshShell = nothing

All from the Autoit help and Microsoft's online MSDN (via Google).

Bye, HTH

Tree

Link to comment
Share on other sites

After glancing over this real quick...why not just make it completely in AutoIt? Anything you want done in VB can be done in AutoIt as far as I know.

I wish I could... but I'm stuck with using HTA pages as the GUI with a VBS back-end. I'm writing a task sequence for MDT, which will run in WinPE.

Link to comment
Share on other sites

Hi All,

A brief de-lurk!

Why not all in Autoit? good Q, but just in case....

from top reprise: getting a folder in the exe:

AutoIt , but Compile this with the Au2Exe prog ("Compile Script to .exe"), using the 'Console app' switch.

HotKeySet("{END}", "Escape")

$var = FileSelectFolder("Choose a folder.", "")
ConsoleWrite($var)

Func Escape()
    Exit
EndFunc

Our vbscript now that works is:

exestr = "C:\ConsoleTestExe.exe"

Dim WshShell, oExec

Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec(exestr)

Do While not oExec.StdOut.AtEndOfStream

strLineRead = oExec.StdOut.ReadLine()

WScript.Echo strLineRead

Loop

Set oExec = nothing

Set WshShell = nothing

All from the Autoit help and Microsoft's online MSDN (via Google).

Bye, HTH

Tree

Thanks for that. I will also look at using the Console. Right now, my plan is to write the folder location to a file, read it with VBS, then delete the file.

~AngloTom

Link to comment
Share on other sites

Ok here's my compiled script's code:

browseFolder()

Func browseFolder()
$var = FileSelectFolder("Choose a folder.", "")

$file = FileOpen("txtFolderLoc.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, $var)

FileClose($file)

EndFunc

And here's how I'm calling it:

Sub runBrowseFolder 
     dim strRunVar, objFile, strFileName, strTextLine, strFolderLoc
 
     'assign file loc
     strFileName = oUtility.ScriptDir & "\txtFolderLoc.txt"
     
     'Run the AutoIT compiled EXE
     oShell.Run """" & oUtility.ScriptDir & "\browseFolder.exe""", 1, true

     'Read and assign folder location in text file to variable
     Set objFile = oFSO.OpenTextFile(strFileName, ForReading)
     strTextLine = objFile.ReadLine
     objFile.Close
     
     'Delete the file
     oFSO.DeleteFile(objFile)
     
     'assign folder location variable to HTA page text box
     If MPCRadio1.IsSelected Then
        fileNameCapture.value = strTextLine
     Else
        fileNameRestore.value = strTextLine
     End If
 End Sub

Everything works well with the compiled script until when ran outside of the VBS. It creates the text file, inputs the user folder location, and exits with 0. When it is called on by the VBS, it does NOT create the file, and therefore does not input the folder location... and subsequently the VBS cannot open the file. I'm thinking there's something wrong with my oShell.Run syntax, but I can't figure out what. I am waiting for the program to finish before I continue on, so I'm not sure what else is left. Any ideas?

~AngloTom

Link to comment
Share on other sites

Ok here's my compiled script's code:

browseFolder()

Func browseFolder()
$var = FileSelectFolder("Choose a folder.", "")

$file = FileOpen("txtFolderLoc.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

FileWrite($file, $var)

FileClose($file)

EndFunc

And here's how I'm calling it:

Sub runBrowseFolder 
     dim strRunVar, objFile, strFileName, strTextLine, strFolderLoc
 
     'assign file loc
     strFileName = oUtility.ScriptDir & "\txtFolderLoc.txt"
     
     'Run the AutoIT compiled EXE
     oShell.Run """" & oUtility.ScriptDir & "\browseFolder.exe""", 1, true

     'Read and assign folder location in text file to variable
     Set objFile = oFSO.OpenTextFile(strFileName, ForReading)
     strTextLine = objFile.ReadLine
     objFile.Close
     
     'Delete the file
     oFSO.DeleteFile(objFile)
     
     'assign folder location variable to HTA page text box
     If MPCRadio1.IsSelected Then
        fileNameCapture.value = strTextLine
     Else
        fileNameRestore.value = strTextLine
     End If
 End Sub

Everything works well with the compiled script until when ran outside of the VBS. It creates the text file, inputs the user folder location, and exits with 0. When it is called on by the VBS, it does NOT create the file, and therefore does not input the folder location... and subsequently the VBS cannot open the file. I'm thinking there's something wrong with my oShell.Run syntax, but I can't figure out what. I am waiting for the program to finish before I continue on, so I'm not sure what else is left. Any ideas?

~AngloTom

Nevermind! I'm an idiot. I'll post solution later.

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
 Share

  • Recently Browsing   0 members

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