/build/static/layout/Breadcrumb_cap_w.png

Dropbox Deployment Script

<# 
Setup.ps1
 
Uninstalls* all versions of DropBox and installs latest
 
* Dropbox does not install for all users, it installs for the installing user, and that
user requires administrative access... this is a problem.
 
Script uses 7-Zip (installed on all of our machines) to unpack the installer into the
desired destination directory, and then creates the necessary registry entries and
Start Menu shortcut.
 
Script does not load each registry hive and attempt to uninstall per-user installs.
 
OS: W8, W7, XP
Arch: x86, x64
 
Adam Sailer
2013.05.09
#>
 
 
## Globals
$invoke = split-path -path $myinvocation.mycommand.path -parent
$os = gwmi win32_OperatingSystem
$proc = gwmi win32_Processor
$debug = $false
 
 
$dest = $env:ProgramFiles
$key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
 
if (($proc.AddressWidth -eq 64) -and ($proc.DataWidth -eq 64))
{
    $dest = ${env:ProgramFiles(x86)}
    $key = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'     
}
 
 
Function KillApps
{
    write-host "`n`n@@ Called KillApps" -fore Magenta
    get-process -name *dropbox* | stop-process -force
}
 
 
Function Unpack
{
    write-host "`n`n@@ Called Unpack" -fore Magenta
 
    $7z = "$env:ProgramFiles\7-Zip\7z.exe"
    if (!(test-path $7z)) { exit 1 }
 
    $archives = (dir -path $invoke\setup -recurse -include Dropbox*.exe)
 
    foreach ($archive in $archives)
    {
        write "Unpacking : `"$archive`""
        $options = "x -o`"$dest\Dropbox`" `"$archive`" -y"
         
        if (!$debug)
        {         
            $process = (Start-Process -FilePath $7z -ArgumentList $options -Wait -Passthru)
            if ($process.ExitCode) { write $process.ExitCode; exit $process.ExitCode }
        }  
        else { write $options }
    }
}
 
 
Function Setup
{
    write-host "`n`n@@ Called Setup" -for Magenta
 
    $apps = @(dir -path $dest\Dropbox -recurse -include dropbox.exe)
 
    $path = "$env:AllUsersProfile\Start Menu\Programs"
 
    foreach ($app in $apps)
    {
        ## $app | select-object *
        $product = $app.VersionInfo.ProductName
        $version = $app.VersionInfo.ProductVersion
 
        $wshell = New-Object -comObject WScript.Shell
         
        $link = $wshell.CreateShortcut("$path\$product.lnk")
        $link.Description = $product
        $link.TargetPath = $app
        $link.IconLocation = $app
         
        if (!$debug) { $link.Save() }
         
         
        #### Registry Entries
 
        $item = "$key\$product"
        new-item -path $key -name $product -force | out-null
 
        set-itemProperty -path $item -name DisplayIcon -value "$app,0" -force
        set-itemProperty -path $item -name DisplayName -value $product -force
        set-itemProperty -path $item -name DisplayVersion -value $version -force
        set-itemProperty -path $item -name Path_Directory -value "$dest\$product" -force
        set-itemProperty -path $item -name Path_Shortcut -value "$path\$product.lnk" -force
        set-itemProperty -path $item -name Path_Menu -value "$path\$product" -force
        set-itemProperty -path $item -name Publisher -value "$product, Inc." -force
        set-itemProperty -path $item -name UninstallString -value 'Use PowerShell script' -force
 
        gp $item
    }
}
 
 
Function Uninstall
{
    Param(
        [Parameter(Mandatory=$false)]
        [string]$inp
        )
 
    write-host "`n`n@@ Called Uninstall" -fore Magenta
 
 
    $paths = @(
        'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
        'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
        ) | where-object { test-path $_ }
 
    $items = @(dir $paths | % { gp $_.PsPath } | ? { $_.DisplayName -imatch $inp })
 
    foreach ($item in $items)
    {
        $item | gm | ? { $_.Name -imatch 'Path_' } | % {
         
            write "Delete : $($item.($_.Name))"
            if (!$debug) { remove-item $item.($_.Name) -recurse -force -ea SilentlyContinue }
        }
        write "Delete : $($item.PSPath)"
        if (!$debug) { remove-item $item.PSPath -force -ea SilentlyContinue }
    }
}
 
 
#
#
 
 
Clear
KillApps
Uninstall Dropbox
Unpack
Setup

Comments

  • Top notch! Saved :) - Erroneus 11 years ago
  • So if I am understanding this, you can use this script in KBOX to depoly as long as you have 7Zip installed? - daveyknits 11 years ago
    • I am not familiar with KBOX, but you should be able to modify this script to call any application that can unpack self-extracting executables and has a command-line interface. In a few minutes here, I'll post my 7-Zip installation script. - amsailer 11 years ago
    • I've posted a new blog entry titled "7-Zip Deployment Script". - amsailer 11 years ago
  • KBOX- Dell KACE - daveyknits 11 years ago
This post is locked
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ