Jump to content

Strange script behavior


Go to solution Solved by trashy,

Recommended Posts

This has me totally baffled!

I'm trying to run dism for win 8 on a win 7 machine. I placed my script in the same folder as all

required dism files. Some commands work some don't, the ones that don't work are actually calling

dism from system32 directory instead of script folder. I suspect it has something to do with certain

commands when wrapped in a switch. Notice lines 116 and 153, same commands, 153 doesn't work.

This isn't true in all cases though, I noted other commands in same switch that do work.

Can any one shed some light on this strange behavior.

PS: I tried @ScriptDir but causes problem with commands that contain multiple variables

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\..\Program Files\AutoIt3\Icons\Oxygen-Icons.org-Oxygen-Apps-utilities-desktop-extra.ico
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Fileversion=2.3.0.0
#AutoIt3Wrapper_Res_LegalCopyright=@TLC
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
#include <Constants.au3>

$Form1 = GUICreate("DismGui", 620, 650, -1, -1, -1, ($WS_EX_WINDOWEDGE))

$Tab1 = GUICtrlCreateTab(24, 0, 570, 600)

;Start Mount Tab
$TabSheet0 = GUICtrlCreateTabItem("Mount")
GUICtrlSetState(-1, $GUI_SHOW)
; Create a dummy control to get the current ControlID
$iStart_0 = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$T1Button1 = GUICtrlCreateButton("Browse", 496, 48, 75, 25)
$T1Button2 = GUICtrlCreateButton("Browse", 496, 300, 75, 25)
$T1Button3 = GUICtrlCreateButton("Mount", 184, 555, 75, 25)
$T1Button4 = GUICtrlCreateButton("UnMount", 424, 555, 75, 25)
$T1Checkbox1 = GUICtrlCreateCheckbox("Commit", 360, 555, 65, 17)
$T1Checkbox2 = GUICtrlCreateCheckbox("ReadOnly", 265, 555, 65, 17)
$T1Label1 = GUICtrlCreateLabel("Mount Image", 272, 32, 66, 17)
$T1Label2 = GUICtrlCreateLabel("Source", 56, 48, 38, 17)
$T1Label3 = GUICtrlCreateLabel("Mount Folder", 45, 300, 62, 17)
$T1Label4 = GUICtrlCreateLabel("Image Index", 40, 555, 62, 17)
$T1Input1 = GUICtrlCreateInput("", 112, 48, 370, 21)
$T1Input2 = GUICtrlCreateInput("", 112, 300, 370, 21)
$T1Input3 = GUICtrlCreateInput("1", 120, 555, 35, 25)
GUICtrlCreateUpdown($T1Input3)
GUICtrlSetLimit(-1, 10, 1)
$T1Edit1 = GUICtrlCreateEdit("", 112, 80, 370, 210)
GUICtrlSetData(-1, "")
$T1Edit2 = GUICtrlCreateEdit("", 112, 330, 370, 210)
GUICtrlSetData(-1, "")
; Create a dummy control to get the current ControlID
$iEnd_0 = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; All the other controls on this tab must be between those 2 values

;Start Driver Tab
$TabSheet1 = GUICtrlCreateTabItem("Drivers")
$iStart_1 = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$T2Button0 = GUICtrlCreateButton("Browse", 504, 48, 75, 25)
$T2Button1 = GUICtrlCreateButton("Browse", 416, 298, 75, 25)
$T2Button2 = GUICtrlCreateButton("ADD", 504, 298, 75, 25)
$T2Button3 = GUICtrlCreateButton("Browse", 416, 325, 75, 25)
$T2Button4 = GUICtrlCreateButton("ADD", 504, 325, 75, 25)
$T2Button7 = GUICtrlCreateButton("Remove", 504, 352, 75, 25)
$T2Button8 = GUICtrlCreateButton("Example", 416, 352, 75, 25)
$T2Button5 = GUICtrlCreateButton("Driver Info", 504, 440, 75, 25)
$T2Button6 = GUICtrlCreateButton("Driver Info", 504, 530, 75, 25)
$T2Input0 = GUICtrlCreateInput("", 120, 48, 370, 21)
$T2Input1 = GUICtrlCreateInput("", 120, 298, 281, 21)
$T2Input2 = GUICtrlCreateInput("", 120, 325, 281, 21)
$T2Input3 = GUICtrlCreateInput("", 120, 352, 281, 21)
$T2Label0 = GUICtrlCreateLabel("Mount Folder", 45, 48, 62, 17)
$T2Label1 = GUICtrlCreateLabel("Single Driver", 56, 298, 64, 17)
$T2Label2 = GUICtrlCreateLabel("Driver Folder", 56, 325, 64, 17)
$T2Label5 = GUICtrlCreateLabel("Driver Name", 56, 352, 64, 17)
$T2Label3 = GUICtrlCreateLabel("Retrieve All Driver Info from Mounted Image", 504, 400, 80, 37)
$T2Label4 = GUICtrlCreateLabel("Retrieve 3rd Party Driver Info from Mounted Image", 504, 490, 85, 37)
$T2Edit1 = GUICtrlCreateEdit("", 120, 80, 370, 210)
GUICtrlSetData(-1, "")
$T2Edit2 = GUICtrlCreateEdit("", 120, 380, 370, 210)
GUICtrlSetData(-1, "")
$iEnd_1 = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Tabs not set
$TabSheet2 = GUICtrlCreateTabItem("Packages")
$iStart_2 = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$T3Button1 = GUICtrlCreateButton("Browse", 504, 48, 75, 25)
$T3Button2 = GUICtrlCreateButton("Browse", 416, 298, 75, 25)
$T3Button3 = GUICtrlCreateButton("ADD", 504, 298, 75, 25)
$T3Button4 = GUICtrlCreateButton("Browse", 416, 325, 75, 25)
$T3Button5 = GUICtrlCreateButton("ADD", 504, 325, 75, 25)
$T3Button6 = GUICtrlCreateButton("Remove", 504, 352, 75, 25)
$T3Button7 = GUICtrlCreateButton("Example", 416, 352, 75, 25)
$T3Button8 = GUICtrlCreateButton("Pkg Info", 504, 440, 75, 25)

$T3Edit1 = GUICtrlCreateEdit("", 120, 80, 370, 210)
GUICtrlSetData(-1, "")
$T3Edit2 = GUICtrlCreateEdit("", 120, 380, 370, 210)
GUICtrlSetData(-1, "")

$T3Input1 = GUICtrlCreateInput("", 120, 48, 370, 21)
$T3Input2 = GUICtrlCreateInput("", 120, 298, 281, 21)
$T3Input3 = GUICtrlCreateInput("", 120, 325, 281, 21)
$T3Input4 = GUICtrlCreateInput("", 120, 352, 281, 21)
$T3Label1 = GUICtrlCreateLabel("Mount Folder", 45, 48, 62, 17)
$T3Label2 = GUICtrlCreateLabel("Single Pkg", 56, 298, 64, 17)
$T3Label3 = GUICtrlCreateLabel("Pkg Folder", 56, 325, 64, 17)
$T3Label4 = GUICtrlCreateLabel("Driver Name", 56, 352, 64, 17)
$iEnd_2 = GUICtrlCreateDummy() ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlCreateTabItem("")
$Button1 = GUICtrlCreateButton("EXIT", 272, 610, 75, 25)
$Button2 = GUICtrlCreateButton("Clean", 24, 610, 75, 25)
$Label1 = GUICtrlCreateLabel("Clean Corrupt Mount Points", 104, 610, 69, 33)
GUISetState(@SW_SHOW)

$Run = Run(@ComSpec & " /c Dism.exe /Get-MountedImageInfo", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;<<<<<<<<<<<<<<<<<<This works
ProcessWaitClose($Run, 2)
$data = StdoutRead($Run)
GUICtrlSetData($T1Edit2, $data)
GUICtrlSetData($T2Edit1, $data)
GUICtrlSetData($T3Edit1, $data)

$aRun = Run(@ComSpec & " /k Dism.exe /Get-ImageInfo /ImageFile:C:\test\boot.wim") ;<<<<<<<<<<This works same as line 154

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button1
            If FileExists("newdism.exe") Then
                $sFileOld = "newdism.exe"
                $sFileRenamed = "dism.exe"
                FileMove($sFileOld, $sFileRenamed)
            EndIf
            Exit
        Case $Button2
            Run(@ComSpec & " /c Dism.exe /Cleanup-Mountpoints && Pause") ;<<<<<<<<<<<<<<<<This works
            ; If the value is between the 2 dummy ControlID on this tab
        Case $iStart_0 To $iEnd_0
            ; The control must have been on this tab
            _Tab_0($nMsg)
        Case $iStart_1 To $iEnd_1
            _Tab_1($nMsg)
        Case $iStart_2 To $iEnd_2
            _Tab_2($nMsg)
    EndSwitch
WEnd

; Run the actions for controls on this tab
Func _Tab_0($nMsg)
    Switch $nMsg
        Case $T1Button1
            $of_T1Button1 = FileOpenDialog("Select WIM File : """, @HomeDrive, """WIM Files (*.wim)", 1, "")
            GUICtrlSetData($T1Input1, $of_T1Button1)
            If FileExists("dism.exe") Then
                $sFileOld = "dism.exe"
                $sFileRenamed = "newdism.exe"
                FileMove($sFileOld, $sFileRenamed)
            EndIf

            $aRun = Run(@ComSpec & " /k Dism.exe /Get-ImageInfo /ImageFile:C:\test\boot.wim") ;<<<<<<<<<<This line doesn't work

            ;$aRun = Run(@ComSpec & " /c Dism.exe /Get-ImageInfo /ImageFile:""" & GUICtrlRead($T1Input1), "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
            ;ProcessWaitClose($aRun, 2)
            ;$aOutput = StdoutRead($aRun)
            ;GUICtrlSetData($T1Edit1, $aOutput)
            ;MsgBox(262144, "Wim Info", $aOutput)
        Case $T1Button2
            $of_T1Button2 = FileSelectFolder("Select Mount Folder", "")
            GUICtrlSetData($T1Input2, $of_T1Button2)
            $bRun = Run(@ComSpec & " /c Dism.exe /Get-MountedImageInfo", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;<<<<<<<<<<This line works
            ProcessWaitClose($bRun, 2)
            $bdata = StdoutRead($bRun)
            GUICtrlSetData($T1Edit2, $bdata)
            GUICtrlSetData($T2Edit1, $bdata)
        Case $T1Button3
Edited by trashy
Link to comment
Share on other sites

The entire script is over 400 lines and will probably double in size when complete.

I chopped off the first 108 lines, focus is on lines 116 and 153

I can run line 116 by itself in any script and it works but wrap it in a switch, line 153,

and it calls dism from system32 dir instead of script folder.

$Run = Run(@ComSpec & " /c Dism.exe /Get-MountedImageInfo", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;<<<<<<<<<<<<<<<<<<This works
ProcessWaitClose($Run, 2)
$data = StdoutRead($Run)
GUICtrlSetData($T1Edit2, $data)
GUICtrlSetData($T2Edit1, $data)
GUICtrlSetData($T3Edit1, $data)

$aRun = Run(@ComSpec & " /k Dism.exe /Get-ImageInfo /ImageFile:C:\test\boot.wim") ;<<<<<<<<<<This works same as line 154

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button1
            If FileExists("newdism.exe") Then
                $sFileOld = "newdism.exe"
                $sFileRenamed = "dism.exe"
                FileMove($sFileOld, $sFileRenamed)
            EndIf
            Exit
        Case $Button2
            Run(@ComSpec & " /c Dism.exe /Cleanup-Mountpoints && Pause") ;<<<<<<<<<<<<<<<<This works
            ; If the value is between the 2 dummy ControlID on this tab
        Case $iStart_0 To $iEnd_0
            ; The control must have been on this tab
            _Tab_0($nMsg)
        Case $iStart_1 To $iEnd_1
            _Tab_1($nMsg)
        Case $iStart_2 To $iEnd_2
            _Tab_2($nMsg)
    EndSwitch
WEnd

; Run the actions for controls on this tab
Func _Tab_0($nMsg)
    Switch $nMsg
        Case $T1Button1
            $of_T1Button1 = FileOpenDialog("Select WIM File : """, @HomeDrive, """WIM Files (*.wim)", 1, "")
            GUICtrlSetData($T1Input1, $of_T1Button1)
            If FileExists("dism.exe") Then
                $sFileOld = "dism.exe"
                $sFileRenamed = "newdism.exe"
                FileMove($sFileOld, $sFileRenamed)
            EndIf

            $aRun = Run(@ComSpec & " /k Dism.exe /Get-ImageInfo /ImageFile:C:\test\boot.wim") ;<<<<<<<<<<This line doesn't work
;>>>>>>>>>>>>>> The line above was to test my theory the 5 lines below are what should be <<<<<<<<<<<<<<<<<<<<;
            ;$aRun = Run(@ComSpec & " /c Dism.exe /Get-ImageInfo /ImageFile:""" & GUICtrlRead($T1Input1), "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
            ;ProcessWaitClose($aRun, 2)
            ;$aOutput = StdoutRead($aRun)
            ;GUICtrlSetData($T1Edit1, $aOutput)
            ;MsgBox(262144, "Wim Info", $aOutput)
        Case $T1Button2
            $of_T1Button2 = FileSelectFolder("Select Mount Folder", "")
            GUICtrlSetData($T1Input2, $of_T1Button2)
            $bRun = Run(@ComSpec & " /c Dism.exe /Get-MountedImageInfo", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;<<<<<<<<<<This line works
            ProcessWaitClose($bRun, 2)
            $bdata = StdoutRead($bRun)
            GUICtrlSetData($T1Edit2, $bdata)
            GUICtrlSetData($T2Edit1, $bdata)
        Case $T1Button3
Edited by trashy
Link to comment
Share on other sites

just a guess  ... reading data from StdoutRead after the process has closed is not o good idea
you may lose part of output doing so.
I suggest to use a loop like this instead:

$bRun = Run(@ComSpec & " /c Dism.exe /Get-MountedImageInfo", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
            $bdata = ""
            Do
                $bdata &= StdoutRead($bRun)
            Until @error
Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Went thru the entire script and changed all cmd lines to @ScriptDir.

I figured everything out all works great with one exception.

RunWait(@ComSpec & ' /k "' & @ScriptDir & '\Dism.exe /Image:""' & GUICtrlRead($T2Input0) & ' /Add-Driver /Driver:""' & GUICtrlRead($T2Input2) & ' /Recurse')

Recurse forces dism to search thru all sub folders, remove recurse and it works but that's not acceptable.

RunWait(@ComSpec & ' /k "' & @ScriptDir & '\Dism.exe /Image:""' & GUICtrlRead($T2Input0) & ' /Add-Driver /Driver:""' & GUICtrlRead($T2Input2))

Can any one help please.

Edited by trashy
Link to comment
Share on other sites

 

This works but won't accept spaces in fiolder names

RunWait(@ComSpec & ' /k "' & @ScriptDir & '\Dism.exe /Image:""' & GUICtrlRead($T2Input0) & ' /Add-Driver /Driver:""' & GUICtrlRead($T2Input2) & '" /Recurse')

 

Could you please post a real example of a command line working with quotes and so on?.

Because checking your last two post with RunWait and /Recurse, the final commands looks like this:

C:\Windows\system32\cmd.exe /k "C:\pathto\Dism.exe /Image:""c:\this is a test\test.img /Add-Driver /Driver:""d:\drivers here\ /Recurse

C:\Windows\system32\cmd.exe /k "C:\pathto\Dism.exe /Image:""c:\this is a test\test.img /Add-Driver /Driver:""d:\drivers here\" /Recurse

Cheers,

sahsanu

 

Edited by sahsanu
Link to comment
Share on other sites

I forgot to mention that if you want to avoid problems with spaces in files, paths... you could always convert a valid path to the short name 8.3 using function FileGetShortName so no more problems related to spaces ;-)

RunWait(@ComSpec & ' /k ' & FileGetShortName(@ScriptDir & "\Dism.exe") & ' /Image:' & FileGetShortName(GUICtrlRead($T2Input0)) & ' /Add-Driver /Driver:' & FileGetShortName(GUICtrlRead($T2Input2)) & ' /Recurse')
Link to comment
Share on other sites

  • Solution

I took this working command line with full file paths

RunWait('C:\Windows\system32\cmd.exe /k "C:\dism8\dism.exe /Image:""C:\mount /add-Driver "/Driver:C:\Optiplex 4"" /Recurse')

And one by one replaced with variables and came up with this.

RunWait(@ComSpec & ' /k "' & @ScriptDir & '""\Dism.exe /Image:""' & GUICtrlRead($T2Input0) & ' /add-Driver "/Driver:' & GUICtrlRead($T2Input2) & '"" /Recurse')

I learned something, next time I'll know how to approach this sort of problem.

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...