Advertisement
xs4eyes

Software installer

Sep 16th, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Function install-fonts{
  2.         $FONTS = 0x14
  3.         $FromPath= #"Location to fonts"
  4.  
  5.         $objShell = New-Object -ComObject Shell.Application
  6.         $objFolder = $objShell.Namespace($FONTS)
  7.  
  8.         $CopyOptions = 4 + 16
  9.         $CopyFlag = [String]::Format("{0:x}", $CopyOptions)
  10.  
  11.  
  12.         foreach($File in $(Ls $Frompath)) {
  13.             If (test-path "c:\windows\fonts\$($file.name)")
  14.             {"Font already exists - not copying"}  #Useful for testing
  15.             Else
  16.             {
  17.                 $copyFlag = [String]::Format("{0:x}", $CopyOptions)
  18.                 "copying $($file.fullname)"           # Useful for debugging
  19.                 $objFolder.CopyHere($File.fullname, $CopyOptions)
  20.             }
  21.         }
  22.     }
  23.  
  24.     # input custom xml from visual studio here if you would like
  25.     $inputXML = @"
  26.    <Window
  27.       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  28.       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  29.       MinHeight="350"
  30.       Width="525"
  31.       SizeToContent="Height"
  32.       Title="PowerShell WPF Window"
  33.       Topmost="True">
  34.        <Grid x:Name="Computer_Setup">
  35.            <Grid.ColumnDefinitions>
  36.                <ColumnDefinition Width="30*"/>
  37.                <ColumnDefinition Width="30*"/>
  38.                <ColumnDefinition Width="30*"/>
  39.            </Grid.ColumnDefinitions>
  40.            <Grid.RowDefinitions>
  41.                <RowDefinition Height="20*"/>
  42.                <RowDefinition Height="Auto"/>
  43.                <RowDefinition Height="20*"/>
  44.            </Grid.RowDefinitions>
  45.            <TextBlock
  46.             x:Name="TextMessag"
  47.             HorizontalAlignment="Center"
  48.             VerticalAlignment="Center"
  49.             FontFamily="Consolas"
  50.             FontSize="20"
  51.             FontWeight="Bold"
  52.             Foreground="Blue" Margin="149,10,152,126" Text=" Software Installer" Grid.ColumnSpan="3" Width="216"/>
  53.            <Button
  54.             Name="Done"
  55.             Width="80"
  56.             Height="25"
  57.             Grid.Column="2"
  58.             Grid.Row="2"
  59.             HorizontalAlignment="Right"
  60.             Margin="10"
  61.             VerticalAlignment="Bottom">Done
  62.            </Button>
  63.            <Button x:Name="Ninite" Content="7FB" HorizontalAlignment="Left" Margin="10,58.019,0,0" VerticalAlignment="Top" Width="152" Grid.Column="1"/>
  64.            <Button x:Name="McAfee_Step_1" Content="McAfee Step 1" HorizontalAlignment="Left" Margin="10.333,59.04,0,0" VerticalAlignment="Top" Width="152"/>
  65.            <Button x:Name="Visual_Step_1" Content="Visual Step 1" HorizontalAlignment="Left" Margin="10.666,108.96,0,0" VerticalAlignment="Top" Width="152"/>
  66.            <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"/>
  67.            <Button x:Name="Office" Content="Microsoft Office" HorizontalAlignment="Left" Margin="10.334,84,0,0" VerticalAlignment="Top" Width="152" Grid.Column="1"/>
  68.            <Button x:Name="Activate" Content="Activate Windows" HorizontalAlignment="Left" Margin="10.334,108.96,0,0" VerticalAlignment="Top" Width="152" Grid.Column="1"/>
  69.            <Button x:Name="McAfee_Step_2" Content="McAfee Step 2" HorizontalAlignment="Left" Margin="10.333,84,0,0" VerticalAlignment="Top" Width="152"/>
  70.            <Button x:Name="Visual_Step_2" Content="Visual Step 2" HorizontalAlignment="Left" Margin="10.333,134.54,0,0" VerticalAlignment="Top" Width="152"/>
  71.            <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"/>
  72.            <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"/>
  73.            <Button x:Name="Word_Viewer" Content="Word Viewer" HorizontalAlignment="Left" Margin="10.333,82.979,0,0" VerticalAlignment="Top" Width="152" Grid.Column="2"/>
  74.            <Button x:Name="Excel_Viewer" Content="Excel Viewer" HorizontalAlignment="Left" Margin="10.333,108.96,0,0" VerticalAlignment="Top" Width="152" Grid.Column="2"/>
  75.        </Grid>
  76.    </Window>
  77.    "@      
  78.  
  79.     $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  80.  
  81.     [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  82.     [xml]$XAML = $inputXML
  83.     #Read XAML
  84.  
  85.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  86.     try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  87.     catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  88.  
  89.     #===========================================================================
  90.     # Load XAML Objects In PowerShell
  91.     #===========================================================================
  92.  
  93.     $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  94.  
  95.     Function Get-FormVariables{
  96.         if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  97.         write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  98.         get-variable WPF*
  99.     }
  100.  
  101.     Get-FormVariables
  102.  
  103.     #===========================================================================
  104.     # Actually make the objects work
  105.     #===========================================================================
  106.  
  107.     #Sample entry of how to add data to a field
  108.  
  109.     #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  110.  
  111.     #===========================================================================
  112.     # Shows the form
  113.     #===========================================================================
  114.     write-host "To show the form, run the following" -ForegroundColor Cyan
  115.     '$Form.ShowDialog() | out-null'
  116.  
  117.  
  118.  
  119.     ##################
  120.  
  121.  
  122.    
  123.     $WPFNinite.add_Click(
  124.         {invoke-item #"location to ninite installer"
  125.             [System.Object]$sender = $args[0]
  126.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  127.    
  128.         }
  129.     )
  130.  
  131.  
  132.  
  133.  
  134.     $WPFFonts.add_Click(
  135.         {
  136.             Install-fonts
  137.             [System.Object]$sender = $args[0]
  138.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  139.    
  140.         }
  141.     )
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.     $WPFActivate.add_Click(
  149.         {
  150.             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"
  151.             [System.Object]$sender = $args[0]
  152.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  153.    
  154.         }
  155.     )
  156.  
  157.  
  158.  
  159.  
  160.     $WPFOffice.add_Click(
  161.         {
  162.             Explorer #location to folder containing our office installs
  163.             Explorer #location to folder containing our office keys
  164.    
  165.             [System.Object]$sender = $args[0]
  166.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  167.    
  168.         }
  169.     )
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.     $WPFVisual_Step_1.add_Click(
  177.         {
  178.             Invoke-Item # location to custom program  
  179.             [System.Object]$sender = $args[0]
  180.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  181.    
  182.         }
  183.     )
  184.  
  185.    
  186.     $WPFVisual_Step_2.add_Click(
  187.         {
  188.             Invoke-Item #location to custom program 2  
  189.             [System.Object]$sender = $args[0]
  190.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  191.    
  192.         }
  193.     )
  194.  
  195.     $WPFVisual_Step_3.add_Click(
  196.         {
  197.             Invoke-Item # Location to custom program 3
  198.             Invoke-Item # Location to custom program 4
  199.             [System.Object]$sender = $args[0]
  200.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  201.    
  202.         }
  203.     )
  204.  
  205.     $WPFMcAfee_Step_1.add_Click(
  206.         {
  207.             invoke-item # location to av installer 1          
  208.             [System.Object]$sender = $args[0]
  209.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  210.    
  211.         }
  212.     )
  213.  
  214.     $WPFMcAfee_Step_2.add_Click(
  215.         {        
  216.             invoke-item # location to av installer 2
  217.             [System.Object]$sender = $args[0]
  218.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  219.    
  220.         }
  221.     )
  222.  
  223.  
  224.     # Setup auto login
  225.     $WPFBarcode_Auto_Login.add_Click(
  226.         {        
  227.             $test = Get-ItemProperty -Path $regpath | Select-Object -ExpandProperty AutoAdminLogon
  228.            
  229.             $MessageboxTitle = “Confirm”
  230.             $Messageboxbody = “The value of the AutoAdminLogon key is now $test. Please confirm you want to change this.”
  231.             $MessageIcon = [System.Windows.MessageBoxImage]::Warning
  232.             $ButtonType = [System.Windows.MessageBoxButton]::OkCancel
  233.                
  234.             $chioce = [System.Windows.MessageBox]::Show($Messageboxbody,$MessageboxTitle,$ButtonType,$MessageIcon)
  235.             IF($chioce -eq "Ok"){
  236.                 [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
  237.                 $computername = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a computer name", "Computer", "$env:computername")
  238.  
  239.                 Enter-PSSession -ComputerName $computername -ErrorAction SilentlyContinue
  240.  
  241.                 Function Test-RegistryValue {
  242.                     Param (
  243.                         [parameter(Mandatory=$true)]
  244.                         [ValidateNotNullOrEmpty()]$Path,
  245.                         [parameter(Mandatory=$true)]
  246.                     [ValidateNotNullOrEmpty()]$Value)
  247.                     try {
  248.                         Get-ItemProperty -Path $Path -ErrorAction Stop | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null
  249.                         return $true
  250.                     }
  251.                     catch {
  252.                         return $false
  253.                     }
  254.                 }
  255.  
  256.                 $regpath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
  257.                 $DefaultDomainname =# "domain name"
  258.                 $DefaultUsername = # "username"
  259.                 $DefaultPassword = # "Password"
  260.        
  261.        
  262.                 $testddn = Test-RegistryValue -path $regpath -Value DefaultDomainName
  263.                 if($testddn = $false){
  264.                     New-Item -path $regpath -name "DefaultDomainName"
  265.                 }
  266.                 New-ItemProperty -Path $regpath -name "DefaultDomainName" -PropertyType String -Value $DefaultDomainname -Force
  267.                
  268.                 $testDUN = Test-RegistryValue -path $regpath -Value DefaultUsername
  269.                 if($testDUN = $false){
  270.                 New-Item -path $regpath -name "DefaultUsername"}
  271.                 New-ItemProperty -Path $regpath -name "DefaultUsername" -PropertyType String -Value $DefaultUsername -Force
  272.          
  273.                 $testPWD = Test-RegistryValue -path $regpath -Value DefaultPassword
  274.                 if($testPWD = $false){
  275.                 New-Item -path $regpath -name "DefaultPassword"}
  276.                 New-ItemProperty -Path $regpath -name "DefaultPassword" -PropertyType String -Value $DefaultPassword -Force
  277.          
  278.                 $testAAl =  Test-RegistryValue -path $regpath -Value AutoAdminLogon
  279.                 if($testPWD = $false){
  280.                 New-Item -path $regpath -name "AutoAdminLogon"}
  281.                 New-ItemProperty -Path $regpath -name "AutoAdminLogon" -PropertyType String -Value 1 -Force        
  282.        
  283.                 Exit-PSSession
  284.                 [System.Object]$sender = $args[0]
  285.                 [System.Windows.RoutedEventArgs]$e = $args[1]  
  286.                 }
  287.          
  288.                 $test = Get-ItemProperty -Path $regpath | Select-Object -ExpandProperty AutoAdminLogon
  289.            
  290.                 $MessageboxTitle = “Test pop-up message title”
  291.                 $Messageboxbody = “The value of the AutoAdminLogon key is now $test
  292.                 $ButtonType = [System.Windows.MessageBoxButton]::Ok
  293.                
  294.                 [System.Windows.MessageBox]::Show($Messageboxbody,$MessageboxTitle,$ButtonType)
  295.        
  296.            
  297.    
  298.         }
  299.     )
  300.  
  301.     $WPFWord_Viewer.add_Click(
  302.         {
  303.          
  304.             [System.Object]$sender = $args[0]
  305.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  306.    
  307.         }
  308.     )
  309.  
  310.     $WPFExcel_Viewer.add_Click(
  311.         {
  312.          
  313.             [System.Object]$sender = $args[0]
  314.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  315.    
  316.         }
  317.     )
  318.  
  319.     $WPFDone.add_Click(
  320.         {
  321.             $Form.Close()
  322.             [System.Object]$sender = $args[0]
  323.             [System.Windows.RoutedEventArgs]$e = $args[1]  
  324.    
  325.         }
  326.     )
  327.  
  328.  
  329.     $Form.ShowDialog() | out-null
  330.  
  331.     $WPFDone.add_Click | get-member
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement