"Marco Shaw [MVP]" wrote:
>
> > #show Form
> > $form.Add_Shown({
> > $script:dt = (&$scriptBlock | out-dataTable)
> > $script
G.DataSource = $DT.psObject.baseobject
> > $Rows.Text="[Rows:$($script:dt.rows.count)]"
> > $dg.AutoResizeColumns()
> > $form.Activate()
> > })
> >
> > $form.showdialog()
> > } >
> Can you share your entire code or is that a problem?
>
> Marco
> No, not a problem. I have replaced certain parts of the code, as it's work
related and I'm not allowed to disclose that information. I've tried to
|Out-Null way and it doesn't seem to have an effect. Any suggestions???
Here is the entire script.
#region variables
$erroractionpreference = "SilentlyContinue"
$strComputer = (Get-Content env:COMPUTERNAME) # Store computer name
$root = [ADSI]"LDAP://RootDSE" #
$strDomain = $root.Get("rootDomainNamingContext") # Connect to Active
Directory
$strInsPath = pwd # Store local working directory
$strLogDetails = "Started main installation routine"
##################################################################################
##################################################################################
# Start of engineer editable variables
#
$strProductName = "Application Name"
$strCommand = cd "d:\Application"
$strArg = msiexec /i "Application.msi"
# End of engineer editable variables
#
##################################################################################
##################################################################################
$strLogFile = "Log File Location"
$strOldLogFile = "Old Log File Location"
#endregion
#region functions
# load WinForms
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
# create form
$form = New-Object Windows.Forms.Form
$form.text = "Form Name"
$form.top = 10
$form.left = 10
$form.height = 130
$form.width = 275
# create label
$label = New-Object Windows.Forms.Label
$label.text = "Domain Name"
$label.height = 30
$label.width = 75
$label.top = 2
$label.left = 25
$form.controls.add($label)
# create button
$button = New-Object Windows.Forms.Button
$button.add_click({onPress})
$button.text = "OK"
$button.height = 20
$button.width = 50
$button.top = 60
$button.left = 100
$form.controls.add($button)
# create radiobutton
$RadioButton = New-Object Windows.Forms.radiobutton
$RadioButton.text = "Button Text"
$RadioButton.height = 20
$RadioButton.width = 150
$RadioButton.top = 2
$RadioButton.left = 100
$form.controls.add($RadioButton)
# create radiobutton1
$radiobutton1 = New-Object Windows.Forms.radiobutton
$RadioButton1.text = "Button Text"
$RadioButton1.height = 20
$RadioButton1.width = 150
$RadioButton1.top = 30
$RadioButton1.left =100
$form.controls.add($RadioButton1)
# create event handler for button
$event = {
$form.Close()
}
# attach event handler
$button.Add_Click($event)
# attach controls to form
$form.controls.add($button)
$form.controls.add($label)
$form.controls.add($textbox)
$form.showdialog()
function filecheck {
param ($chkpath)
if ((Test-Path $chkpath) -eq $false) {
updatelog "$chkpath NOT FOUND!!!"
finish 1
}
}
function logfilecheck {
if ((Test-Path $strLogFile) -eq $true) {
if ((Test-Path $strOldLogFile) -eq $false) {
md $strOldLogFile
}
Move-Item -force $strLogFile LogFileName.log
}
}
function finish { # finishes the script and outputs an appropriate message
param ($iserror)
if ($iserror -eq 1)
{
$Date = Get-Date
cls
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $strLogFile
"***ERROR: Installation aborted! $Date" >> $strLogFile
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $strLogFile
exit 1 # returns $False to indicate error if needed
}
else
{
$Date = Get-Date
cls
$host.ui.rawui.windowtitle = "Installation Finished."
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $strLogFile
"***INFO: Installation completed successfully! $Date" >> $strLogFile
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $strLogFile
exit 1
}
function errorcheck {
###################################################################################
# This function checks for errors in the previous command and the logfile
entry #
# is updated
#
###################################################################################
if (!$?) {
updatelog "$Error.ErrorDetails"
finish 1
}
}
function updatelog {
###################################################################################
# This function updates the install log
#
###################################################################################
param($strLogMessage)
$strdate = date
$strMessage = "$strdate" + " " + "$strLogMessage"
$strMessage >> $strLogFile
}
function startinstall {
###################################################################################
# This function runs the installation command line
#
###################################################################################
param($strCommand ,$strArg)
updatelog "Executing $strCommand"
#cd ..
#$strCommand = "$strInsPath" + "\" + "$strExeFile" # Concatenate full path
to installation executable
$shell = New-Object -comObject Shell.Application #
$shell.ShellExecute("$strCommand","$strArg") # Running installation program
errorcheck
updatelog "$strCommand has been executed"
}
#endregion
#region Constructor
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
#endregion
#Region Main code
updatelog "Beginning installation of $strProductName"
logfilecheck
filecheck $strCommand # Check that file exits
if ($strCommand -gt 0) {
startinstall $strCommand $strArg
}
#show Form
$form.Add_Shown({
$script:dt = (&$scriptBlock | out-dataTable)
$script

G.DataSource = $DT.psObject.baseobject
$Rows.Text="[Rows:$($script:dt.rows.count)]"
$dg.AutoResizeColumns()
$form.Activate()
})
$form.showdialog() | Out-Null
}
$add = $doc.getElementByID("RadioButton")
$add = $doc.getElementByID("RadioButton1")
$add.checked = $true
finish 0
#endregion