Skip to content

Instantly share code, notes, and snippets.

@Jeff-Lewis
Last active November 8, 2021 12:27
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Jeff-Lewis/49e578f210c1d0f13570 to your computer and use it in GitHub Desktop.
Save Jeff-Lewis/49e578f210c1d0f13570 to your computer and use it in GitHub Desktop.
Run Google Drive as a service.
:: 1) Download srvany.exe from Microsoft Windows 2003 Resource Kit (available free from Microsoft).
:: 2) Copy srvany.exe into the folder where google drive is installed or next to this script file.
:: 3) Run this script as an Administrator
echo off
cls
SET STARTING_DIR=%CD%
SET SCRIPT_DIR=%~dp0
echo Running from: %STARTING_DIR%
echo Script Dir: %SCRIPT_DIR%
SET DEFAULT_USERNAME=%USERDOMAIN%\%USERNAME%
SET /P UNAME=Enter username for account to run service under. (%DEFAULT_USERNAME%) || SET UNAME=%DEFAULT_USERNAME%
SET /P PWORD=Enter %UNAME% password. || Set PWORD=NothingChosen
If "%PWORD%"=="NothingChosen" goto :sub_error_nopass
echo Copying srvany.exe to C:\Program Files (x86)\Google\Drive
copy %SCRIPT_DIR%\srvany.exe "C:\Program Files (x86)\Google\Drive"
echo Adding Google Drive as a service...
echo sc create GoogleDriveSync displayName= "Google Drive Service" start= auto obj= "%UNAME%" password= %PWORD% binPath= "C:\Program Files (x86)\Google\Drive\srvany.exe"
sc create GoogleDriveSync displayName= "Google Drive Service" start= auto obj= "%UNAME%" password= %PWORD% binPath= "C:\Program Files (x86)\Google\Drive\srvany.exe"
echo Updating registry for service...
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\GoogleDriveSync\Parameters /f
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\GoogleDriveSync\Parameters /v Application /d "C:\Program Files (x86)\Google\Drive\googledrivesync.exe" /f
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\GoogleDriveSync\Parameters /v AppParameters /d "/autostart --noshow_confirmation_dialog_on_delete" /f
echo Starting service...
net start GoogleDriveSync
echo Finished.
pause
goto:eof
:sub_error_nopass
echo No password given. Ending.
@corrin
Copy link

corrin commented Jul 8, 2018

Hey, thanks for this - awesome!

I had to make a couple minor tweaks.

  1. Google Drive seems to be in C:\Program Files\ now, not (x86)
  2. I needed to edit group policy and allow 'log in as a service'

It might also be worth mentioning that if you stuff up (e.g. forget the copy in step 2)
Then the easiest thing to do is uninstall the service and reboot.

@conficient
Copy link

Great script - but I needed a change.

If the source folder contains spaces, the copy of srvany.exe will fail, so you need to add double-quotes around the source parameter.

@mambulo
Copy link

mambulo commented Jun 28, 2019

THANKS a LOT by the script!

I also had issues when trying to run it on a Windows 7 Pro machine. You may want to correct this part:

sc create GoogleDriveSync displayName= "Google Drive Service" start= auto obj= "%UNAME%" password= %PWORD% binPath= "C:\Program Files\Google\Drive\srvany.exe"

Notice the space between the "=" and it's value....this makes a BIG difference, if you don't place that space over there, it won't create (or register) properly the new windows service in the Windows registry. For more information checkout this link:

https://serverfault.com/questions/152393/problems-creating-service-using-sc-exe

I hope this comment helps someone in the future.

@Jeff-Lewis
Copy link
Author

Thanks @mambulo, I added spaces to parameters.

@adriancs2
Copy link

srvany.exe is no more available for download from Microsoft

@heliocabral
Copy link

Hey, thanks for this - awesome!

I had to make a couple minor tweaks.

  1. Google Drive seems to be in C:\Program Files\ now, not (x86)
  2. I needed to edit group policy and allow 'log in as a service'

It might also be worth mentioning that if you stuff up (e.g. forget the copy in step 2)
Then the easiest thing to do is uninstall the service and reboot.

Hi!
Can you be more specific about the group policy change?
I'm having some trouble getting this right.
The service starts and runs but but it doesn't sync.
I'm running this on a Windows Server 2008.
Does anyone have some idea what it might be wrong or if this is a valid method in 2021?

Thank you

@Jeff-Lewis
Copy link
Author

@adriancs2 I don't guarantee anything here but there's a copy of the Windows Resource Kit on archive.org that contains srvany.exe.

@Jeff-Lewis
Copy link
Author

@heliocabral I haven't used this in years but check where Google Drive (Google File Stream) is installed. Currently it's C:\Program Files\Google\Drive File Stream\47.0.19.0\GoogleDriveFS.exe
Also, the latest Google Drive creates a virtual disk in Windows and this might or might not work under a service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment