Results 1 to 6 of 6

Thread: Comparing db value to WMI value, something not working ...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    MS
    Posts
    22

    Comparing db value to WMI value, something not working ...

    One value is from a WMI call to get a computer's physical memory, I place this value in a database, when I run the script again I compare the WMI call value to what is in the database. Im doing this to see if the memory was tampered with. But the values are ALWAYS returning as not equal. Even though they appear to be equal. I checked them and they are both also showing as "numeric". Any suggestions?

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: Comparing db value to WMI value, something not working ...

    Originally posted by skid2964
    One value is from a WMI call to get a computer's physical memory, I place this value in a database, when I run the script again I compare the WMI call value to what is in the database. Im doing this to see if the memory was tampered with. But the values are ALWAYS returning as not equal. Even though they appear to be equal. I checked them and they are both also showing as "numeric". Any suggestions?
    What language are you using, vb, c# etc. Post your code, we might be able to fix your problem.

    Try converting both value to same type(e.g. Long) and then compare it.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    MS
    Posts
    22
    Ooops, the language is VB script ...

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by skid2964
    Ooops, the language is VB script ...
    Post your code if possible.

    In vb i know WMI returns the RAM as long.

    How are you comparing the value?

    Try somethinglike

    if str(MemStat.dwTotalPhys)=str(yourvalue) then
    'is equal
    else
    'not equal
    end if

    you could also try strcnv, like i said if you post your code i could probably fix your problem.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    MS
    Posts
    22
    Here is my code ...

    Code:
    'Sub to get physical memory, I then pass this to the
    "Opendatabase_Write_Data" sub below ....
    
    Sub Get_Win32_ComputerSystem_Info
    
     Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
    	
    	For Each objItem in colItems
    	
    	Machine_Domain = objItem.Domain
    	Machine_Manufacturer = objItem.Manufacturer
    	Machine_Model_Number = objItem.Model
    	Machine_Physical_Memory = (objItem.TotalPhysicalMemory \ 1048576)
    	
    	Next
    	
    	   
     objItem = Null
     Set colItems = Nothing	
     
    End Sub	
    
    
    'Sub for comparing ,then writing data ......
    
    Sub OpenDatabase_Write_Data(FieldName, NewValue)
    
     Dim objConnection, objRSinfo, objRSchange
     Dim infostr, changestr, lcstr, OldValue
     
     Set objConnection = CreateObject("ADODB.Connection")
     objConnection.Open "Provider=sqloledb;" &_
    	  				"Data Source=" & SourceServer & ";" &_
    					"Initial Catalog=" & InitCatalog & ";" &_
    					"User ID=" & dbUser & ";" &_
    					"Password=" & dbPass & ";"
    
     Set objRSinfo = CreateObject("ADODB.Recordset")
     infostr = "Select " & FieldName & " from POS_Machine_Info Where Machine_Name = '" & Machine_Name & "'" 
     objRSinfo.Open infostr,objConnection,3,3
     
     Set objRSchange = CreateObject("ADODB.Recordset")
     changestr = "Select * from POS_Detect_Change" 
     objRSchange.Open changestr,objConnection,3,3
      
    		If Not IsNull(objRSinfo.fields(0).Value) Then
    					
    			OldValue = objRSinfo.Fields(0).Value
    	
    			If OldValue <> NewValue Then
    						
    				objRSinfo(FieldName) = NewValue
    				objRSinfo.Update
    				
    					objRSchange.AddNew
    					objRSchange("Machine_Name") = Machine_Name
    					objRSchange("Changed_Column") = FieldName
    					objRSchange("Changed_From") = OldValue
    					objRSchange("Changed_To") = NewValue
    					objRSchange("Changed_TimeStamp") = Now 
    					objRSchange.Update
    						
    			End If
    				
    		Else
    					
    			objRSinfo(FieldName) = NewValue
    			objRSinfo.Update
    			
    		End If
    				
     objRSinfo.Close
     objRSchange.Close
     objConnection.Close
     
     x = Null
     infostr = Null
     changestr = Null
     lcstr = Null
     Set objConnection = Nothing
     Set objRSinfo = Nothing
     Set objRSchange = Nothing
     
    End Sub

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    MS
    Posts
    22
    I got it ..... I found this: VarType(Variable), I checked to see of what data type each of my variables were, then adjusted as nessecary. The OldValue was a string, the Newvalue was a Long, as other posts have suggested it may be, ... So I converted the NewValue to a string during the checking process. All is well...

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width