NetShareGetInfo - returns ERROR_ACCESS_DENIED
-
I am using this API to retrieve the Network Share Information on another machine. Both the machines have been logged on as "Administrator".. But the return status of this API is always "ERROR_ACCESS_DENIED". Does anybody know why? The syntax of my call is as follows: char szPath[255]; WCHAR wcHostName[255]; WCHAR wcShareName[255]; if ( strHost.CompareNoCase(strHostName) == 0 ) MultiByteToWideChar( CP_ACP, 0, strHostName, -1, wcHostName,255 ); else MultiByteToWideChar( CP_ACP, 0, strIP, -1, wcHostName,255 ); MultiByteToWideChar( CP_ACP, 0, strShareName, -1, wcShareName,255 ); PSHARE_INFO_502 BufPtr; NET_API_STATUS res; if ( (res = NetShareGetInfo( (char*)wcHostName, (char*)wcShareName, 502, (LPBYTE *)&BufPtr )) == ERROR_SUCCESS ) { WideCharToMultiByte( CP_ACP, 0, (const unsigned short*)BufPtr->shi502_path, -1, szPath, 255, NULL, NULL ); m_strFileName = szPath; int nLen = m_strFileName.GetLength(); if ( m_strFileName.GetAt(nLen-1) != '\\' ) m_strFileName += '\\'; m_strFileName += strUNCFile; NetApiBufferFree(BufPtr); } else { strErrors += "Unable to convert UNC Name to Local name \n"; bOk = false; } Ramesh S
-
I am using this API to retrieve the Network Share Information on another machine. Both the machines have been logged on as "Administrator".. But the return status of this API is always "ERROR_ACCESS_DENIED". Does anybody know why? The syntax of my call is as follows: char szPath[255]; WCHAR wcHostName[255]; WCHAR wcShareName[255]; if ( strHost.CompareNoCase(strHostName) == 0 ) MultiByteToWideChar( CP_ACP, 0, strHostName, -1, wcHostName,255 ); else MultiByteToWideChar( CP_ACP, 0, strIP, -1, wcHostName,255 ); MultiByteToWideChar( CP_ACP, 0, strShareName, -1, wcShareName,255 ); PSHARE_INFO_502 BufPtr; NET_API_STATUS res; if ( (res = NetShareGetInfo( (char*)wcHostName, (char*)wcShareName, 502, (LPBYTE *)&BufPtr )) == ERROR_SUCCESS ) { WideCharToMultiByte( CP_ACP, 0, (const unsigned short*)BufPtr->shi502_path, -1, szPath, 255, NULL, NULL ); m_strFileName = szPath; int nLen = m_strFileName.GetLength(); if ( m_strFileName.GetAt(nLen-1) != '\\' ) m_strFileName += '\\'; m_strFileName += strUNCFile; NetApiBufferFree(BufPtr); } else { strErrors += "Unable to convert UNC Name to Local name \n"; bOk = false; } Ramesh S
i'm not sure what you mean when you say "both machines are logged on as administrator". It doesn't matter who is logged in on the other machine. Also, just because you're administrator on your machine you don't get admin privs on the other machine -- that would be quite a security hole! For this api to work, you must be logged into an account recognized as an administrator (or power user? i forget...) account by the machine to which this api is directed.