Question
Windows form
- kroum
- Auteur du sujet
- Hors Ligne
- Membre senior
-
Réduire
Plus d'informations
- Messages : 63
- Remerciements reçus 3
il y a 7 ans 5 mois #27913
par kroum
Windows form a été créé par kroum
Bonjour
j'ai un petit soucis sur un script
je cherche à créer des variables système et utilisateur
lorsque j'exécute mon code la fenêtre powershell se fige et je suis obligé de le tuer via le gestionnaire des tâches
je l'utilise depuis un windows.form
j'ai créer plusieurs boutons , tous les autres boutons fonctionnent, j'ai vérifié a plusieurs reprises je n'arrive pas a détecter l'erreur
lorsque je prends le contenu du bouton pour l'exécuter ailleurs que dans un windows form ça fonctionne
Pouvez vous m'aider SVP merci
voici le code
[code:1]
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\apllipresente.log\"
$log= \"D:\MPF\Install_MPF.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()
[/code:1]<br><br>Message édité par: kroum, à: 6/12/18 15:11
j'ai un petit soucis sur un script
je cherche à créer des variables système et utilisateur
lorsque j'exécute mon code la fenêtre powershell se fige et je suis obligé de le tuer via le gestionnaire des tâches
je l'utilise depuis un windows.form
j'ai créer plusieurs boutons , tous les autres boutons fonctionnent, j'ai vérifié a plusieurs reprises je n'arrive pas a détecter l'erreur
lorsque je prends le contenu du bouton pour l'exécuter ailleurs que dans un windows form ça fonctionne
Pouvez vous m'aider SVP merci
voici le code
[code:1]
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\apllipresente.log\"
$log= \"D:\MPF\Install_MPF.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()
[/code:1]<br><br>Message édité par: kroum, à: 6/12/18 15:11
Connexion ou Créer un compte pour participer à la conversation.
- Philippe
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 1778
- Remerciements reçus 21
il y a 7 ans 5 mois #27919
par Philippe
Réponse de Philippe sur le sujet Re:Windows form
salut
je comprend pas trop pourquoi mais il faut que tu remplace les [Environment]::SetEnvironmentVariable
pour l'environnement user
[code:1] #[Environment]::«»SetEnvironmentVariable(\"HOME1\", \"%LOCALAPPDATA%\CAO\", \"user\"«»)
Set-ItemProperty -Path 'HKCU:\Environment' -Name 'HOME1' -Value '%LOCALAPPDATA%\CAO'
[/code:1]
pour l'environnement machine
[code:1]# [System.Environment]::«»SetEnvironmentVariable(\"CAO_RACINE\", \"E:\$folder\", \"Machine\"«»)
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name 'CAO_RACINE' -Value 'E:\$folder'
[/code:1]
je comprend pas trop pourquoi mais il faut que tu remplace les [Environment]::SetEnvironmentVariable
pour l'environnement user
[code:1] #[Environment]::«»SetEnvironmentVariable(\"HOME1\", \"%LOCALAPPDATA%\CAO\", \"user\"«»)
Set-ItemProperty -Path 'HKCU:\Environment' -Name 'HOME1' -Value '%LOCALAPPDATA%\CAO'
[/code:1]
pour l'environnement machine
[code:1]# [System.Environment]::«»SetEnvironmentVariable(\"CAO_RACINE\", \"E:\$folder\", \"Machine\"«»)
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name 'CAO_RACINE' -Value 'E:\$folder'
[/code:1]
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.037 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Windows form