Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Script opens extra blank page

$
0
0

Hi all

I've sort of cobbled a few peoples scripts together I'm making for non-domain Windows 8 PCs in a domain environment. It asks for the username and password with not hassles, maps the network drives but then pops up with a blank script.

Can anyone see why it's doing this? Thanks!

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.TextBox")

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "DCPROMO AnswerFile Information"
$objForm.Size = New-Object System.Drawing.Size(455,365)
$objForm.StartPosition = "CenterScreen"
$FontBold = new-object System.Drawing.Font("Arial",8,[Drawing.FontStyle]'Bold' )

$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
    {$name=$objTextBox.Text;$pwd=$objTextBox2.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$objForm.Close()}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(120,285)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$name=$objTextBox.Text;$pwd=$objTextBox2.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(195,285)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(425,20)
$objLabel.Font = $fontBold
$objLabel.text = "Please enter your Username and Password"
$objForm.Controls.Add($objLabel)

$objLabel1 = New-Object System.Windows.Forms.Label
$objLabel1.Location = New-Object System.Drawing.Size(30,47)
$objLabel1.Size = New-Object System.Drawing.Size(60,20)
$objLabel1.Text = "Username:"
$objForm.Controls.Add($objLabel1)

$objLabel2 = New-Object System.Windows.Forms.Label
$objLabel2.Location = New-Object System.Drawing.Size(30,87)
$objLabel2.Size = New-Object System.Drawing.Size(60,20)
$objLabel2.Text = "Password:"
$objForm.Controls.Add($objLabel2)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(95,45)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$objTextBox2 = New-Object System.Windows.Forms.TextBox
$objTextBox2.Location = New-Object System.Drawing.Size(95,85)
$objTextBox2.PasswordChar = '*'
$objTextBox2.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox2)

$objForm.Topmost = $True
$handler = {$objForm.ActiveControl = $objTextBox}

$objForm.add_Load($handler)
$objForm.Add_Shown({$objForm.Activate()})
[Void] $objForm.ShowDialog()

$adapter = Get-WmiObject Win32_networkAdapterConfiguration | Where-Object { $_.IpEnabled }
$dns = $adapter.DNSDomain

net use x: /d
net use x: \\fs01\$name /USER:$name@$dns $pwd


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>