winforms - Display custom message while installation using powershell -
i unable figure out mistake doing.the following script call bunch of batch files , while batch files doing there job, progress shown in progress bar along name of script. want achieve display custom message during installation process. not able find out mistake, appreciated.
[system.reflection.assembly]::loadwithpartialname("system.windows.forms") | out-null [system.reflection.assembly]::loadwithpartialname("system.drawing") | out-null set-location $psscriptroot #call scripts installation $scriptshome = get-item '.\test\forps\*' #define form # init form $form = new-object system.windows.forms.form $form.width = 1000 $form.height = 200 $form.text = "** installation in progress-please not close window**" $form.font = new-object system.drawing.font("times new roman" ,12, [system.drawing.fontstyle]::regular) $form.minimizebox = $false $form.maximizebox = $false $form.windowstate = "normal" $form.startposition = "centerscreen" $form.opacity = .8 $form.backcolor = "gray" #define icon form $icon = new-object system.drawing.graphics (".\icon.jpg") $form.icon = $icon # init progressbar $progressbar = new-object system.windows.forms.progressbar $progressbar.maximum = $scriptshome.count $progressbar.minimum = 0 $progressbar.location = new-object system.drawing.size(10,70) $progressbar.size = new-object system.drawing.size(967,10) $form.controls.add($progressbar) $form.controls.add($messages) #running script name $label = new-object system.windows.forms.label $label.autosize = $true $label.location = new-object system.drawing.point(10,50) $form.controls.add($label) #define array messages #array $messages = @("preparing install patch set..preparing stop related processes", "upgrading application", "copying missing folder", "applying patch", "starting stopped services", "checkcing healthyness of system after installation may take half hour...", "rebooting server" ) $messages = new-object system.windows.forms.label $messages.autosize = $true $messages.location = new-object system.drawing.point(10,50) $form.controls.add($messages) # add_shown action $shownformaction = { $form.activate() foreach ($script in $scriptshome) { $progressbar.increment(1) #$messages.text = $messages[$messages] $label.text = "$($script.name)" start-process $script.fullname -wait -windowstyle hidden } $form.dispose() } $form.add_shown($shownformaction) # show form $form.showdialog()
thanks in advance.
you're reusing same variable name list of messages , label showing message itself:
$messages = @("preparing install patch set..preparing stop related processes", "upgrading application", "copying missing folder", "applying patch", "starting stopped services", "checkcing healthyness of system after installation may take half hour...", "rebooting server" ) $messages = new-object system.windows.forms.label $messages.autosize = $true $messages.location = new-object system.drawing.point(10,50)
rename 1 of them (ie. use $messagelabel
label):
$messagelabel = new-object system.windows.forms.label $messagelabel.autosize = $true $messagelabel.location = new-object system.drawing.point(10,50)
since increment progressbar
1 every step, can reuse progress bar value index $messages
array:
foreach ($script in $scriptshome) { $progressbar.increment(1) $messagelabel.text = $messages[$progressbar.value - 1] $label.text = "$($script.name)" start-process $script.fullname -wait -windowstyle hidden }
Comments
Post a Comment