JeffQOOQAAA

Call another au3 then return main program

15 posts in this topic

Hi

I have a problem ,  if description not clearly , please bear with me, thanks.

As below is my main program.

Call(_PoolName)

Func _PoolName()
Do
    Local $Poolname = InputBox("Input Machine Pool name", "Format:" &@LF& "Submit Project: Phase_UMA(DIS)_Project" &@LF& "Verfiy Project: Test_Project")

    If StringRegExp($Poolname, "_UMA_") Then
      $ID = _ArraySearch($aArray_Base,$Poolname)
         If $ID = -1 Then
          _ArrayAdd($aArray_Base, $Poolname)
          _ArrayDisplay($aArray_Base)
          Call(_Determine($Poolname))
         Else
            MsgBox(0,"", "Pool name is repeat")
            Call(_PoolName)
         EndIf

=======================================================================================================================================

Func _Determine($Poolname)

$File = FileOpen("auto.txt", 0)
Do
   $Char = FileRead($File, 55000)
   $Char1 = StringReplace($Char,"$Project_name",$Poolname,0,1)

   If FileExists(@DesktopDir & "\MachinePool.ps1") Then
      FileDelete(@DesktopDir & "\MachinePool.ps1")
      FileWrite(@DesktopDir & "\MachinePool.ps1", $Char1)
   Else
       FileWrite(@DesktopDir & "\MachinePool.ps1", $Char1)
   EndIf
Until 1

RunWait(@ComSpec & " /c " & "powershell " & "Set-ExecutionPolicy UnRestricted")

$1 = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "
$2 = """. "
$3 = "'C:\Users\Administrator\Desktop\MachinePool.ps1'"
Run($1 & $2 & $3 &"-auto -playlist C:\Users\Administrator\Desktop\hlk_0113\Playlist.xml", '')

EndFunc

 

 

Function  _PoolName() then call another function  _Determine($Poolname)

but not wait _Determine($Poolname) end then as soon return Function  _PoolName()

Is possibly?

Share this post


Link to post
Share on other sites



One way, in your _Determine.au3 file add the following at the top of your script

If $CmdLine[0] > 1 Then
    _Determine($CmdLineRaw)
EndIf

Within the _Pool.au3 file replace :

Call(_Determine($Poolname))

with

Run(@ScriptDir & '\Determine.exe ' & $Poolname, '', @SW_HIDE)

Or something like that

Share this post


Link to post
Share on other sites

@Subz

May i know what is $CmdLine[0]?

Share this post


Link to post
Share on other sites

In built variable, basically if you were to run your compiled app "Determine.exe switch1 switch2" it would return

$CmdLine[0] = 2
$CmdLine[1] = "switch1"
$CmdLine[2] = "switch2"

$CmdLineRaw = "switch1 switch2"

 

Share this post


Link to post
Share on other sites

So, for my command 

switch1 = $Poolname?

Share this post


Link to post
Share on other sites

Correct, so as mentioned within the _Pool.au3 file, replace :

Call(_Determine($Poolname))

with

Run(@ScriptDir & '\Determine.exe ' & $Poolname, '', @SW_HIDE)

Share this post


Link to post
Share on other sites

May I built to .exe for Determine.au3?

Share this post


Link to post
Share on other sites

Sorry not sure what you mean, do you mean how to compile your script into an exe?

Share this post


Link to post
Share on other sites

I want to know , if my parameter only 1 ($Poolname)

My $CmdLine is 1?

Share this post


Link to post
Share on other sites

#10 ·  Posted

Sorry my bad, understand now, the code above should have been:

If $CmdLine[0] > 0 Then
    _Determine($CmdLineRaw)
EndIf

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

1 hour ago, JeffQOOQAAA said:

I want to know , if my parameter only 1 ($Poolname)

My $CmdLine is 1?

Your

$CmdLine[0] = 1

[0] is the total count

and

$CmdLine[1] = $Poolname

[1] is the first one

EDIT: Why call .au3 file when instead of the compiled exe?

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

@Subz

I've try your way, but seen like no response  can't normally execute.

Maybe something wrong?

 

 

If $CmdLine[0] > 0 Then
    _Determine($CmdLineRaw)
EndIf

Func _Determine($Poolname)

$File = FileOpen("auto.txt", 0)
Do
   $Char = FileRead($File, 55000)
   $Char1 = StringReplace($Char,"$Project_name",$Poolname,0,1)

   If FileExists(@DesktopDir & "\MachinePool.ps1") Then
      FileDelete(@DesktopDir & "\MachinePool.ps1")
      FileWrite(@DesktopDir & "\MachinePool.ps1", $Char1)
   Else
       FileWrite(@DesktopDir & "\MachinePool.ps1", $Char1)
   EndIf
Until 1

RunWait(@ComSpec & " /c " & "powershell " & "Set-ExecutionPolicy UnRestricted")

$1 = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "
$2 = """. "
$3 = "'C:\Users\Administrator\Desktop\MachinePool.ps1'"
Run($1 & $2 & $3 &"-auto -playlist C:\Users\Administrator\Desktop\hlk_0113\Playlist.xml", '')

EndFunc

=========================================================

Func _PoolName()
Do
    Local $Poolname = InputBox("Input Machine Pool name", "Format:" &@LF& "Submit Project: Phase_UMA(DIS)_Project" &@LF& "Verfiy Project: Test_Project")

    If StringRegExp($Poolname, "_UMA_") Then
      $ID = _ArraySearch($aArray_Base,$Poolname)
         If $ID = -1 Then
          _ArrayAdd($aArray_Base, $Poolname)
          _ArrayDisplay($aArray_Base)
         Run(@ScriptDir & '\Determine.exe ' & $Poolname, '', @SW_HIDE)
         Else
            MsgBox(0,"", "Pool name is repeat")
            Call(_PoolName)
         EndIf

Share this post


Link to post
Share on other sites

#13 ·  Posted

Can you compile the following as an .exe and run your PoolName script again, this will create a "Determine.log" file in the same folder and show you the progress and any errors.

Global $bDebug = True
If $bDebug Then Global $hOpen = FileOpen(@ScriptDir & '\Determine.log', 1)

If $CmdLine[0] > 0 Then
    If $bDebug Then _DebugLog('$CmdLineRaw = ' & $CmdLineRaw)
    _Determine($CmdLineRaw)
EndIf

FileClose($hOpen)

Func _DebugLog($sString)
    FileWrite($hOpen, @YEAR & '\' & @MON & '\' & @MDAY & ' ' & @HOUR & ':' & @MIN & ':' & @SEC & ' :: ' & $sString & @CRLF)
EndFunc

Func _Determine($Poolname)
    If $bDebug Then _DebugLog('_Determine(' & $Poolname & ')')

$File = FileOpen("auto.txt", 0)
    If $bDebug Then _DebugLog('FileOpen("auto.txt", 0) Returned :' & @error)
Do
   $Char = FileRead($File, 55000)
    If $bDebug Then _DebugLog('$Char Returned :' & $Char)
   $Char1 = StringReplace($Char,"$Project_name",$Poolname,0,1)
    If $bDebug Then _DebugLog('$Char1 Returned :' & $Char1)

   If FileExists(@DesktopDir & "\MachinePool.ps1") Then
    If $bDebug Then _DebugLog('FileExists :"' & @DesktopDir & '\MachinePool.ps1"')
      $hFileDelete = FileDelete(@DesktopDir & "\MachinePool.ps1")
    If $bDebug Then _DebugLog('FileDelete :"' & @DesktopDir & '\MachinePool.ps1" Returned - ' & $hFileDelete)

    $hFileWrite = FileWrite(@DesktopDir & '\MachinePool.ps1', $Char1)
    If $bDebug Then _DebugLog('FileWrite :"' & @DesktopDir & '\MachinePool.ps1" Returned - ' & $hFileWrite)
   Else
        $hFileWrite = FileWrite(@DesktopDir & '\MachinePool.ps1', $Char1)
    If $bDebug Then _DebugLog('FileWrite :"' & @DesktopDir & '\MachinePool.ps1" Returned - ' & $hFileWrite)
   EndIf
Until 1

    $hRunWait = RunWait(@ComSpec & " /c " & "powershell " & "Set-ExecutionPolicy UnRestricted")
    If $bDebug Then _DebugLog('RunWait : "' &@ComSpec & ' /c powershell Set-ExecutionPolicy UnRestricted" Returned - ' & $hRunWait)

    $1 = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "
    $2 = """. "
    $3 = "'C:\Users\Administrator\Desktop\MachinePool.ps1'"
    $hRun = Run($1 & $2 & $3 &"-auto -playlist C:\Users\Administrator\Desktop\hlk_0113\Playlist.xml", '')
    If $bDebug Then _DebugLog('Run : "' & $1 & $2 & $3 & '"-auto -playlist "C:\Users\Administrator\Desktop\hlk_0113\Playlist.xml" Returned - ' & $hRun)
EndFunc

 

Share this post


Link to post
Share on other sites

#14 ·  Posted

@Subz    

Sorry my bad, It can normally execute, but one thing need you help 
Is possibly when call determine.exe then main program can as soon as return poolname function?
I don't want to wait determin.exe end then return poolname function.....

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

Unfortunately you have only posted a portion of your _PoolName() function, but here is how I would do it:
nb: Just added Ctrl+q to exit the function

HotKeySet('^q', 'ExitScript')

$aArray_Base[1]
While 1
    _PoolName()
    Sleep(100)
WEnd

Func _PoolName()
    Local $Poolname = InputBox("Input Machine Pool name", "Format:" &@LF& "Submit Project: Phase_UMA(DIS)_Project" &@LF& "Verfiy Project: Test_Project")
    If StringRegExp($Poolname, "_UMA_") Then
        $ID = _ArraySearch($aArray_Base,$Poolname)
        If $ID = -1 Then
            _ArrayAdd($aArray_Base, $Poolname)
            Run(@ScriptDir & '\Determine.exe ' & $Poolname, '', @SW_HIDE)
            Return
        EndIf
    EndIf
EndFunc

Func ExitScript()
    Exit
EndFunc

 

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