Jump to content

Load program from CMD


aa2zz6
 Share

Recommended Posts

I have a .ini file that holds my path for our mapping software. I can't seem to get the CMD function to read the file path. I removed everything but the file path but it doesn't work.

[ArcGIS Desktop]
Path=C:\Users\<user name>\AppData\Local\ESRI\Desktop10.1\Launcher.exe

Local Const $sFilePath = @ScriptDir & "\Mapping\Path\ " & "Path" & ".ini"
    Local $sFilewrite = IniWrite($sFilePath, "ArcGIS Desktop", "Path=", "C:\Users\aa2zz6\AppData\Local\ESRI\Desktop10.1\Launcher.exe")
    
    Start()
    Func Start()
    $MyCommand = $sFilewrite
    Run(@ComSpec & " /c " & $MyCommand, @SystemDir, @SW_HIDE)
    EndFunc   ;==>Start

 

Edited by aa2zz6
Link to comment
Share on other sites

Credit to MHz for creating the CMD part.

Creating the .ini file

;Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = @ScriptDir & "\Mapping\" & "Config.ini"


    Local $sFilewrite = 'IGNORE_ERRORS=' & IniWrite($sFilePath, "settings", 'IGNORE_ERRORS', 1 &  @CRLF & 'Installer='&  $out)

$out is generated by another CMD process script that scans the hard drive in order to find the mapping software. But if you know the path won't change I would write it in like below.

;Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = @ScriptDir & "\Mapping\" & "Config.ini"


    Local $sFilewrite = 'IGNORE_ERRORS=' & IniWrite($sFilePath, "settings", 'IGNORE_ERRORS', 1 &  @CRLF & 'Installer=' &  "C:\Users\aa2zz6\AppData\Local\ESRI\Desktop10.1\ArcGIS Desktop.exe")

.ini file will look like

[settings]
IGNORE_ERRORS=1
Installer=C:\Users\aa2zz6\AppData\Local\ESRI\Desktop10.1\ArcGIS Desktop.exe

Reading file path to CMD

Global $Ignore, $Ini, $Installer, $Pid

; Ini Settings file
$Ini = @ScriptDir & "\Mapping\" & "Config.ini""
; Read Ini Setting: IGNORE_ERRORS=0 or IGNORE_ERRORS=1
$Ignore = 'IGNORE_ERRORS=' & IniRead($Ini, "Settings", "IGNORE_ERRORS", 0)
; Read Ini Setting: Installer to run later
$Installer = IniRead($Ini, "Settings", "Installer", "")

; If $Installer is something and $Installer exists, then run it.
If $Installer And FileExists($Installer) Then
    $Pid = Run('"' & @ComSpec & '" /c "' & $Installer & '" /v "' & $Ignore & '"', @ScriptDir, @SW_HIDE)
    ; Check if @error is set. (Use of Exit is optional as used for example)
    If @error Then Exit 1
    ; Wait for process to close
    ProcessWaitClose($Pid)
Else
    ; Act on condition failure of $Installer
    If Not $Installer Then Exit 2
    If Not FileExists($Installer) Then Exit 3
EndIf

 

Edited by aa2zz6
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

×
×
  • Create New...