Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName system.drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$terminatescript=$false
#création d'une form intitulé install MPF avec les dimensions
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '863,750'
$Form.text = "Install MPF"
$Form.TopMost = $True
#création des 4 boutons
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "1-Install the features"
$Button1.width = 209
$Button1.height = 83
$Button1.location = New-Object System.Drawing.Point(22,16)
$Button1.Font = 'Microsoft Sans Serif,10,style=Bold'
$Button2 = New-Object system.Windows.Forms.Button
$Button2.text = "2-Install a ressource"
$Button2.width = 209
$Button2.height = 83
$Button2.location = New-Object System.Drawing.Point(257,16)
$Button2.Font = 'Microsoft Sans Serif,10,style=Bold'
$Button3 = New-Object system.Windows.Forms.Button
$Button3.text = "3-Install the variables"
$Button3.width = 209
$Button3.height = 83
$Button3.location = New-Object System.Drawing.Point(500,16)
$Button3.Font = 'Microsoft Sans Serif,10,style=Bold'
$Button4 = New-Object system.Windows.Forms.Button
$Button4.text = "Validate"
$Button4.width = 209
$Button4.height = 30
$Button4.location = New-Object System.Drawing.Point(257,384)
$Button4.Font = 'Microsoft Sans Serif,10,style=Bold'
$Button5 = New-Object system.Windows.Forms.Button
$Button5.text = "Quit"
$Button5.width = 209
$Button5.height = 30
$Button5.location = New-Object System.Drawing.Point(22,550)
$Button5.Font = 'Microsoft Sans Serif,10,style=Bold'
#Création d'une case pour saisir du texte
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $false
$TextBox1.width = 200
$TextBox1.height = 20
$TextBox1.location = New-Object System.Drawing.Point(257,138)
$TextBox1.Font = 'Microsoft Sans Serif,10'
$TextBox2 = New-Object system.Windows.Forms.TextBox
$TextBox2.multiline = $false
$TextBox2.width = 200
$TextBox2.height = 20
$TextBox2.location = New-Object System.Drawing.Point(257,192)
$TextBox2.Font = 'Microsoft Sans Serif,10'
$TextBox3 = New-Object system.Windows.Forms.TextBox
$TextBox3.multiline = $false
$TextBox3.width = 200
$TextBox3.height = 20
$TextBox3.location = New-Object System.Drawing.Point(257,246)
$TextBox3.Font = 'Microsoft Sans Serif,10'
$TextBox4 = New-Object system.Windows.Forms.TextBox
$TextBox4.multiline = $false
$TextBox4.width = 200
$TextBox4.height = 20
$TextBox4.location = New-Object System.Drawing.Point(257,300)
$TextBox4.Font = 'Microsoft Sans Serif,10'
$TextBox5 = New-Object system.Windows.Forms.TextBox
$TextBox5.multiline = $false
$TextBox5.width = 200
$TextBox5.height = 20
$TextBox5.location = New-Object System.Drawing.Point(257,354)
$TextBox5.Font = 'Microsoft Sans Serif,10'
#Création de 3 barres de progression
$ProgressBar1 = New-Object system.Windows.Forms.ProgressBar
$ProgressBar1.width = 209
$ProgressBar1.height = 60
$ProgressBar1.location = New-Object System.Drawing.Point(22,462)
$ProgressBar1.Value = 0
$ProgressBar2 = New-Object system.Windows.Forms.ProgressBar
$ProgressBar2.width = 209
$ProgressBar2.height = 60
$ProgressBar2.location = New-Object System.Drawing.Point(257,462)
$ProgressBar3 = New-Object system.Windows.Forms.ProgressBar
$ProgressBar3.width = 209
$ProgressBar3.height = 60
$ProgressBar3.location = New-Object System.Drawing.Point(503,462)
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "Progress Bar"
$Label1.AutoSize = $true
$Label1.width = 50
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(22,442)
$Label1.Font = 'Microsoft Sans Serif,10'
$Label2 = New-Object system.Windows.Forms.Label
$Label2.text = "Enter the name of the shared ressource directory"
$Label2.AutoSize = $true
$Label2.width = 25
$Label2.height = 10
$Label2.location = New-Object System.Drawing.Point(257,114)
$Label2.Font = 'Microsoft Sans Serif,10,style=Bold'
$Label3 = New-Object system.Windows.Forms.Label
$Label3.text = "Enter the name of local group STD 3D"
$Label3.AutoSize = $true
$Label3.width = 25
$Label3.height = 10
$Label3.location = New-Object System.Drawing.Point(257,168)
$Label3.Font = 'Microsoft Sans Serif,10,style=Bold'
$Label4 = New-Object system.Windows.Forms.Label
$Label4.text = "Enter the name of local group ADM 3D"
$Label4.AutoSize = $true
$Label4.width = 25
$Label4.height = 10
$Label4.location = New-Object System.Drawing.Point(257,222)
$Label4.Font = 'Microsoft Sans Serif,10,style=Bold'
$Label5 = New-Object system.Windows.Forms.Label
$Label5.text = "Progress Bar"
$Label5.AutoSize = $true
$Label5.width = 25
$Label5.height = 10
$Label5.location = New-Object System.Drawing.Point(257,442)
$Label5.Font = 'Microsoft Sans Serif,10'
$Label6 = New-Object system.Windows.Forms.Label
$Label6.text = "Progress Bar"
$Label6.AutoSize = $true
$Label6.width = 25
$Label6.height = 10
$Label6.location = New-Object System.Drawing.Point(500,442)
$Label6.Font = 'Microsoft Sans Serif,10'
$Label7 = New-Object system.Windows.Forms.Label
$Label7.text = "Enter the name of Global group STD 3D"
$Label7.AutoSize = $true
$Label7.width = 25
$Label7.height = 10
$Label7.location = New-Object System.Drawing.Point(257,276)
$Label7.Font = 'Microsoft Sans Serif,10,style=Bold'
$Label8 = New-Object system.Windows.Forms.Label
$Label8.text = "Enter the name of Global group ADM 3D"
$Label8.AutoSize = $true
$Label8.width = 25
$Label8.height = 10
$Label8.location = New-Object System.Drawing.Point(257,324)
$Label8.Font = 'Microsoft Sans Serif,10,style=Bold'
$PictureBox1 = New-Object system.Windows.Forms.PictureBox
$PictureBox1.width = 466
$PictureBox1.height = 199
$PictureBox1.location = New-Object System.Drawing.Point(257,550)
$PictureBox1.imageLocation = "D:\MPF_CHINA\MPF.jpg"
$PictureBox1.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::zoom
$Form.controls.AddRange(@($Button1,$Button2,$Button3,$Button5,$ProgressBar1,$ProgressBar2,$ProgressBar3,$Label1,$Label5,$PictureBox1,$label6))
#code
$applipresentes="D:\MPF_CHINA\apllipresente.log"
$log= "D:\MPF_CHINA\Install_MPF_CAOSX.log"
del $log
$Button3.add_click(
{
#$folder=$textBox1.text
$folder="CAO10D"
<#$Form.controls.remove($label2)
$Form.controls.remove($TextBox1)
$Form.controls.remove($label3)
$Form.controls.remove($TextBox2)
$Form.controls.remove($label4)
$Form.controls.remove($TextBox3)
$Form.controls.remove($label7)
$Form.controls.remove($TextBox4)
$Form.controls.remove($label8)
$Form.controls.remove($TextBox5)
$Form.controls.remove($Button4)
#>
###Création de la variable HOME
[Environment]::SetEnvironmentVariable("HOME1", "%LOCALAPPDATA%\CAO", "user")
if ($? -eq "True")
{
$date=get-date
"$date" + " --> The variable HOME was created: OK" >> $log
$ProgressBar3.Value =20
$Label6.text=""
Sleep 1
$Label6.ForeColor="Green"
$Label6.text="The variable HOME was created"
Sleep 3
}
else {
$date=get-date
"$date" + "Thank you to create manually the variable HOME: KO" >> $log
$ProgressBar3.Value =20
$Label6.text=""
Sleep 1
$Label6.ForeColor="Red"
$Label6.text="Create manually the variable HOME"
Sleep 3
}
###Création de la variable CAO_RACINE############
[System.Environment]::SetEnvironmentVariable("CAO_RACINE", "E:\$folder", "Machine")
if ($? -eq "True")
{
$date=get-date
"$date" + " --> The variable CAO_RACINE was created: OK" >> $log
$ProgressBar3.Value =40
$Label6.text=""
Sleep 1
$Label6.ForeColor="Green"
$Label6.text="The variable CAO_RACINE was created"
Sleep 3
}
else {
$date=get-date
"$date" + "Thank you to create manually the variable CAO_RACINE: KO" >> $log
$ProgressBar3.Value =40
$Label6.text=""
Sleep 1
$Label6.ForeColor="Red"
$Label6.text="Create manually the variable CAO_RACINE"
Sleep 3
}
###Création de la variable CAD_SOFT############
[System.Environment]::SetEnvironmentVariable("CAD_SOFT", "E:\$folder", "Machine")
if ($? -eq "True")
{
$date=get-date
"$date" + " --> The variable CAD_SOFT was created" >> $log
$ProgressBar3.Value =60
$Label6.text=""
Sleep 1
$Label6.ForeColor="Green"
$Label6.text="The variable CAD_SOFT was created"
Sleep 3
}
else {
$date=get-date
"$date" + "Thank you to create manually the variable CAD_SOFT: KO" >> $log
$ProgressBar3.Value =60
$Label6.text=""
Sleep 1
$Label6.ForeColor="Red"
$Label6.text="Create manually the variable CAD_SOFT"
Sleep 3
}
###Modification de la variable path#####
[System.Environment]::SetEnvironmentVariable("PATH",$env:Path +";%CAD_SOFT%\logiciels\caoinit\root\script",'Machine')
if ($? -eq "True")
{
$date=get-date
"$date" + " --> The variable PATH was modified: OK " >> $log
$ProgressBar3.Value =80
$Label6.text=""
Sleep 1
$Label6.ForeColor="Green"
$Label6.text="The variable PATH was modified"
Sleep 3
}
else {
$date=get-date
"$date" + "Thank you to modify manually the variable PATH" >> $log
$ProgressBar3.Value =80
$Label6.text=""
Sleep 1
$Label6.ForeColor="Red"
$Label6.text="Modify manually the variable PATH"
Sleep 3
}
####Copier HOME.bat dans le menu démarrage"
Copy-Item "D:\MPF_CHINA\HOME.bat" 'C:\ProgramData\Microsoft\Windows\Start Menu\programs\startup'
if ($? -eq "True")
{
$date=get-date
"$date" + " --> The script home.bat was copied: OK " >> $log
$ProgressBar3.Value =100
$Label6.text=""
Sleep 1
$Label6.ForeColor="Green"
$Label6.text="The script home.bat was copied"
Sleep 3
$Label6.ForeColor="Green"
$Label6.text="Third step completed"
}
else {
"$date" + " Thank you for copying the script home.bat to C:\ProgramData\Microsoft\Windows\Start Menu\programs\
startup" >> $log
$ProgressBar2.Value =100
$Label6.text=""
Sleep 1
$Label6.ForeColor="Red"
$Label4.text="Copy the script home.bat to the startup directory "
Sleep 3
$Label6.ForeColor="Green"
$Label6.text="Third step completed"
}
#fin du bouton 3
})
$Button5.add_click(
{
$Form.close()
})
[void]$Form.ShowDialog()
|