Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function install-fonts{
- $FONTS = 0x14
- $FromPath= #"Location to fonts"
- $objShell = New-Object -ComObject Shell.Application
- $objFolder = $objShell.Namespace($FONTS)
- $CopyOptions = 4 + 16
- $CopyFlag = [String]::Format("{0:x}", $CopyOptions)
- foreach($File in $(Ls $Frompath)) {
- If (test-path "c:\windows\fonts\$($file.name)")
- {"Font already exists - not copying"} #Useful for testing
- Else
- {
- $copyFlag = [String]::Format("{0:x}", $CopyOptions)
- "copying $($file.fullname)" # Useful for debugging
- $objFolder.CopyHere($File.fullname, $CopyOptions)
- }
- }
- }
- # input custom xml from visual studio here if you would like
- $inputXML = @"
- <Window
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- MinHeight="350"
- Width="525"
- SizeToContent="Height"
- Title="PowerShell WPF Window"
- Topmost="True">
- <Grid x:Name="Computer_Setup">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="30*"/>
- <ColumnDefinition Width="30*"/>
- <ColumnDefinition Width="30*"/>
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="20*"/>
- <RowDefinition Height="Auto"/>
- <RowDefinition Height="20*"/>
- </Grid.RowDefinitions>
- <TextBlock
- x:Name="TextMessag"
- HorizontalAlignment="Center"
- VerticalAlignment="Center"
- FontFamily="Consolas"
- FontSize="20"
- FontWeight="Bold"
- Foreground="Blue" Margin="149,10,152,126" Text=" Software Installer" Grid.ColumnSpan="3" Width="216"/>
- <Button
- Name="Done"
- Width="80"
- Height="25"
- Grid.Column="2"
- Grid.Row="2"
- HorizontalAlignment="Right"
- Margin="10"
- VerticalAlignment="Bottom">Done
- </Button>
- <Button x:Name="Ninite" Content="7FB" HorizontalAlignment="Left" Margin="10,58.019,0,0" VerticalAlignment="Top" Width="152" Grid.Column="1"/>
- <Button x:Name="McAfee_Step_1" Content="McAfee Step 1" HorizontalAlignment="Left" Margin="10.333,59.04,0,0" VerticalAlignment="Top" Width="152"/>
- <Button x:Name="Visual_Step_1" Content="Visual Step 1" HorizontalAlignment="Left" Margin="10.666,108.96,0,0" VerticalAlignment="Top" Width="152"/>
- <Button x:Name="Fonts" Content="Fonts" HorizontalAlignment="Left" Margin="10.666,24.96,0,0" VerticalAlignment="Top" Width="152" RenderTransformOrigin="-0.473,-1.238" Grid.Row="2"/>
- <Button x:Name="Office" Content="Microsoft Office" HorizontalAlignment="Left" Margin="10.334,84,0,0" VerticalAlignment="Top" Width="152" Grid.Column="1"/>
- <Button x:Name="Activate" Content="Activate Windows" HorizontalAlignment="Left" Margin="10.334,108.96,0,0" VerticalAlignment="Top" Width="152" Grid.Column="1"/>
- <Button x:Name="McAfee_Step_2" Content="McAfee Step 2" HorizontalAlignment="Left" Margin="10.333,84,0,0" VerticalAlignment="Top" Width="152"/>
- <Button x:Name="Visual_Step_2" Content="Visual Step 2" HorizontalAlignment="Left" Margin="10.333,134.54,0,0" VerticalAlignment="Top" Width="152"/>
- <Button x:Name="Visual_Step_3" Content="Visual Step 3" HorizontalAlignment="Left" Margin="10.333,0,0,0" VerticalAlignment="Top" Width="152" Grid.Row="2"/>
- <Button x:Name="Barcode_Auto_Login" Content="Barcode Auto Login" HorizontalAlignment="Left" Margin="10,58.019,0,0" VerticalAlignment="Top" Width="152" Grid.Column="2"/>
- <Button x:Name="Word_Viewer" Content="Word Viewer" HorizontalAlignment="Left" Margin="10.333,82.979,0,0" VerticalAlignment="Top" Width="152" Grid.Column="2"/>
- <Button x:Name="Excel_Viewer" Content="Excel Viewer" HorizontalAlignment="Left" Margin="10.333,108.96,0,0" VerticalAlignment="Top" Width="152" Grid.Column="2"/>
- </Grid>
- </Window>
- "@
- $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
- [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
- [xml]$XAML = $inputXML
- #Read XAML
- $reader=(New-Object System.Xml.XmlNodeReader $xaml)
- try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
- catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
- #===========================================================================
- # Load XAML Objects In PowerShell
- #===========================================================================
- $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
- Function Get-FormVariables{
- if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
- write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
- get-variable WPF*
- }
- Get-FormVariables
- #===========================================================================
- # Actually make the objects work
- #===========================================================================
- #Sample entry of how to add data to a field
- #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
- #===========================================================================
- # Shows the form
- #===========================================================================
- write-host "To show the form, run the following" -ForegroundColor Cyan
- '$Form.ShowDialog() | out-null'
- ##################
- $WPFNinite.add_Click(
- {invoke-item #"location to ninite installer"
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFFonts.add_Click(
- {
- Install-fonts
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFActivate.add_Click(
- {
- Start-Process -FilePath "https://microsoft.gointeract.io/mobileweb/?interaction=1443478049354-2924fcb582254ed49836617882f915015fecd10-64be&accountId=microsoft&appkey=fdd66706-ae19-4524-a9e5-440df6739dcd&Language=English&name=pana&Click%20To%20Call%20Caller%20Id=+13086272915&dnis=24"
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFOffice.add_Click(
- {
- Explorer #location to folder containing our office installs
- Explorer #location to folder containing our office keys
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFVisual_Step_1.add_Click(
- {
- Invoke-Item # location to custom program
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFVisual_Step_2.add_Click(
- {
- Invoke-Item #location to custom program 2
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFVisual_Step_3.add_Click(
- {
- Invoke-Item # Location to custom program 3
- Invoke-Item # Location to custom program 4
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFMcAfee_Step_1.add_Click(
- {
- invoke-item # location to av installer 1
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFMcAfee_Step_2.add_Click(
- {
- invoke-item # location to av installer 2
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- # Setup auto login
- $WPFBarcode_Auto_Login.add_Click(
- {
- $test = Get-ItemProperty -Path $regpath | Select-Object -ExpandProperty AutoAdminLogon
- $MessageboxTitle = “Confirm”
- $Messageboxbody = “The value of the AutoAdminLogon key is now $test. Please confirm you want to change this.”
- $MessageIcon = [System.Windows.MessageBoxImage]::Warning
- $ButtonType = [System.Windows.MessageBoxButton]::OkCancel
- $chioce = [System.Windows.MessageBox]::Show($Messageboxbody,$MessageboxTitle,$ButtonType,$MessageIcon)
- IF($chioce -eq "Ok"){
- [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
- $computername = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a computer name", "Computer", "$env:computername")
- Enter-PSSession -ComputerName $computername -ErrorAction SilentlyContinue
- Function Test-RegistryValue {
- Param (
- [parameter(Mandatory=$true)]
- [ValidateNotNullOrEmpty()]$Path,
- [parameter(Mandatory=$true)]
- [ValidateNotNullOrEmpty()]$Value)
- try {
- Get-ItemProperty -Path $Path -ErrorAction Stop | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
- return $true
- }
- catch {
- return $false
- }
- }
- $regpath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
- $DefaultDomainname =# "domain name"
- $DefaultUsername = # "username"
- $DefaultPassword = # "Password"
- $testddn = Test-RegistryValue -path $regpath -Value DefaultDomainName
- if($testddn = $false){
- New-Item -path $regpath -name "DefaultDomainName"
- }
- New-ItemProperty -Path $regpath -name "DefaultDomainName" -PropertyType String -Value $DefaultDomainname -Force
- $testDUN = Test-RegistryValue -path $regpath -Value DefaultUsername
- if($testDUN = $false){
- New-Item -path $regpath -name "DefaultUsername"}
- New-ItemProperty -Path $regpath -name "DefaultUsername" -PropertyType String -Value $DefaultUsername -Force
- $testPWD = Test-RegistryValue -path $regpath -Value DefaultPassword
- if($testPWD = $false){
- New-Item -path $regpath -name "DefaultPassword"}
- New-ItemProperty -Path $regpath -name "DefaultPassword" -PropertyType String -Value $DefaultPassword -Force
- $testAAl = Test-RegistryValue -path $regpath -Value AutoAdminLogon
- if($testPWD = $false){
- New-Item -path $regpath -name "AutoAdminLogon"}
- New-ItemProperty -Path $regpath -name "AutoAdminLogon" -PropertyType String -Value 1 -Force
- Exit-PSSession
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- $test = Get-ItemProperty -Path $regpath | Select-Object -ExpandProperty AutoAdminLogon
- $MessageboxTitle = “Test pop-up message title”
- $Messageboxbody = “The value of the AutoAdminLogon key is now $test”
- $ButtonType = [System.Windows.MessageBoxButton]::Ok
- [System.Windows.MessageBox]::Show($Messageboxbody,$MessageboxTitle,$ButtonType)
- }
- )
- $WPFWord_Viewer.add_Click(
- {
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFExcel_Viewer.add_Click(
- {
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $WPFDone.add_Click(
- {
- $Form.Close()
- [System.Object]$sender = $args[0]
- [System.Windows.RoutedEventArgs]$e = $args[1]
- }
- )
- $Form.ShowDialog() | out-null
- $WPFDone.add_Click | get-member
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement