Last active
November 23, 2017 16:41
-
-
Save alencar/a0aed07494283e7fb1dc176e450ba023 to your computer and use it in GitHub Desktop.
Find drive letter for Google File Stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* google-file-stream.c | |
* Alexandre Alencar | |
* alexandre dot alencar at gmail dot com | |
* github.com/alencar | |
* | |
* Compile with: gcc google-file-stream.c -o google-file-stream.exe -Wall | |
* Usage: | |
* FOR /F %D IN ('google-file-stream.exe') DO SET GFS=%D | |
* | |
* You now know where the Google File Stream is mounted on and can do | |
* whatever your want with it. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <windows.h> | |
#define BUFSIZE 512 | |
int main( int argc, char * argv[] ) { | |
char lpVolumeNameBuffer[MAX_PATH+1]; | |
char szTemp[BUFSIZE]; | |
char szName[MAX_PATH]; | |
char szDrive[3] = TEXT(" :"); | |
char *p; | |
UINT uMode; | |
/* | |
* Temporary disable media error messages | |
*/ | |
uMode = SetErrorMode(SEM_FAILCRITICALERRORS); | |
szTemp[0] = '\0'; | |
/* | |
* Save Logical Drive list | |
*/ | |
if(GetLogicalDriveStrings(BUFSIZE-1, szTemp)){ | |
p = szTemp; | |
do { | |
*szDrive = *p; | |
/* | |
* Given a logical drive, does it is available? | |
*/ | |
if(QueryDosDevice(szDrive, szName, MAX_PATH)){ | |
/* | |
* Given a drive letter, does it is Google Drive File Stream? | |
*/ | |
if(GetVolumeInformation(szDrive, lpVolumeNameBuffer, MAX_PATH+1, NULL, NULL, NULL, NULL, 0)){ | |
if(strcmp(lpVolumeNameBuffer, "Google Drive File Stream") == 0){ | |
/* | |
* Output the drive letter | |
*/ | |
printf("%s", szDrive); | |
} | |
} | |
} | |
while(*p++); | |
} while(*p); | |
} | |
/* | |
* Restore media error messages | |
*/ | |
SetErrorMode(uMode); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment