Dropbox in PowerShell and as Windows Service

Dropbox comes in handy as a way of distributing files across systems. You can easily get files to a whole fleet of computers and then use PowerShell to automate tasks.

If you ever wanted to run Dropbox as a Windows Service so it starts with Windows before a user logs in, follow the instructions below.

But first you need this tool srvany

  1. Delete the Dropbox service:
    sc delete "Dropbox Service"
    
  2. Run the following command:
    sc create Dropbox binPath= "C:\...\srvany.exe" DisplayName= "Dropbox Service"
    
  3. Choose properties on Dropbox service > Click on tab “Log On” > Click “This account“, and select the appropriate account in order to run dropbox > Set appropriate password > Set startup type to “Automatic“.
  4. Run in PowerShell:
    New-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dropbox\Parameters
    
    New-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dropbox\Parameters -Name Application -PropertyType String -Value "C:\Program Files (x86)\Dropbox\Client\Dropbox.exe"
  5. Go back to Services, and start the Dropbox service

Then, you can incorporate Dropbox into PowerShell by finding the correct Dropbox location and Dropbox path in Windows automatically using PowerShell. The PowerShell below will assign the correct Dropbox path to a variable $dropboxpath which you can use throughout your PowerShell script.


#region Dropbox path
$dropboxDBfile = Get-ChildItem Path $env:USERPROFILE\AppData\Local Recurse ErrorAction SilentlyContinue | ? {$_.Name -eq 'host.db'}
$base64path = gc $dropboxDBfile.FullName | select index 1 # -index 1 is the 2nd line in the file
$dropboxPath = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($base64path)) # convert from base64 to ascii
#endregion

Don’t forget you can Windows Remote Management / Remote PowerShell to manage your Windows workloads remotely. If you need to setup Remote PowerShell, you can follow my guide.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s