diff --git a/Agent/OCSInventory.cpp b/Agent/OCSInventory.cpp index 5070eec..b16b418 100644 --- a/Agent/OCSInventory.cpp +++ b/Agent/OCSInventory.cpp @@ -775,5 +775,13 @@ BOOL COCSInventoryApp::parseCommandLine() // /NOTIFY if (isRequired( m_lpCmdLine, _T( "notify"))) m_pConfig->setNotify( TRUE); + // /WMI_FLAG_MODE[=READ/COMPLETE]^M + if (isRequired(m_lpCmdLine, _T("wmi_flag_mode"))) + // Get wmi flag mode + m_pConfig->setWmiFlagMode(getParamValue(m_lpCmdLine, _T("wmi_flag_mode"))); + // /DEFAULT_USER_DOMAIN[=user] + if (isRequired(m_lpCmdLine, _T("default_user_domain"))) + // Get default user domain + m_pConfig->setDefaultUserDomain(getParamValue(m_lpCmdLine, _T("default_user_domain"))); return TRUE; } diff --git a/NSIS_agent_setup/Agent2.ini b/NSIS_agent_setup/Agent2.ini new file mode 100644 index 0000000..836194d --- /dev/null +++ b/NSIS_agent_setup/Agent2.ini @@ -0,0 +1,76 @@ +; Ini file generated by the HM NIS Edit IO designer. +[Settings] +NumFields=9 + +[Field 1] +Type=Groupbox +Text=WMI options... +Left=0 +Right=300 +Top=3 +Bottom=102 + +[Field 2] +Type=Label +Text=Behavior of WMI calls : +Left=9 +Right=85 +Top=17 +Bottom=27 + +[Field 3] +Type=Label +Text=Default user domain : +Left=9 +Right=78 +Top=81 +Bottom=96 + +[Field 4] +Type=Text +Left=80 +Right=290 +Top=80 +Bottom=92 + +[Field 5] +Type=Label +Text=COMPLETE: Allow WMI to retrieve current domain user +Left=9 +Right=285 +Top=32 +Bottom=40 + +[Field 6] +Type=Label +Text=If the WMI does not allow the recovery of the current user +Left=9 +Right=292 +Top=54 +Bottom=64 + +[Field 7] +Type=Label +Text=READ: Not allow +Left=9 +Right=62 +Top=41 +Bottom=49 + +[Field 8] +Type=Label +Text=which default user should OCS return ? +Left=9 +Right=132 +Top=65 +Bottom=73 + +[Field 9] +Type=Droplist +State=COMPLETE +ListItems=COMPLETE|READ +Left=88 +Right=290 +Top=14 +Bottom=107 + diff --git a/NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x64.nsi b/NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x64.nsi index ffee4eb..58a64a5 100644 --- a/NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x64.nsi +++ b/NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x64.nsi @@ -54,6 +54,7 @@ ICON "install-ocs.ico" Page custom AskServerOptions ValidateServerOptions "" Page custom AskProxyOptions ValidateProxyOptions "" Page custom AskAgentOptions ValidateAgentOptions "" +Page custom AskAgent2Options ValidateAgent2Options "" ; Where to save inventory result when /LOCAL is used Page custom AskLocalInventory ValidateLocalInventory "" ; Directory page @@ -529,6 +530,22 @@ ParseCmd_NoTag_End: ; Remove parsed arg from command line ${WordReplace} '$9' '/TAG=$R0' "" "+" $R1 StrCpy $9 $R1 + ; /WMI_FLAG_MODE="value" + ${GetOptions} '$9' '/WMI_FLAG_MODE=' $R0 + IfErrors 0 +2 + StrCpy $R0 "COMPLETE" + WriteINIStr "$PLUGINSDIR\agent2.ini" "Field 9" "State" "$R0" + ; Remove parsed arg from command line + ${WordReplace} '$9' '/WMI_FLAG_MODE=$R0' "" "+" $R1 + StrCpy $9 $R1 + ; /DEFAULT_USER_DOMAIN="value" + ${GetOptions} '$9' '/DEFAULT_USER_DOMAIN=' $R0 + IfErrors 0 +2 + StrCpy $R0 "" + WriteINIStr "$PLUGINSDIR\agent2.ini" "Field 4" "State" "$R0" + ; Remove parsed arg from command line + ${WordReplace} '$9' '/DEFAULT_USER_DOMAIN=$R0' "" "+" $R1 + StrCpy $9 $R1 ; No service ${GetOptions} '$9' '/NO_SERVICE' $R0 IfErrors 0 ParseCmd_NoService @@ -1081,6 +1098,14 @@ WriteServiceIni_Skip_NoTag: ReadINIStr $R0 "$PLUGINSDIR\agent.ini" "Field 6" "State" StrCpy $R1 '$R2 /TAG="$R0"' StrCpy $R2 $R1 + ; WMI_FLAG_MODE + ReadINIStr $R0 "$PLUGINSDIR\agent2.ini" "Field 9" "State" + StrCpy $R1 '$R2 /WMI_FLAG_MODE="$R0"' + StrCpy $R2 $R1 + ; DEFAULT_USER_DOMAIN + ReadINIStr $R0 "$PLUGINSDIR\agent2.ini" "Field 4" "State" + StrCpy $R1 '$R2 /DEFAULT_USER_DOMAIN="$R0"' + StrCpy $R2 $R1 ; No Service ReadINIStr $R0 "$PLUGINSDIR\agent.ini" "Field 7" "State" StrCmp $R0 "1" 0 WriteServiceIni_Skip_NoService @@ -1162,6 +1187,7 @@ not_running: File /oname=$PLUGINSDIR\server.ini "server.ini" File /oname=$PLUGINSDIR\proxy.ini "proxy.ini" File /oname=$PLUGINSDIR\agent.ini "agent.ini" + File /oname=$PLUGINSDIR\agent2.ini "agent2.ini" File /oname=$PLUGINSDIR\local.ini "local.ini" File /oname=$PLUGINSDIR\splash.bmp "Banner-ocs.bmp" File /oname=$PLUGINSDIR\SetACL.exe "SetACL.exe" @@ -1360,6 +1386,16 @@ FunctionEnd Function ValidateAgentOptions FunctionEnd +Function AskAgent2Options + ${If} ${SectionIsSelected} 3 ; Index of Network inventory section + !insertmacro MUI_HEADER_TEXT "OCS Inventory NG Agent for Windows properties" "If needed, specify OCS Inventory NG Agent options..." + InstallOptions::dialog "$PLUGINSDIR\agent2.ini" + ${EndIf} +FunctionEnd + +Function ValidateAgent2Options +FunctionEnd + Function AskLocalInventory ${If} ${SectionIsSelected} 4 ; Index of Local inventory section !insertmacro MUI_HEADER_TEXT "OCS Inventory Agent for Windows" "Choose folder to save inventory result..." diff --git a/NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x86.nsi b/NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x86.nsi index c034664..b79502d 100644 --- a/NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x86.nsi +++ b/NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x86.nsi @@ -53,6 +53,7 @@ ICON "install-ocs.ico" Page custom AskServerOptions ValidateServerOptions "" Page custom AskProxyOptions ValidateProxyOptions "" Page custom AskAgentOptions ValidateAgentOptions "" +Page custom AskAgent2Options ValidateAgent2Options "" ; Where to save inventory result when /LOCAL is used Page custom AskLocalInventory ValidateLocalInventory "" ; Directory page @@ -529,6 +530,22 @@ ParseCmd_NoTag_End: ; Remove parsed arg from command line ${WordReplace} '$9' '/TAG=$R0' "" "+" $R1 StrCpy $9 $R1 + ; /WMI_FLAG_MODE="value" + ${GetOptions} '$9' '/WMI_FLAG_MODE=' $R0 + IfErrors 0 +2 + StrCpy $R0 "COMPLETE" + WriteINIStr "$PLUGINSDIR\agent2.ini" "Field 9" "State" "$R0" + ; Remove parsed arg from command line + ${WordReplace} '$9' '/WMI_FLAG_MODE=$R0' "" "+" $R1 + StrCpy $9 $R1 + ; /DEFAULT_USER_DOMAIN="value" + ${GetOptions} '$9' '/DEFAULT_USER_DOMAIN=' $R0 + IfErrors 0 +2 + StrCpy $R0 "" + WriteINIStr "$PLUGINSDIR\agent2.ini" "Field 4" "State" "$R0" + ; Remove parsed arg from command line + ${WordReplace} '$9' '/DEFAULT_USER_DOMAIN=$R0' "" "+" $R1 + StrCpy $9 $R1 ; No service ${GetOptions} '$9' '/NO_SERVICE' $R0 IfErrors 0 ParseCmd_NoService @@ -1037,6 +1054,14 @@ WriteServiceIni_Skip_NoTag: ReadINIStr $R0 "$PLUGINSDIR\agent.ini" "Field 6" "State" StrCpy $R1 '$R2 /TAG="$R0"' StrCpy $R2 $R1 + ; WMI_FLAG_MODE + ReadINIStr $R0 "$PLUGINSDIR\agent2.ini" "Field 9" "State" + StrCpy $R1 '$R2 /WMI_FLAG_MODE="$R0"' + StrCpy $R2 $R1 + ; DEFAULT_USER_DOMAIN + ReadINIStr $R0 "$PLUGINSDIR\agent2.ini" "Field 4" "State" + StrCpy $R1 '$R2 /DEFAULT_USER_DOMAIN="$R0"' + StrCpy $R2 $R1 ; No Service ReadINIStr $R0 "$PLUGINSDIR\agent.ini" "Field 7" "State" StrCmp $R0 "1" 0 WriteServiceIni_Skip_NoService @@ -1111,6 +1136,7 @@ not_running: File /oname=$PLUGINSDIR\server.ini "server.ini" File /oname=$PLUGINSDIR\proxy.ini "proxy.ini" File /oname=$PLUGINSDIR\agent.ini "agent.ini" + File /oname=$PLUGINSDIR\agent2.ini "agent2.ini" File /oname=$PLUGINSDIR\local.ini "local.ini" File /oname=$PLUGINSDIR\splash.bmp "Banner-ocs.bmp" File /oname=$PLUGINSDIR\SetACL.exe "SetACL.exe" @@ -1309,6 +1335,16 @@ FunctionEnd Function ValidateAgentOptions FunctionEnd +Function AskAgent2Options + ${If} ${SectionIsSelected} 3 ; Index of Network inventory section + !insertmacro MUI_HEADER_TEXT "OCS Inventory NG Agent for Windows properties" "If needed, specify OCS Inventory NG Agent options..." + InstallOptions::dialog "$PLUGINSDIR\agent2.ini" + ${EndIf} +FunctionEnd + +Function ValidateAgent2Options +FunctionEnd + Function AskLocalInventory ${If} ${SectionIsSelected} 4 ; Index of Local inventory section !insertmacro MUI_HEADER_TEXT "OCS Inventory NG Agent for Windows" "Choose folder to save inventory result..." diff --git a/OCSInventory Front/Config.cpp b/OCSInventory Front/Config.cpp index aed50c2..c8192eb 100644 --- a/OCSInventory Front/Config.cpp +++ b/OCSInventory Front/Config.cpp @@ -55,6 +55,8 @@ void CConfig::Clear() m_csIpDiscLat.Empty(); m_bFastIp = FALSE; m_csVersion.Empty(); + m_csWmiFlagMode = "COMPLETE"; + m_csDefaultUserDomain.Empty(); } LPCTSTR CConfig::getVersion() @@ -97,6 +99,36 @@ LPCTSTR CConfig::getLocalInventoryFolder() return m_csLocal; } +BOOL CConfig::isDefaultUserDomainRequired() +{ + return !m_csDefaultUserDomain.IsEmpty(); +} + +LPCTSTR CConfig::getDefaultUserDomain() +{ + return m_csDefaultUserDomain; +} + +tag_WBEM_GENERIC_FLAG_TYPE CConfig::getWmiFlagMode() +{ + CString m_csComplete("READ"); + if (m_csWmiFlagMode == m_csComplete) + m_uFlag = WBEM_FLAG_DIRECT_READ; + else + m_uFlag = WBEM_FLAG_RETURN_WBEM_COMPLETE; + return m_uFlag; +} + +LPCTSTR CConfig::getWmiFlagModeText() +{ + CString m_csComplete("READ"); + if (m_csWmiFlagMode == m_csComplete) + m_csFlag = "WBEM_FLAG_DIRECT_READ"; + else + m_csFlag = "WBEM_FLAG_RETURN_WBEM_COMPLETE"; + return m_csFlag; +} + BOOL CConfig::isNoTagRequired() { return m_bNoTag; @@ -191,6 +223,12 @@ BOOL CConfig::load( LPCTSTR lpstrFile) GetPrivateProfileString( OCS_AGENT_SECTION, _T( "ComProvider"), OCS_DEFAULT_PROVIDER, csBuffer.GetBuffer( 1024), 1024, m_csConfigFile); csBuffer.ReleaseBuffer(); setCommunicationProvider( csBuffer); + // Default user domain name + GetPrivateProfileString(OCS_AGENT_SECTION, _T("DEFAULT_USER_DOMAIN"), _T(""), m_csDefaultUserDomain.GetBuffer(1024), 1024, m_csConfigFile); + m_csDefaultUserDomain.ReleaseBuffer(); + // WMI flag mode + GetPrivateProfileString(OCS_AGENT_SECTION, _T("WMI_FLAG_MODE"), _T(""), m_csWmiFlagMode.GetBuffer(1024), 1024, m_csConfigFile); + m_csWmiFlagMode.ReleaseBuffer(); return TRUE; } @@ -219,6 +257,10 @@ BOOL CConfig::save( LPCTSTR lpstrFile) bResult = bResult && WritePrivateProfileString( OCS_AGENT_SECTION, _T( "NoTAG"), csBuffer, m_csConfigFile); // Force IP Discover for the specified network bResult = bResult && WritePrivateProfileString( OCS_AGENT_SECTION, _T( "IpDisc"), m_csIpDisc, m_csConfigFile); + // Wmi flag mode + bResult = bResult && WritePrivateProfileString(OCS_AGENT_SECTION, _T("WMI_FLAG_MODE"), m_csWmiFlagMode, m_csConfigFile); + // Default user domain + bResult = bResult && WritePrivateProfileString(OCS_AGENT_SECTION, _T("DEFAULT_USER_DOMAIN"), m_csDefaultUserDomain, m_csConfigFile); // Communication provider to use CFile comFile( m_csComProvider, CFile::modeRead); bResult = bResult && WritePrivateProfileString( OCS_AGENT_SECTION, _T( "ComProvider"), comFile.GetFileName(), m_csConfigFile); @@ -302,6 +344,16 @@ void CConfig::setNoTagRequired(BOOL bNoTag) m_bNoTag = bNoTag; } +void CConfig::setWmiFlagMode(LPCTSTR lpstrWmiFlag) +{ + m_csWmiFlagMode = lpstrWmiFlag; +} + +void CConfig::setDefaultUserDomain(LPCTSTR lpstrDefaultUserDomain) +{ + m_csDefaultUserDomain = lpstrDefaultUserDomain; +} + void CConfig::setXmlFolder(LPCTSTR lpstrFolder) { if ((lpstrFolder == NULL) || (_tcslen( lpstrFolder) == 0)) diff --git a/OCSInventory Front/Config.h b/OCSInventory Front/Config.h index a1775f9..323450b 100644 --- a/OCSInventory Front/Config.h +++ b/OCSInventory Front/Config.h @@ -51,6 +51,7 @@ class CConfig; #include "OCSInventory Front Classes.h" #include "Singleton.h" +#include class OCSINVENTORYFRONT_API CConfig : public CSingleton { @@ -115,6 +116,12 @@ class OCSINVENTORYFRONT_API CConfig : public CSingleton BOOL isForceInventoryRequired(); // Get Communication Provider DLL LPCTSTR getCommunicationProvider(); + // Get Default User Domain + BOOL isDefaultUserDomainRequired(); + LPCTSTR getDefaultUserDomain(); + // Get WMI flag mode + tag_WBEM_GENERIC_FLAG_TYPE getWmiFlagMode(); + LPCTSTR getWmiFlagModeText(); // Enable pr not debugging mode void setDebugRequired( UINT uDebug = TRUE); @@ -147,6 +154,10 @@ class OCSINVENTORYFRONT_API CConfig : public CSingleton void setHkcuRequired( BOOL bHKCU = TRUE); // Set Communication Provider DLL to use without extension .DLL void setCommunicationProvider( LPCTSTR lpstrDll); + // Set WMI flag /WMI_FLAG_MODE=[READ/COMPLETE] + void setWmiFlagMode(LPCTSTR lpstrWmiFlag = LPCTSTR("COMPLETE")); + // Set Default user domain /DEFAULT_USER_DOMAIN=name + void setDefaultUserDomain(LPCTSTR lpstrDefaultUserDomain = NULL); // Write Administrative info to admininfo.conf hidden file in agent install folder BOOL writeAccountInfos( LPCTSTR lpstrName, LPCTSTR lpstrValue); @@ -170,6 +181,10 @@ class OCSINVENTORYFRONT_API CConfig : public CSingleton CString m_csIpDiscLat; // Is /IPDISC_LAT:"number_of_ms" enabled to force IP Discover latency BOOL m_bFastIp; // Is /FASTIP enabled, to disable network load contriol settings in IP Discover CString m_csComProvider; // What's the communication provider to use to contact server ? + CString m_csWmiFlagMode; // READ or COMPLETE + tag_WBEM_GENERIC_FLAG_TYPE m_uFlag; + CString m_csDefaultUserDomain; // Default user domain name + CString m_csFlag; // Agent version CString m_csVersion; }; diff --git a/OCSInventory Front/InventoryRequest.cpp b/OCSInventory Front/InventoryRequest.cpp index c246075..539e30c 100644 --- a/OCSInventory Front/InventoryRequest.cpp +++ b/OCSInventory Front/InventoryRequest.cpp @@ -621,7 +621,8 @@ BOOL CInventoryRequest::runInventory() CSoftware cSoftOS; // Get logged on user - if (!m_pSysInfo->getUserName( cs1)) + m_pLogger->log(LOG_PRIORITY_DEBUG, _T("INVENTORY => WMI FLAG MODE is set to <%s>"), getAgentConfig()->getWmiFlagModeText()); + if (!m_pSysInfo->getUserName(cs1, getAgentConfig()->getWmiFlagMode())) m_pLogger->log( LOG_PRIORITY_WARNING, _T( "INVENTORY => Failed to retrieve logged on user")); else m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "INVENTORY => Logged on user ID is <%s>"), cs1); @@ -655,11 +656,18 @@ BOOL CInventoryRequest::runInventory() cs1); m_Device.SetDomainOrWorkgroup( cs1); // Get NT user Domain - if (!m_pSysInfo->getUserDomain( cs1)) - m_pLogger->log( LOG_PRIORITY_WARNING, _T( "INVENTORY => Failed to retrieve user domain")); + if (!getAgentConfig()->isDefaultUserDomainRequired()) + { + if (!m_pSysInfo->getUserDomain(cs1, getAgentConfig()->getWmiFlagMode())) + m_pLogger->log(LOG_PRIORITY_WARNING, _T("INVENTORY => Failed to retrieve user domain")); + else + m_pLogger->log(LOG_PRIORITY_DEBUG, _T("INVENTORY => User domain is <%s>"), cs1); + } else - m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "INVENTORY => User domain is <%s>"), - cs1); + { + cs1 = getAgentConfig()->getDefaultUserDomain(); + m_pLogger->log(LOG_PRIORITY_DEBUG, _T("INVENTORY => Default User domain is set to <%s>"), cs1); + } m_Device.SetUserDomain( cs1); // Get BIOS information if (!m_pSysInfo->getBiosInfo( &m_BIOS)) diff --git a/OcsWmi/OcsWmi.cpp b/OcsWmi/OcsWmi.cpp index 353a143..f969880 100644 --- a/OcsWmi/OcsWmi.cpp +++ b/OcsWmi/OcsWmi.cpp @@ -478,7 +478,7 @@ BOOL COcsWmi::GetClassObjectVariantValue( LPCTSTR lpstrProperty, VARIANT &pVal) } -INT_PTR COcsWmi::GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty) +INT_PTR COcsWmi::GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { if (IsWindows8OrGreater()) { @@ -503,7 +503,7 @@ INT_PTR COcsWmi::GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTST if (csObject.IsEmpty()) return 0; m_hResult = m_pIWbemServices->GetObject(_bstr_t(csObject), - WBEM_FLAG_RETURN_WBEM_COMPLETE, + m_uFlag, NULL, &pClassObject, NULL); @@ -536,7 +536,7 @@ INT_PTR COcsWmi::GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTST } } -BOOL COcsWmi::GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, VARIANT &pVal) +BOOL COcsWmi::GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, VARIANT &pVal, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { ASSERT( m_pClassObject); ASSERT( lpstrRefElement); @@ -556,7 +556,7 @@ BOOL COcsWmi::GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPC if (csObject.IsEmpty()) return FALSE; m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject), - WBEM_FLAG_RETURN_WBEM_COMPLETE, + m_uFlag, NULL, &pClassObject, NULL); @@ -584,7 +584,7 @@ BOOL COcsWmi::GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPC } -LPCTSTR COcsWmi::GetRefElementClassObjectStringValue(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty) +LPCTSTR COcsWmi::GetRefElementClassObjectStringValue(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { ASSERT( m_pClassObject); ASSERT( lpstrRefElement); @@ -606,7 +606,7 @@ LPCTSTR COcsWmi::GetRefElementClassObjectStringValue(LPCTSTR lpstrRefElement, LP if (csObject.IsEmpty()) return NULL; m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject), - WBEM_FLAG_RETURN_WBEM_COMPLETE, + m_uFlag, NULL, &pClassObject, NULL); @@ -638,7 +638,7 @@ LPCTSTR COcsWmi::GetRefElementClassObjectStringValue(LPCTSTR lpstrRefElement, LP } -DWORD COcsWmi::GetRefElementClassObjectDwordValue(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty) +DWORD COcsWmi::GetRefElementClassObjectDwordValue(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { ASSERT( m_pClassObject); ASSERT( lpstrRefElement); @@ -661,7 +661,7 @@ DWORD COcsWmi::GetRefElementClassObjectDwordValue(LPCTSTR lpstrRefElement, LPCTS if (csObject.IsEmpty()) return 0; m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject), - WBEM_FLAG_RETURN_WBEM_COMPLETE, + m_uFlag, NULL, &pClassObject, NULL); @@ -688,7 +688,7 @@ DWORD COcsWmi::GetRefElementClassObjectDwordValue(LPCTSTR lpstrRefElement, LPCTS } -__int64 COcsWmi::GetRefElementClassObjectI64Value(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty) +__int64 COcsWmi::GetRefElementClassObjectI64Value(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { ASSERT( m_pClassObject); ASSERT( lpstrRefElement); @@ -711,7 +711,7 @@ __int64 COcsWmi::GetRefElementClassObjectI64Value(LPCTSTR lpstrRefElement, LPCTS if (csObject.IsEmpty()) return 0; m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject), - WBEM_FLAG_RETURN_WBEM_COMPLETE, + m_uFlag, NULL, &pClassObject, NULL); @@ -738,7 +738,7 @@ __int64 COcsWmi::GetRefElementClassObjectI64Value(LPCTSTR lpstrRefElement, LPCTS } -unsigned __int64 COcsWmi::GetRefElementClassObjectU64Value(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty) +unsigned __int64 COcsWmi::GetRefElementClassObjectU64Value(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { ASSERT( m_pClassObject); ASSERT( lpstrRefElement); @@ -761,7 +761,7 @@ unsigned __int64 COcsWmi::GetRefElementClassObjectU64Value(LPCTSTR lpstrRefEleme if (csObject.IsEmpty()) return 0; m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject), - WBEM_FLAG_RETURN_WBEM_COMPLETE, + m_uFlag, NULL, &pClassObject, NULL); diff --git a/OcsWmi/OcsWmi.h b/OcsWmi/OcsWmi.h index e90347f..9ef06c9 100644 --- a/OcsWmi/OcsWmi.h +++ b/OcsWmi/OcsWmi.h @@ -62,23 +62,23 @@ class OCSWMI_API COcsWmi // Get Length of data in object INT_PTR GetClassObjectLength( LPCTSTR lpstrProperty); - INT_PTR GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty); + INT_PTR GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); // Get current enumerated object properties (or properties of an objet referenced by the current enumerated object) LPCTSTR GetClassObjectStringValue( LPCTSTR lpstrProperty); - LPCTSTR GetRefElementClassObjectStringValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty); + LPCTSTR GetRefElementClassObjectStringValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); DWORD GetClassObjectDwordValue( LPCTSTR lpstrProperty); - DWORD GetRefElementClassObjectDwordValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty); + DWORD GetRefElementClassObjectDwordValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); __int64 GetClassObjectI64Value( LPCTSTR lpstrProperty); - __int64 GetRefElementClassObjectI64Value( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty); + __int64 GetRefElementClassObjectI64Value( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); unsigned __int64 GetClassObjectU64Value( LPCTSTR lpstrProperty); - unsigned __int64 GetRefElementClassObjectU64Value( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty); + unsigned __int64 GetRefElementClassObjectU64Value( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); BOOL GetClassObjectVariantValue( LPCTSTR lpstrProperty, VARIANT &pVal); - BOOL GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, VARIANT &pVal); + BOOL GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, VARIANT &pVal, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); HRESULT GetLastErrorWMI(); diff --git a/SysInfo/SysInfo.cpp b/SysInfo/SysInfo.cpp index ccc5499..76c12b1 100644 --- a/SysInfo/SysInfo.cpp +++ b/SysInfo/SysInfo.cpp @@ -636,7 +636,7 @@ BOOL CSysInfo::isNotebook() } -BOOL CSysInfo::getUserName(CString &csUserName) +BOOL CSysInfo::getUserName(CString &csUserName, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { TCHAR szUserName[255]; DWORD dwUserName = 255; @@ -657,7 +657,7 @@ BOOL CSysInfo::getUserName(CString &csUserName) See https://bugs.launchpad.net/ocsinventory-windows-agent/+bug/1300172 */ - if (m_wmiInfo.IsConnected() && m_wmiInfo.GetLoggedOnUser( csUserName)) + if (m_wmiInfo.IsConnected() && m_wmiInfo.GetLoggedOnUser( csUserName, m_uFlag)) return TRUE; // Call the GetUserName function. AddLog( _T( "GetUserName: Trying to find logged on User ID from current running process...\n")); @@ -862,10 +862,10 @@ BOOL CSysInfo::getDomainOrWorkgroup(CString &csDomain) return m_registryInfo.GetDomainOrWorkgroup( csDomain); } -BOOL CSysInfo::getUserDomain(CString &csUserDomain) +BOOL CSysInfo::getUserDomain(CString &csUserDomain, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { // First, try WMI - if (m_wmiInfo.GetUserDomain( csUserDomain)) + if (m_wmiInfo.GetUserDomain( csUserDomain, m_uFlag)) return TRUE; // Last, use registry return m_registryInfo.GetDomainOrWorkgroup( csUserDomain); diff --git a/SysInfo/SysInfo.h b/SysInfo/SysInfo.h index ae3dfd2..3ac9713 100644 --- a/SysInfo/SysInfo.h +++ b/SysInfo/SysInfo.h @@ -106,7 +106,7 @@ class SYSINFO_API CSysInfo BOOL getOS( CString &csName, CString &csVersion, CString &csComment, CString &csDescription, CString &csInstallDate); DWORD getAddressWidthOS(); BOOL getDomainOrWorkgroup( CString &csDomain); - BOOL getUserDomain( CString &csUserDomain); + BOOL getUserDomain( CString &csUserDomain, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); // Memory information BOOL getMemory( ULONG *m_ulPhysicalMemory, ULONG *m_ulSwapSize); @@ -133,7 +133,7 @@ class SYSINFO_API CSysInfo BOOL isNotebook(); // User information - BOOL getUserName( CString &csUserName); + BOOL getUserName( CString &csUserName, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); BOOL getUserNameFromExplorerProcess( CString &csUserName); // Last user logged in the system diff --git a/SysInfo/Wmi.cpp b/SysInfo/Wmi.cpp index 7f82e10..d8f926e 100644 --- a/SysInfo/Wmi.cpp +++ b/SysInfo/Wmi.cpp @@ -1023,7 +1023,7 @@ BOOL CWmi::GetVideoAdapters(CVideoAdapterList *pMyList) } } -BOOL CWmi::GetNetworkAdapters(CNetworkAdapterList *pMyList) +BOOL CWmi::GetNetworkAdapters(CNetworkAdapterList *pMyList, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { ASSERT( pMyList); @@ -1047,29 +1047,29 @@ BOOL CWmi::GetNetworkAdapters(CNetworkAdapterList *pMyList) while (m_dllWMI.MoveNextEnumClassObject()) { myObject.Clear(); - lIfIndex = m_dllWMI.GetRefElementClassObjectDwordValue( _T( "Element"), _T( "InterfaceIndex")); + lIfIndex = m_dllWMI.GetRefElementClassObjectDwordValue( _T( "Element"), _T( "InterfaceIndex"), m_uFlag); myObject.SetIfIndex( lIfIndex); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "AdapterType")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "AdapterType"), m_uFlag); myObject.SetType( csBuffer); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "ProductName")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "ProductName"), m_uFlag); myObject.SetDescription( csBuffer); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Speed")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Speed"), m_uFlag); myObject.SetSpeed( csBuffer); - csMacAddress = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "MACAddress")); + csMacAddress = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "MACAddress"), m_uFlag); myObject.SetMACAddress( csMacAddress); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "IPAddress")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "IPAddress"), m_uFlag); myObject.SetIPAddress( csBuffer); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "IPSubnet")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "IPSubnet"), m_uFlag); myObject.SetIPNetMask( csBuffer); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DefaultIPGateway")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DefaultIPGateway"), m_uFlag); myObject.SetGateway( csBuffer); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DHCPServer")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DHCPServer"), m_uFlag); myObject.SetDhcpServer( csBuffer); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue(_T("Setting"), _T("MTU")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue(_T("Setting"), _T("MTU"), m_uFlag); myObject.SetMtu(csBuffer); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Status")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Status"), m_uFlag); myObject.SetStatus( csBuffer); - csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "AdapterType")); + csBuffer = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Element"), _T( "AdapterType"), m_uFlag); myObject.SetTypeMIB( csBuffer); AddLog( _T( "\t\t\n"), myObject.GetIfIndex(), myObject.GetType(), myObject.GetDescription(), myObject.GetSpeed(), @@ -1835,7 +1835,7 @@ BOOL CWmi::GetDomainOrWorkgroup( CString &csDomain) } -BOOL CWmi::GetLoggedOnUser( CString &csUser) +BOOL CWmi::GetLoggedOnUser( CString &csUser, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { // If not WMI connected => cannot do this if (!m_bConnected) @@ -1850,10 +1850,10 @@ BOOL CWmi::GetLoggedOnUser( CString &csUser) { while (m_dllWMI.MoveNextEnumClassObject()) { - if (m_dllWMI.GetRefElementClassObjectDwordValue( _T( "Dependent"), _T( "LogonType")) == 2) + if (m_dllWMI.GetRefElementClassObjectDwordValue( _T( "Dependent"), _T( "LogonType"), m_uFlag) == 2) { // This is an interactive session - csUser = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Antecedent"), _T( "Name")); + csUser = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Antecedent"), _T( "Name"), m_uFlag); AddLog( _T( "\t\t\n"), csUser); uIndex++; } @@ -1876,7 +1876,7 @@ BOOL CWmi::GetLoggedOnUser( CString &csUser) return FALSE; } -BOOL CWmi::GetUserDomain( CString &csDomain) +BOOL CWmi::GetUserDomain( CString &csDomain, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag) { BOOL bResult = FALSE; @@ -1893,10 +1893,10 @@ BOOL CWmi::GetUserDomain( CString &csDomain) { while (m_dllWMI.MoveNextEnumClassObject()) { - if (m_dllWMI.GetRefElementClassObjectDwordValue( _T( "Dependent"), _T( "LogonType")) == 2) + if (m_dllWMI.GetRefElementClassObjectDwordValue( _T( "Dependent"), _T( "LogonType"), m_uFlag) == 2) { // This is an interactive session - csDomain = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Antecedent"), _T( "Domain")); + csDomain = m_dllWMI.GetRefElementClassObjectStringValue( _T( "Antecedent"), _T( "Domain"), m_uFlag); AddLog( _T( "\t\t\n"), csDomain); uIndex++; } diff --git a/SysInfo/Wmi.h b/SysInfo/Wmi.h index b4a51fa..36f62b7 100644 --- a/SysInfo/Wmi.h +++ b/SysInfo/Wmi.h @@ -49,8 +49,8 @@ class SYSINFO_API CWmi BOOL GetOS( CString &csName, CString &csVersion, CString &csComment, CString &csDescription, CString &csInstallDate); DWORD GetAddressWidthOS(); BOOL GetDomainOrWorkgroup(CString &csDomain); - BOOL GetLoggedOnUser( CString &csUser); - BOOL GetUserDomain(CString &csDomain); + BOOL GetLoggedOnUser( CString &csUser, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); + BOOL GetUserDomain(CString &csDomain, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); BOOL GetInputDevices( CInputDeviceList *pMyList); BOOL GetSystemPorts( CSystemPortList *pMyList); BOOL GetPrinters( CPrinterList *pMyList); @@ -60,7 +60,7 @@ class SYSINFO_API CWmi BOOL GetMemorySlots( CMemorySlotList *pMyList); BOOL GetModems( CModemList *pMyList); BOOL GetMonitors( CMonitorList *pMyList); - BOOL GetNetworkAdapters( CNetworkAdapterList *pMyList); + BOOL GetNetworkAdapters( CNetworkAdapterList *pMyList, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag); BOOL GetSoundDevices( CSoundDeviceList *pMyList); BOOL GetStoragePeripherals( CStoragePeripheralList *pMyList); BOOL GetSystemControllers( CSystemControllerList *pMyList); diff --git a/TestSysInfo/TestSysInfoDlg.cpp b/TestSysInfo/TestSysInfoDlg.cpp index 1f5ab89..f853ed0 100644 --- a/TestSysInfo/TestSysInfoDlg.cpp +++ b/TestSysInfo/TestSysInfoDlg.cpp @@ -1656,75 +1656,75 @@ void CTestSysInfoDlg::OnBnClickedWmi() CString str, res; str = _T( "InterfaceIndex = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "InterfaceIndex")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "InterfaceIndex"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "AdapterType = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "AdapterType")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "AdapterType"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "ProductName = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "ProductName")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "ProductName"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "MaxSpeed = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Speed")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Speed"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "Manufacturer = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Manufacturer")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Manufacturer"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "Caption = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Caption")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Caption"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "Description = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Description")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Description"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "MACAddress = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "MACAddress")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "MACAddress"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "IPAddress = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "IPAddress")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "IPAddress"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "IPSubnet = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "IPSubnet")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "IPSubnet"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "DefaultIPGateway = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DefaultIPGateway")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DefaultIPGateway"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "DNSDomain = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DNSDomain")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DNSDomain"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "DNSSearchOrder = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DNSSearchOrder")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DNSSearchOrder"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "DHCPEnabled = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DHCPEnabled")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DHCPEnabled"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "DHCPServer = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DHCPServer")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Setting"), _T( "DHCPServer"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "Status = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Status")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "Status"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "NetConnectionStatus = "); - res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "NetConnectionStatus")); + res = myWmiDll.GetRefElementClassObjectStringValue( _T( "Element"), _T( "NetConnectionStatus"), WBEM_FLAG_RETURN_WBEM_COMPLETE); str += res; m_List.AddString( str); str = _T( "IPEnabled = "); - res.Format( _T( "%lu"), myWmiDll.GetRefElementClassObjectDwordValue( _T( "Setting"), _T( "IPEnabled"))); + res.Format( _T( "%lu"), myWmiDll.GetRefElementClassObjectDwordValue( _T( "Setting"), _T( "IPEnabled"), WBEM_FLAG_RETURN_WBEM_COMPLETE)); str += res; m_List.AddString( str); m_List.AddString( _T( "")); @@ -2965,7 +2965,7 @@ BOOL CTestSysInfoDlg::runSysInfo() CSysInfo mySysInfo( TRUE, szTempPath); // Get logged on user - if (!mySysInfo.getUserName( cs1)) + if (!mySysInfo.getUserName( cs1, WBEM_FLAG_RETURN_WBEM_COMPLETE)) AfxMessageBox( _T( "Failed to get username !")); m_Device.SetLoggedOnUser( cs1); // Last logged on user @@ -2987,7 +2987,7 @@ BOOL CTestSysInfoDlg::runSysInfo() AfxMessageBox( _T( "Failed to get Domain or Workgroup information !")); m_Device.SetDomainOrWorkgroup( cs1); // Get NT user Domain - if (!mySysInfo.getUserDomain( cs1)) + if (!mySysInfo.getUserDomain( cs1, WBEM_FLAG_RETURN_WBEM_COMPLETE)) AfxMessageBox( _T( "Failed to get User Domain information !")); m_Device.SetUserDomain( cs1); // Get BIOS information