Troubleshooting about eject drive since explorer.exe

Hello,

In Windows 7;

When I call API DefineDosDevice drive to my file system driver it’s OK.
Eject function since explorer, it’s OK!

In my drive I call the function IoCreateSymbolicLink \ \ DosDevices \ \ Global \ % drive: only if I am root user , otherwise returns DefineDosDevice ERROR_ACCESS_DENIED if I am in user mode.

When I call API DefineDosDevice as a user, it works without i having call the function IoCreateSymbolicLink from my driver

My worries, when I create my filesystem drive as user, and I click Eject since explorer.exe, Windows sends me an error (translated to english) : Removable Disk (drive%:slight_smile: is in using, Save the files on opening this disc and close the file or program which use the file before eject the drive…".

How to solve this trouble?

Source code which call DefineDosDevice as user and not root user :

PSID SpcLookupName(LPCTSTR lpszSystemName, LPCTSTR lpszAccountName) {

PSID Sid;

DWORD cbReferencedDomainName, cbSid;

LPTSTR ReferencedDomainName;

SID_NAME_USE eUse;

cbReferencedDomainName = cbSid = 0;

if (LookupAccountName(lpszSystemName, lpszAccountName, 0, &cbSid, 0,
&cbReferencedDomainName, &eUse)) {

SetLastError(ERROR_NONE_MAPPED);

return 0;

}

if (GetLastError( ) != ERROR_INSUFFICIENT_BUFFER) return 0;

if (!(Sid = (PSID)LocalAlloc(LMEM_FIXED, cbSid))) return 0;

ReferencedDomainName = (LPTSTR)LocalAlloc(LMEM_FIXED,
cbReferencedDomainName+2560);

if (!ReferencedDomainName) {

LocalFree(Sid);

return 0;

}

if (!LookupAccountName(lpszSystemName, lpszAccountName, Sid, &cbSid,
ReferencedDomainName, &cbReferencedDomainName, &eUse)) {

LocalFree(ReferencedDomainName);

LocalFree(Sid);

return 0;

}

LocalFree(ReferencedDomainName);

return Sid;

}

BOOL
WINAPI
forcedosdevice(
__in DWORD dwFlags,
__in LPCWSTR lpDeviceName,
__in_opt LPCWSTR lpTargetPath
)
{
HANDLE hToken, hModifiedToken;

if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken ))

{

//MessageBox(NULL, L"Error1", L"ok", MB_OK);

return false;

}

PSID sidAdmin;

DWORD SidSize = SECURITY_MAX_SID_SIZE;

if(!(sidAdmin = LocalAlloc(LMEM_FIXED, SidSize)))

{

return false;

}

if(!CreateWellKnownSid((WELL_KNOWN_SID_TYPE)26, NULL, sidAdmin, &SidSize))

{

LocalFree(sidAdmin);

return false;

}

SID_AND_ATTRIBUTES sidAttr =

{

sidAdmin, 0

};

if(!CreateRestrictedToken(hToken, 0, 0, sidAttr, 0, NULL, 0,
NULL, &hModifiedToken))

{

//MessageBoxA(NULL, L"Error2", L"ok", MB_OK);

LocalFree(sidAdmin);

return false;

}

if(ImpersonateLoggedOnUser(hModifiedToken))

{

int err=GetLastError();
SetLastError(0);
//*lpDeviceName=L’G’;
BOOL bResult=DefineDosDeviceW(dwFlags,lpDeviceName,lpTargetPath);
err=GetLastError();
//RevertToSelf();
return bResult;
}
}

Thank you for me help