Пример #1
0
int DeleteDokanService(LPCWSTR ServiceName) {
  fwprintf(stdout, L"Removing '%s'...\n", ServiceName);
  if (!DokanServiceDelete(ServiceName)) {
    fwprintf(stderr, L"Error removing '%s'\n", ServiceName);
    return EXIT_FAILURE;
  }
  fwprintf(stdout, L"'%s' removed.\n", ServiceName);
  return EXIT_SUCCESS;
}
Пример #2
0
int __cdecl
wmain(int argc, PWCHAR argv[])
{
	size_t	i;
    WCHAR	fileName[MAX_PATH];
    WCHAR	driverFullPath[MAX_PATH] = { 0 };
    WCHAR	mounterFullPath[MAX_PATH] = { 0 };
    WCHAR	type;

    //setlocale(LC_ALL, "");

    GetModuleFileName(NULL, fileName, MAX_PATH);
    
    // search the last "\"
    for(i = wcslen(fileName) - 1; i > 0 && fileName[i] != L'\\'; --i)
    {
        ;
    }
    fileName[i] = L'\0';

    wcscpy_s(mounterFullPath, MAX_PATH, fileName);
    wcscat_s(mounterFullPath, MAX_PATH, L"\\mounter.exe");
    fwprintf(stderr, L"mounter path %s\n", mounterFullPath);

    GetSystemDirectory(driverFullPath, MAX_PATH);
    wcscat_s(driverFullPath, MAX_PATH, L"\\drivers\\dokan.sys");

    fwprintf(stderr, L"driver path %s\n", driverFullPath);
    

    if (GetOption(argc, argv, 1) == L'v') {
        fprintf(stderr, "dokanctl : %s %s\n", __DATE__, __TIME__);
        fprintf(stderr, "Dokan version : %d\n", DokanVersion());
        fprintf(stderr, "Dokan driver version : 0x%X\n", DokanDriverVersion());
        return 0;
    
    } else if (GetOption(argc, argv, 1) == L'm') {
        return ShowMountList();

    } else if (GetOption(argc, argv, 1) == L'u' && argc == 3) {
        return Unmount(argv[2], FALSE);

    } else if (GetOption(argc, argv, 1) == L'u' &&
                GetOption(argc, argv, 3) == L'f' && argc == 4) {
        return Unmount(argv[2], TRUE);

    } else if (argc < 3 || wcslen(argv[1]) != 2 || argv[1][0] != L'/' ) {
        return ShowUsage();
    }

    type = towlower(argv[2][0]);

    switch(towlower(argv[1][1])) {
    case L'i':
        if (type ==  L'd') {
            if (DokanServiceInstall(DOKAN_DRIVER_SERVICE,
                                    SERVICE_FILE_SYSTEM_DRIVER,
                                    driverFullPath))
                fprintf(stderr, "driver install ok");
            else
                fprintf(stderr, "driver install failed");

        } else if (type == L's') {
            if (DokanServiceInstall(DOKAN_MOUNTER_SERVICE,
                                    SERVICE_WIN32_OWN_PROCESS,
                                    mounterFullPath))
                fprintf(stderr, "mounter install ok");
            else
                fprintf(stderr, "mounter install failed");
        
        } else if (type == L'a') {
            if (DokanServiceInstall(DOKAN_DRIVER_SERVICE,
                                    SERVICE_FILE_SYSTEM_DRIVER,
                                    driverFullPath))
                fprintf(stderr, "driver install ok");
            else
                fprintf(stderr, "driver install failed");

            if (DokanServiceInstall(DOKAN_MOUNTER_SERVICE,
                                    SERVICE_WIN32_OWN_PROCESS,
                                    mounterFullPath))
                fprintf(stderr, "mounter install ok");
            else
                fprintf(stderr, "mounter install failed");
        } else if (type == L'n') {
            if (DokanNetworkProviderInstall())
                fprintf(stderr, "network provider install ok");
            else
                fprintf(stderr, "network provider install failed");
        }
        break;

    case L'r':
        if (type == L'd') {
            if (DokanServiceDelete(DOKAN_DRIVER_SERVICE))
                fprintf(stderr, "driver remove ok");
            else
                fprintf(stderr, "driver remvoe failed");
        
        } else if (type == L's') {
            if (DokanServiceDelete(DOKAN_MOUNTER_SERVICE))
                fprintf(stderr, "mounter remove ok");
            else
                fprintf(stderr, "mounter remvoe failed");	
        
        } else if (type == L'a') {
            if (DokanServiceDelete(DOKAN_MOUNTER_SERVICE))
                fprintf(stderr, "mounter remove ok");
            else
                fprintf(stderr, "mounter remvoe failed");	

            if (DokanServiceDelete(DOKAN_DRIVER_SERVICE))
                fprintf(stderr, "driver remove ok");
            else
                fprintf(stderr, "driver remvoe failed");
        } else if (type == L'n') {
            if (DokanNetworkProviderUninstall())
                fprintf(stderr, "network provider remove ok");
            else
                fprintf(stderr, "network provider remove failed");
        }
        break;
    case L'd':
        if (L'0' <= type && type <= L'9') {
            ULONG mode = type - L'0';
            if (DokanSetDebugMode(mode)) {
                fprintf(stderr, "set debug mode ok");
            } else {
                fprintf(stderr, "set debug mode failed");
            }
        }
        break;
    default:
        fprintf(stderr, "unknown option");
    }
    

    return 0;
}