Last active
November 27, 2024 20:12
-
-
Save jumpyvi/b74414c5abe72523f7a51fa9f63f24b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Connecter-Samba { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNullOrEmpty()] | |
$nom, $mdp, $location_reseau | |
) | |
$command = "New-SmbMapping -LocalPath 'S:' -RemotePath '$location_reseau' -Username '$nom' -Password '$mdp'" | |
$lancer_msx = "Start-Process explorer.exe S:" | |
Write-Host "Lancement de net use ->: $command" | |
Invoke-Expression $command | |
Invoke-Expression $lancer_msx | |
} | |
function Annuler-Connections { | |
[CmdletBinding()] | |
param ( | |
$location_reseau | |
) | |
$commande_annule = "Remove-SmbMapping -RemotePath $location_reseau -Force -ErrorAction Stop" | |
Invoke-Expression $commande_annule | |
} | |
Add-Type -AssemblyName System.Windows.Forms | |
# Créer le dialogue de base | |
$form = New-Object System.Windows.Forms.Form | |
$form.Text = "SimbaConnector200" | |
$form.Icon = New-Object System.Drawing.Icon(".\simba.ico") | |
$form.Size = New-Object System.Drawing.Size(480, 200) | |
$form.StartPosition = "CenterScreen" | |
$pre_remplissage_path = "\\WIN-ILG0AIL0PU3.vincentgabriel.local\Global" | |
# Créer le input path | |
$label_path = New-Object System.Windows.Forms.Label | |
$label_path.Text = "Entrer votre path:" | |
$label_path.Location = New-Object System.Drawing.Point(10,0) | |
$label_path.AutoSize = $true | |
$form.Controls.Add($label_path) | |
$entre_path = New-Object System.Windows.Forms.TextBox | |
$entre_path.Location = New-Object System.Drawing.Point(10, 20) | |
$entre_path.Text = $pre_remplissage_path | |
$form.Controls.Add($entre_path) | |
# Mettre a "false pour le testage" | |
$entre_path.ReadOnly = $false | |
# Créer le input nom | |
$label_nom_utilisateur = New-Object System.Windows.Forms.Label | |
$label_nom_utilisateur.Text = "Entrer votre nom d'utilisateur:" | |
$label_nom_utilisateur.AutoSize = $true | |
$label_nom_utilisateur.Location = New-Object System.Drawing.Point(30, 60) | |
$form.Controls.Add($label_nom_utilisateur) | |
$entre_nom = New-Object System.Windows.Forms.TextBox | |
$entre_nom.Location = New-Object System.Drawing.Point(200, 60) | |
$entre_nom.Width = 200 | |
$form.Controls.Add($entre_nom) | |
# Créer le input mdp | |
$label_mdp = New-Object System.Windows.Forms.Label | |
$label_mdp.Text = "Entrer votre mot de passe:" | |
$label_mdp.AutoSize = $true | |
$label_mdp.Location = New-Object System.Drawing.Point(30, 90) | |
$form.Controls.Add($label_mdp) | |
$entre_mdp = New-Object System.Windows.Forms.TextBox | |
$entre_mdp.Location = New-Object System.Drawing.Point(200, 90) | |
$entre_mdp.UseSystemPasswordChar = $true | |
$entre_mdp.Width = $entre_nom.Width | |
$form.Controls.Add($entre_mdp) | |
# Créer le boutton annuler | |
$boutton_annuler = New-Object System.Windows.Forms.Button | |
$boutton_annuler.Text = "Annuler" | |
$boutton_annuler.Location = New-Object System.Drawing.Point(80, 120) | |
$boutton_annuler.Add_Click({ $entre_nom.Text = ""; $entre_mdp.Text = ""; $form.Close() }) | |
$form.Controls.Add($boutton_annuler) | |
# Créer le boutton OK | |
$boutton_ok = New-Object System.Windows.Forms.Button | |
$boutton_ok.Text = "OK" | |
$boutton_ok.Location = New-Object System.Drawing.Point(180, 120) | |
$boutton_ok.Add_Click({ $form.Close() }) | |
$form.Controls.Add($boutton_ok) | |
# Créer le boutton supprimer connexions | |
$boutton_ok = New-Object System.Windows.Forms.Button | |
$boutton_ok.Text = "Supprimer connexions existantes" | |
$boutton_ok.Location = New-Object System.Drawing.Point(125, 15) | |
$boutton_ok.Size = New-Object System.Drawing.Size(200, 30) | |
$boutton_ok.Add_Click({ Annuler-Connections -location_reseau $entre_path.Text }) | |
$form.Controls.Add($boutton_ok) | |
# Affiche le dialogue | |
$form.ShowDialog() | |
# Imprime le résultat si l'entré n'est pas vide | |
if ($entre_nom.Text -ne "" -and $entre_mdp.Text -ne "") { | |
Connecter-Samba -nom $entre_nom.Text -mdp $entre_mdp.Text -location_reseau $entre_path.Text | |
} else { | |
Write-Host "Erreur: vous devez entrer votre nom d'utilisateur et mot de passe." | |
} |
Author
jumpyvi
commented
Sep 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment