Skip to content

Instantly share code, notes, and snippets.

@altrive
Last active March 18, 2024 12:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save altrive/5416163 to your computer and use it in GitHub Desktop.
Save altrive/5416163 to your computer and use it in GitHub Desktop.
Install and setup script for SysInternals tools(BGInfo/AutoLogon).

Summary

Install and setup script for SysInternals tools(BGInfo/AutoLogon).

Usage

Install-SysInternalsTool
Enable-AutoLogon -UserName "Test\Administrator" -Password "Password!"
Register-BGInfoStartup
#Install SysInternals BGInfo/AutoLogon tools
function Install-SysInternalsTool
{
#Target directory is %WinDir%C:\Windows\System32\SysInternals
$targetDir = Join-Path $env:WinDir "System32\SysInternals"
#Tools to be downloaded
$tools = @{
Bginfo = "http://live.sysinternals.com/Bginfo.exe"
Autologon = "http://live.sysinternals.com/Autologon.exe"
}
#Create Directory
Write-Verbose "Create Directory: $targetDir"
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
#Download tools to target directory
try{
$wc = New-Object System.Net.WebClient
foreach($tool in $tools.Values){
$filePath = Join-Path $targetDir ([IO.Path]::GetFileName($tool))
Write-Verbose "Downloading $tool"
$wc.DownloadFile($tool,$filePath)
}
}
finally{
$wc.Dispose()
}
}
#Enable auto logon using SysInternals AutoLogon.exe
function Enable-AutoLogon
{
param(
[string] $UserName,
[string] $Password
)
$exePath = Join-Path $env:WinDir "System32\SysInternals\AutoLogon.exe"
if(!(Test-Path $exePath)){
Write-Error "AutoLogon.exe is not found at $exePath"
}
$paths = $UserName.Split("\")
$domain = $paths[0]
$user = $paths[1]
Start-Process -FilePath $exePath -ArgumentList "/accepteula", $user, $domain, $password -Wait
}
#Register BGInfo.exe to startup comand
function Register-BGInfoStartup
{
$exePath = Join-Path $env:WinDir "System32\SysInternals\BGInfo.exe"
if(!(Test-Path $exePath)){
Write-Error "BGInfo.exe is not found at $exePath"
}
#Register Startup command for All User
$startupPath = Join-Path $env:ProgramData "Microsoft\Windows\Start Menu\Programs\Startup\BGInfo.lnk"
$shell = New-Object -COM WScript.Shell
$shortcut = $shell.CreateShortcut($startupPath)
$shortcut.TargetPath = $exePath
$shortcut.Arguments = "/accepteula /timer:0 /silent"
$shortcut.Save()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment