; ENVIRONMENT
;------------------------------------------------
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn  ; Enable warnings to assist with detecting common errors.
;DetectHiddenWindows, On
#SingleInstance, Force
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%   ; Ensures a consistent starting directory.
;SetKeyDelay, 500
CoordMode, ToolTip, Screen
CoordMode, Mouse, Screen
;#NoTrayIcon
;Menu, Tray, Icon, ..\Icons\ICONNAMEHERE
; #Include, %A_ScriptDir%\Installs\Autohotkey\RunCMD.ahk
; Notes/Extra Info/#Includes
;------------------------------------------------
StartScriptAsAdmin()

; Set working directory depending on if \\smb is available
; if()
; Msgbox % "A_ScriptName: " A_ScriptName


if(InStr(A_ScriptName, ".ahk")){
   SetWorkingDir, %A_ScriptDir% 
}
else, {
    if(FileExist("\\smb\Toolbox\"))
    SetWorkingDir,\\smb\Toolbox\
    else,
    SetWorkingDir, %A_ScriptDir%

}

; Msgbox % "WorkingDir: " WorkingDir

PSToolbox_FN = PowershellToolbox.ps1
PowerShell_Toolbox_FP = %A_WorkingDir%\Installs\PowerShell\%PSToolbox_FN%

; Upgrade_Chocolatey_FN = Upgrade_Chocolatey.ps1
Upgrade_Chocolatey_FP = %A_WorkingDir%\Installs\PowerShell\Upgrade_Chocolatey.ps1



StaticIP_FN = SetStaticIPAddress.ps1
StaticIP_Destination_FP = %A_WorkingDir%\Installs\PowerShell\%StaticIP_FN%

; RenamePC_FN = RenamePC.ps1
; RenamePC_Destination_FP = %A_WorkingDir%\Installs\PowerShell\%RenamePC_FN%




Argument = %1%
if(Argument = "UpdateWindows"){
    Gosub, UpdateWindowsNow
    ExitApp
}

; IniRead, %A_ScriptDir%
IniRead, GUIVersion,%A_ScriptDir%\Installs\Misc\Toolbox-Settings.ini, General,Version, %A_Space% ; , Key [, Default]
GUI_Title = Windows Toolbox - v%GUIVersion%


if(FileExist("C:\Windows-Setup.log"))
FileRead, LogText, C:\Windows-Setup.log
else, 
LogText = Reminders: `nSet BIOS Primary AC Profile if this is a laptop

; if(!FileExist("Installs"))
; FileCreateDir, %A_WorkingDir%\Installs

; FileInstall, FreshInstallSetup.ps1, %PowerShell_Toolbox_FP%, 1
; FileInstall, SetStaticIPAddress.ps1, %StaticIP_Destination_FP%, 1
; FileInstall, RenamePC.ps1, %RenamePC_Destination_FP%, 1


/*
; add script to boot if ity user and not IT desktop
if(A_Username = "ity" and InStr(A_ScriptFullPath, ".exe")){
    if(A_ComputerName != "MGMT-3060" and A_ComputerName != "MGMT-7030"){
        FileCreateShortcut, %A_ScriptFullPath%, C:\Users\ity\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\%A_ScriptName%.lnk ; [, WorkingDir, Args, Description, IconFile, ShortcutKey, IconNumber
    }
}

*/


; VARIABLES
;------------------------------------------------
; Get logged in user's username for ShareX profile copy
strComputer := "."
strNamespace := "\root\cimv2"

objWMI := ComObjGet("winmgmts:\\"  strComputer  strNamespace)
colCS := objWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem")

For objSession in colCS
{
    ; MsgBox, % "User: " objSession.UserName
    LoggedInUsername := objSession.UserName
    if(InStr(LoggedInUsername, "\")){
        LoggedInUsername := StrSplit(LoggedInUsername, "\")[2]

    }
}


; Msgbox % "LoggedInUsername: " LoggedInUsername

; read settings from last runs
SettingsFileFP = C:\ProgramData\Windows-Toolbox-Settings.ini

IniRead, LastWindowsUpdate, %SettingsFileFP%, Toolbox, WindowsUpdate, %A_Space%
(LastWindowsUpdate = "Done")?(WindowsUpdateCheckStatus := 0):(WindowsUpdateCheckStatus := 1)



; https://www.autohotkey.com/boards/viewtopic.php?t=70884
; https://ss64.com/nt/syntax-settings.html
; Open up Windows Update and check for updates
; Run ms-settings:windowsupdate-action

; -------------------------------GUI Variables-------------------------------
Margin := 10
VerticalMargin := 20
gui, Margin, %Margin%, 2

ColumnOneXPos := 10
vertical_line_height = 500

ColumnOneHeaderWidth := 200
ColumnTwoHeaderWidth := 200
ColumnThreeHeaderWidth := 315
ColumnFourHeaderWidth := 315

; ColumnOneHeaderWidth 

ColumnOneVerticalLineXPos := ColumnOneHeaderWidth + ColumnOneXPos + 10


ColumnTwoXPos := ColumnOneVerticalLineXPos + Margin
Column_Two_Vertical_line_x_Pos := ColumnTwoXPos + ColumnTwoHeaderWidth + Margin


Column_Three_Vertical_line_x_Pos := ColumnTwoXPos + ColumnTwoHeaderWidth + Margin
ColumnThreeXPos := Column_Three_Vertical_line_x_Pos + Margin 


Column_Four_Vertical_line_x_Pos := ColumnThreeXPos + ColumnThreeHeaderWidth + Margin
ColumnFourXPos := Column_Four_Vertical_line_x_Pos + Margin 



ColumnTwoSubCheckboxesXPos := ColumnTwoXPos + 20

; MAIN SCRIPT
;------------------------------------------------


; GUI
; Default checkbox checks are set by the "CheckForNewMachineInstall" sub
;------------------------------------------------
Gui, Font, s17
Gui, Font, Bold
Gui, Add, Button, x%ColumnOneXPos% y0 w%ColumnOneHeaderWidth% h25, Chocolatey
gui, font, s10
Gui, Add, Button, x%ColumnOneXPos% w%ColumnOneHeaderWidth% h20 gUpgradeChocolatey, Upgrade Choco Packages
Gui, Font, s17
Gui, Font, Normal
Gui, Add, Checkbox, x%margin% yp+30 vChocolatey gUpdateGUI,Chocolatey
Gui, Add, Checkbox, x30 yp+30 vChocoAutoUpgrade gUpdateGUI, Auto Upgrade
; Gui, Add, Checkbox, vChocoAutoUpgrade gUpdateGUI checked, Auto Upgrade
; Gui, Add, Checkbox, x30 yp+30 vChocoUpgrade gUpdateGUI, Upgrade
Gui, Add, Checkbox, x%margin% y+5 vDellCU gUpdateGUI,Dell CU

Gui, Add, Checkbox, x10 y+5 vpdfxchange gUpdateGUI,PDF X-Change


; Gui, Add, Text,x20, Install Office 365
; Gui, Add, Checkbox, x120 yp+0 vOffice365_64 gUpdateGUI checked, 64bit

Gui, Add, Checkbox, x10 gUpdateGUI vShareX,ShareX
; gui, font, s10
; Gui, Add, Checkbox, x+%Margin% yp+5 vCustomShareXUser gUpdateGUI, Other User
; gui, font, s14
; Gui, Add, Checkbox, x30 yp+30 vShareXCurrentUser gUpdateGUI checked, Current User
; Gui, Add, Checkbox, x30 yp+30 vShareXCustomUserCheck gUpdateGUI,
; Gui, Add, Edit, vLoggedInUsername gupdateGUI checked x30 yp+30 xp+30 w150 h28, %LoggedInUsername%
gui, font, s17


Gui, Add, Checkbox, x10 gUpdateGUI vVoidtoolsEverything , Everything
Gui, Add, Checkbox, x30 yp+30 vVoidtoolsEverythingConfig  gUpdateGUI, Config

gui, font, s10
Gui, Font, Bold
Gui, Add, Button, x%ColumnOneXPos% w%ColumnOneHeaderWidth% y+20 h20, Optional Choco Packages
Gui, Font, Normal
gui, font, s17
Gui, Add, Checkbox, x10 gUpdateGUI vGoogleChrome,Google Chrome
Gui, Add, Checkbox, x10 gUpdateGUI vBitwarden,Bitwarden
Gui, Add, Checkbox, x10 vadobereader gUpdateGUI,Adobe Reader
Gui, Add, Checkbox, x10 gUpdateGUI vDrawIO,draw.io
Gui, Add, Checkbox, x10 vchocoZabbixAgent gUpdateGUI ,Zabbix Agent
Gui, Add, Checkbox, x10 gUpdateGUI vWireguard,Wireguard

gui, add, text, x%ColumnOneVerticalLineXPos% y0 h%vertical_line_height% 0x11   ;Vertical Line > Etched Gray

; COLUMN TWO
Gui, Font, s15
Gui, Font, Bold
Gui, Add, Button, x%ColumnTwoXPos% y0 w%ColumnTwoHeaderWidth% h25, MSI/EXE Installs
Gui, Font, Normal
Gui, Font, s17
Gui, Add, Checkbox, x%ColumnTwoXPos% yp+30 gUpdateGUI vOffice365_64 ,Office
Gui, Add, Checkbox, x+10 yp+0 gUpdateGUI vOffice365_32 gUpdateGUI, 32-bit
Gui, Add, Checkbox, x%ColumnTwoXPos% y+%margin% vMeshCentral gUpdateGUI , Mesh Central
Gui, Add, Checkbox, x%ColumnTwoXPos% vPrinterDrivers y+%margin% gUpdateGUI , Printer Drivers

gui, font, s10
Gui, Font, Bold
Gui, Add, Button, x%ColumnTwoXPos% w%ColumnTwoHeaderWidth% y+20 h20, Optional Packages
Gui, Font, Normal
gui, font, s17

Gui, Add, Checkbox, x%ColumnTwoXPos% y+%margin% vUrBackup gUpdateGUI, urBackup
Gui, Add, Checkbox, x%ColumnTwoXPos% gUpdateGUI y+%margin% vDWGSeePro,DWGSee
; Gui, Add, Checkbox, x%ColumnTwoXPos% gUpdateGUI y+%margin% vZabbixAgent,Zabbix Agent




gui, add, text, x%Column_Two_Vertical_line_x_Pos% y0 h%vertical_line_height% 0x11   ;Vertical Line > Etched Gray





; TWEAKS
gui, font, s17
Gui, Font, Bold
Gui, Add, Button, x%ColumnThreeXPos% y0 w%ColumnThreeHeaderWidth% h25, Tweaks
Gui, Font, Normal

Gui, Add, Checkbox, x%ColumnThreeXPos% yp+30 vUpdateWindows gUpdateGUI, Update Windows
Gui, Add, Checkbox, x%ColumnThreeXPos% y+1 vDebloat gUpdateGUI , Debloat
Gui, Add, Checkbox, vSaneWindowsUpdates gUpdateGUI , Sane Windows Updates
Gui, Add, Checkbox, vOOSU gUpdateGUI , Quiet 10 Privacy

Gui, Add, Checkbox, vDisableLockscreen gUpdateGUI, Disable Lockscreen
Gui, Add, Checkbox, vWallpaper gUpdateGUI, Set Wallpaper
Gui, Add, Checkbox, vCleanW11StartMenu gUpdateGUI , Clean Start Menu

Gui, Add, Checkbox, vChangeTimeout , Change Display Timeout
Gui, Add, Checkbox, vDisplayTime30 gUpdateGUI  yp+30 xp+%margin%, 30 Mins
Gui, Add, Checkbox, vDisplayTime0 yp+0 xp+120 gUpdateGUI, Never
Gui, Add, Checkbox, x%ColumnThreeXPos% vAddWifiNetwork gUpdateGUI x%ColumnThreeXPos% yp+30 , Configure Wifi
Gui, Add, Checkbox, x%ColumnThreeXPos% vDomainJoin gUpdateGUI x%ColumnThreeXPos% yp+30, Domain Join
Gui, Add, Checkbox, x%ColumnThreeXPos% vAutoLogon gUpdateGUI x%ColumnThreeXPos% yp+30, Autologon
; Gui, Add, Checkbox, vSetStaticIP gUpdateGUI x%ColumnThreeXPos% yp+40, IP:
; Gui, Add, Edit, vStaticIPAddress xp+60 w150 h28, 206.210.
; Gui, Font, s7
; Gui, Add, Button, x+5 gShowCurrentIP gShowCurrentIP,Current
; Gui, Font, s17
Gui, Add, Checkbox, vSetHostname gUpdateGUI x%ColumnThreeXPos% y+0, Hostname:
Gui, Add, Edit, vNewHostname xp+150 w150 h28,
Gui, Add, Checkbox, x%ColumnThreeXPos% vAddVPN gUpdateGUI x%ColumnThreeXPos% y+0, Add VPN
Gui, Font, s10

Gui, font, Red
Gui, Add, Checkbox, x+%Margin% yp+5 vEditVPNSettings gUpdateGUI cRed,Set rasphonepbk.ini

gui, font, s17
; Gui, Add, Checkbox, x%ColumnThreeXPos% y+%margin% vBGInfo gUpdateGUI,BGInfo
; gui, font, s13
; Gui, Add, Checkbox, x+%Margin% yp+4 vBGInfoBoot gUpdateGUI, On Boot
gui, font, s15
Gui, Add, Checkbox, x%ColumnThreeXPos% y+%margin% vRestartPCShortcut gUpdateGUI,Restart PC Shortcut
Gui, Add, Checkbox, x%ColumnThreeXPos% y+%margin% vExitPowerShell gUpdateGUI,Exit PS on Completion
Gui, Add, Checkbox, x%ColumnThreeXPos% y+%margin% vRestart gUpdateGUI,Restart PC (30s)
Gui, Add, Checkbox, x+10 yp+0 gUpdateGUI vRestartInstant gUpdateGUI, Instant



; Column FOUR
Gui, Font, s17
Gui, Font, Bold
gui, add, text, x%Column_Four_Vertical_line_x_Pos% y0 h%vertical_line_height% 0x11   ;Vertical Line > Etched Gray
Gui, Add, Button, x%ColumnFourXPos% y0 w%ColumnThreeHeaderWidth% h25 gPullUpdateLog, Logs
Gui, Font, Normal
Gui, Font, s15
Gui, Font, s7
Gui, Add, Edit, vLogText x%ColumnFourXPos% y+%margin% w%ColumnFourHeaderWidth% h300, %LogText%

Gui, Font, s15
Gui, Font, Bold
Gui, Add, Button, x%ColumnFourXPos% y+%margin% h35 w%ColumnFourHeaderWidth% gUpdateWindowsNow, Update Windows Now
Gui, Add, Button, w%ColumnFourHeaderWidth% gCheckForNewMachineInstall, Select for New Install
Gui, Add, Button, w%ColumnFourHeaderWidth% gUncheckAll, Uncheck All
Gui, Add, Button, w%ColumnFourHeaderWidth% gSubmit, Execute

; Gui, Add, Text, x+5,  Debloat

; Gui, Show, ;  w1230 ; , w600 h200
gui, Show,,%GUI_Title%

goto, CheckForNewMachineInstall

Return


ShowCurrentIP:
Command = ipconfig /all
; command = powershell (Get-NetIPAddress -AddressFamily IPV4 -InterfaceAlias Ethernet).IPAddress
CurrentIPAddress := RunCMD(command)
Hostname := RunCMD("hostname")
NetworkDetails := "Hostname: " . Hostname  . CurrentIPAddress
HostnameForFA := StrSplit(Hostname, "`r")[1]
; Clipboard := Hostname
; msgbox \\willow\Depts\IT\WindowsNetworking\%HostnameForFA%.txt
FileAppend, %NetworkDetails%, \\willow\Depts\IT\WindowsNetworking\%HostnameForFA%.txt
; Msgbox % "Hostname: " Hostname
; Clipboard := NetworkDetails
Msgbox % NetworkDetails
Return

PullUpdateLog:
FileRead, LogText, C:\Windows-Setup.log
GuiControl,,LogText, %LogText%
Return


UncheckAll:
GuiControl,,Debloat,0 
GuiControl,,OOSU,0 
GuiControl,,UblockEdge,0 
GuiControl,,ShareX,0 
GuiControl,,VoidtoolsEverything,0 
GuiControl,,VoidtoolsEverythingConfig,0
GuiControl,,Parcview,0 
GuiControl,,PVConfig,0 
GuiControl,,Chocolatey,0 
GuiControl,,DellCU,0 
GuiControl,,NoMachine,0 
GuiControl,,NoMachineConfig,0 
GuiControl,,pdfxchange,0 
GuiControl,,adobereader,0 
GuiControl,,Office,0 
GuiControl,,Office365_64,0 
GuiControl,,Office365_32,0 
GuiControl,,DisableLockscreen,0 
GuiControl,,Wallpaper,0 
GuiControl,,CleanW11StartMenu,0 
GuiControl,,UpdateWindows,0 
GuiControl,,ChangeTimeout,0 
GuiControl,,DisplayTime30,0 
GuiControl,,DisplayTime0,0 
GuiControl,,SaneWindowsUpdates,0 
GuiControl,,ChocoAutoUpgrade,0 
GuiControl,,DomainJoin,0 
GuiControl,,EditVPNrasphone,0 
GuiControl,,AddWifiNetwork,0 
GuiControl,,PrinterDrivers,0 
GuiControl,,urbackup,0 
GuiControl,,MeshCentral,0 

gui, Submit, NoHide
Return

CheckForNewMachineInstall:
GuiControl,,Debloat,1
GuiControl,,OOSU,1
GuiControl,,UblockEdge,0 
GuiControl,,Parcview,1 
GuiControl,,PVConfig,1 
GuiControl,,Chocolatey,1
GuiControl,,DellCU,1
; GuiControl,,NoMachine,1
; GuiControl,,NoMachineConfig,1
GuiControl,,pdfxchange,1
GuiControl,,MeshCentral,1
; GuiControl,,UrBackup,1
; GuiControl,,Office,1
GuiControl,,Office365_64,1
GuiControl,,Office365_32,0 
; GuiControl,,DisableLockscreen,1
GuiControl,,Wallpaper,0 
GuiControl,,CleanW11StartMenu,1 
GuiControl,,UpdateWindows,1
GuiControl,,ChangeTimeout,1
GuiControl,,DisplayTime30,1 
GuiControl,,DisplayTime0,0 
GuiControl,,SaneWindowsUpdates,1
GuiControl,,ChocoAutoUpgrade,1
GuiControl,,VoidtoolsEverything,1
GuiControl,,VoidtoolsEverythingConfig,1
GuiControl,,AddWifiNetwork,1
GuiControl,,PrinterDrivers,1
GuiControl,,ShareX,1
; GuiControl,,DellCU,0 
; GuiControl,,DellCU,0 

gui, Submit, NoHide

Return


UpdateGUI:
gui, Submit, NoHide
Return

UpgradeChocolatey:
Gui, Submit, NoHide
Run, PowerShell -NoExit -C "choco upgrade all -y"
Return

UpdateWindowsNow:

Arguments .= "UpdateWindows-chocoDellCU" ;  . "Restart"
IniRead, LastWindowsUpdate, %SettingsFileFP%, Toolbox, WindowsUpdate, %A_Tab% 
IniWrite, Done, %SettingsFileFP%, Toolbox, WindowsUpdate

Run, PowerShell -NoExit -C "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force; %PowerShell_Toolbox_FP% %Arguments%"

Return


Submit:
Gui, Submit, NoHide

Arguments := 


if(Debloat)
Arguments .= "Debloat"

if(SaneWindowsUpdates)
Arguments .= "SaneWindowsUpdates"

if(ChocoAutoUpgrade)
Arguments .= "ChocoAutoUpgrade"

if(Chocolatey)
Arguments .= "Chocolatey"

if(ChocoUpgrade)
Arguments .= "ChocoUpgrade"

if(DellCU)
Arguments .= "chocoDellCU"

if(pdfxchange)
Arguments .= "chocopdfxchange"

(adobereader)?(Arguments .= "chocoadobereader"):()


if(Office365_64 OR Office OR Office365_32){
    if(Office365_64)
    Arguments .= "Office365" 
    if(Office365_32)
    Arguments .= "Office32bit"
}


if(OOSU)
Arguments .= "OOSU"

(MeshCentral)?(Arguments .= "MeshCentral"):()
(UrBackup)?(Arguments .= "UrBackup"):()

if(NoMachine)
Arguments .= "chocoNoMachine-"

if(NoMachineConfig)
Arguments .= "NoMachineConfig"

if(Parcview)
Arguments .= "Parcview"

if(PVConfig)
Arguments .= "PVConfig"

if(DisableLockscreen)
Arguments .= "DisableLockscreen"

if(Wallpaper)
Arguments .= "Wallpaper"

if(UpdateWindows){
    Arguments .= "UpdateWindows"
    IniRead, LastWindowsUpdate, %SettingsFileFP%, Toolbox, WindowsUpdate, %A_Tab% 
    IniWrite, Done, %SettingsFileFP%, Toolbox, WindowsUpdate
    ; msgbox
}

if(CleanW11StartMenu){
    Arguments .= "CleanW11StartMenu"
}

if(DisplayTime0 and ChangeTimeout)
Arguments .= "DisplayTime0"

if(DisplayTime30 and ChangeTimeout)
Arguments .= "DisplayTime30"

if(AutoLogon)
Arguments .= "AutoLogon"

if(DomainJoin)
Arguments .= "DomainJoin"

if(AddWifiNetwork)
Arguments .= "AddWifiNetwork"


; if(Bitwarden)
; Arguments .= "Bitwarden"

(GoogleChrome)?(Arguments .= "choco-GoogleChrome"):()
(Bitwarden)?(Arguments .= "choco-Bitwarden"):()

(DrawIO)?(Arguments .= "choco-drawio"):()

(DWGSeePro)?(Arguments .= "DWGSeePro"):()

(ZabbixAgent)?(Arguments .= "ZabbixAgent"):()
(chocoZabbixAgent)?(Arguments .= "chocoZabbixAgent"):()


if(Wireguard)
Arguments .= "Wireguard"

; Msgbox % "arguments: " arguments

if(ShareX){
    Arguments .= "chocoShareX"
}

if(BGInfo){
    Arguments .= "BGInfo"
}

if(BGInfoBoot){
    Arguments .= "BGBootInfo"
}


if(EditVPNSettings){

 /*   Username := RunCMD("wmic computersystem get username")

    ; Regular expression pattern to match and pull out the username up to a new line character
    regexPattern := "WMPCO\\([^\r\n]+)"

    ; Perform the regex match
    if RegExMatch(Username, regexPattern, output)
    {
        ; Extracted username
        LoggedInUser := output1
        ; MsgBox % "Extracted Username: " extractedString
    }
    else
    {
        MsgBox, Failed to pull out the username from the returned CMD value.

    }
    */

    rasphonepbkwConfig_FP = \\smb\Toolbox\Installs\VPN\rasphone.pbk
    rasphonepbk_FP = C:\Users\%LoggedInUsername%\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk

    ; Msgbox % "rasphonepbkwConfig_FP: " rasphonepbkwConfig_FP
    ; Msgbox % "rasphonepbk_FP: " rasphonepbk_FP

    if(FileExist(rasphonepbk_FP)){

        ; filecopy does not work because the credentials are connected to the .pbk file and copying the file will make windows clear the credentials.

        IniRead, UseRasCredentials, %rasphonepbk_FP%, White Mountain Paper - VPN, UseRasCredentials, %A_Space%
        if(UseRasCredentials = ""){
            msgbox, rasphone.pbk file does not exist. Please make sure that the Windows VPN is named:`nWhite Mountain Paper - VPN
            Return
        }

        ; otherwise, iniwrite to file:
        ; IniWrite, Value, Filename, Section, Key
        IniWrite,0, %rasphonepbk_FP%, White Mountain Paper - VPN,UseRasCredentials
        IniRead, UseRasCredentials, %rasphonepbk_FP%, White Mountain Paper - VPN, UseRasCredentials, %A_Space%
        if(UseRasCredentials = 1 or UseRasCredentials = ""){
            ; Msgbox, Failed to edit the Rasphone.pbk file. CLick ok to open up the directory to do it manually.
            run, C:\Users\%LoggedInUsername%\AppData\Roaming\Microsoft\Network\Connections\Pbk
            Return
        }
        
        run, notepad.exe C:\Users\%LoggedInUsername%\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk
    }
    else, {
        msgbox, Error: Rasphone.pbk does not exist or it wasn't found at:`n%rasphonepbk_FP%
    }


    ; https://www.tenforums.com/tutorials/3123-clsid-key-guid-shortcuts-list-windows-10-a.html
    run, explorer shell:::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
    msgbox, Please Enable "Microsoft CHAP Version 2" under Security Settings of the VPN Property.

    ; FileCopy, %A_ScriptDir%\Installs\VPN\rasphone.pbk, C:\Users\%A_Username%\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk, 1 ;, Dest [, Flag (1 = overwrite)]
    ; rasphone_FP = C:\Users\%A_Username%\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk
    ; if(FileExist("rasphone_FP"))
}

if(UblockEdge){
    run, https://microsoftedge.microsoft.com/addons/detail/ublock-origin/odfafepnkmbhccpbejgmiehpchacaeak
}



if(VoidtoolsEverything)
Arguments .= "chocoVoidtoolsEverything"

if(VoidtoolsEverythingConfig)
Arguments .= "EverythingConfig"


; -- PRINTERS --
if(PrinterDrivers)
Arguments .= "PrinterDrivers"

if(Printer_MGMTSHARP)
Arguments .= "MGMTSHARP"

if(Printer_MGMTHPColor)
Arguments .= "Printer_MGMTHPColor"

if(Printer_TM06SUPICANONCOLOR)
Arguments .= "Printer_TM06SUPICANONCOLOR"


if(AddVPN){
    Send, {RWin}
    sleep, 500
    send, Add vpn
    sleep, 500
    send, {Enter}
    sleep, 2000
    send, {Enter} ; Click "Add VPN" button
    sleep, 1000

    ; within the Add VPN COnnection interface:
    send, {Down} ; down in case the "Windows (Built In)" option is not selected
    send, {Tab} ; tab down to connection name
    sleep, 1000
    send, White Mountain Paper - VPN
    send, {Tab}
    sleep, 1000
    send, 69.193.72.92

    send, {Tab}
    sleep, 1000
    send, {Down}{Down}{Down}{Down} ; select L2TP/IPSEC with pre-shared key
    send {Tab}
    sleep, 1000
    Key := "61vBoUGLZr/VrNlXpRQhFr4LdxfuYGFk"
    send, %Key%
}


/*if(PVConfig){ ; Instlal parcview and copy config files 
    ; run, %A_WorkingDir%\Installs\PARCview 5.0.0.6\PARCView Silent No Launch.msi

    FileCreateDir, C:\ProgramData\Capstone\PARCView
    FileCopy, %A_WorkingDir%\Installs\PARCview 5.0.0.6\PVConfig.XML, C:\ProgramData\Capstone\PARCView\PVConfig.XML, 1
}

*/
/*if(Office365_32){
    run, %A_WorkingDir%\Installs\Office365Setup_32BIT.exe
}
*/

; Clipboard := arguments
; Clipboard := PowerShell_Toolbox_FP
; Msgbox % "PowerShell_Toolbox_FP: " PowerShell_Toolbox_FP
; Msgbox % "arguments: " arguments

(Restart)?(Arguments .= "Restart"):()
(RestartInstant)?(Arguments .= "RestartInstant"):()


if(Arguments){
    if(ExitPowerShell)
    Run, PowerShell -C "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force; %PowerShell_Toolbox_FP% %Arguments% %NewHostname%"
    else, 
    Run, PowerShell -NoExit -C "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force; %PowerShell_Toolbox_FP% %Arguments% %NewHostname%"
}



SetTimer, PullUpdateLog, 10000

Return



GuiClose:       ;close Gui to Exit
GuiEscape:      ;press Esc to Exit
ExitApp




; Functions
;------------------------------------------------

StartScriptAsAdmin(){
    full_command_line := DllCall("GetCommandLine", "str")

    if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
        try {
            if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
            else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
        }
        ExitApp
    }

    if(!A_IsAdmin){
       Msgbox, failed to get admin. 
       Return
   }  
}