Scope-IT / marksman

Windows agent for Snipe-IT asset management system
Apache License 2.0
132 stars 23 forks source link

Changing asset tag to SMBiosAssetTag #15

Closed emike09 closed 5 years ago

emike09 commented 5 years ago

Hello, We're needing the agent to query the asset tag using WMI on SMBiosAssetTag to query the asset tag set in the bios of Dell laptops and desktops. Running the following from PS provides the expected result: (Get-WmiObject Win32_SystemEnclosure).SMBiosAssetTag I'm new to VS and C#, and get errors when I try to run a build: Error CS1729 'SearchFilter' does not contain a constructor that takes 1 arguments line 105 I think I can figure out the code needed to query the asset tag directly if I could get the solution to build. Any help greatly appreciated!

danielhogg commented 5 years ago

The first thing that comes to mind is - are you using the correct version of the SnipeSharp API? Marksman has a dependency on this particular version of SnipeSharp.

emike09 commented 5 years ago

That's the version I'm using, I used to get SnipeSharp errors until I added the dependancy, now the build error is related to SearchFilter. I'm assuming I can't just provide the dependencies and hit build solution?

emike09 commented 5 years ago

Looks like it can't find Location, Manufacture, Company, etc as well. With the proper snipesharp.dll added as reference, I get the following errors:

Error CS1729 'Manufacturer' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Marksman.cs 100 N/A Compiler Error CS1729 'SearchFilter' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Broker.cs 105 N/A Compiler Error CS1729 'SearchFilter' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Broker.cs 109 N/A Compiler Error CS1729 'SearchFilter' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Broker.cs 115 N/A Compiler Error CS1729 'SearchFilter' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Broker.cs 119 N/A Compiler Error CS1729 'SearchFilter' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Broker.cs 123 N/A Compiler Error CS1729 'SearchFilter' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Broker.cs 127 N/A Compiler Error CS1729 'Location' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Marksman.cs 61 N/A Compiler Error CS1729 'StatusLabel' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Marksman.cs 68 N/A Compiler Error CS1729 'Company' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Marksman.cs 75 N/A Compiler Error CS1729 'Category' does not contain a constructor that takes 1 arguments marksman C:\Users\mike.capps\source\repos\marksman2 C:\Users\mike.capps\source\repos\marksman2\Marksman.cs 93 N/A Compiler

Steps to reproduce:

  1. Clone SnipeSharp repo from github.
  2. Build SnipeSharp to obtain snipesharp.dll
  3. Clone Marksman from github
  4. Add snipesharp.dll as a reference
  5. Build Marksman solution
  6. Receive errors.

I know this has to be my own lack of understanding how VS 2017 and .NET works.

danielhogg commented 5 years ago

I am pretty sure what's going on here, as I was able to regenerate that series of errors by building SnipeSharp.dll from this link: https://github.com/barrycarey/SnipeSharp (which is the wrong version).

Here's what I got (same as your errors)

1>------ Build started: Project: marksman, Configuration: Release Any CPU ------ 1>C:\Users\Danny\code\ScopeIT\marksman\Marksman.cs(61,44,61,52): error CS1729: 'Location' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Marksman.cs(68,50,68,61): error CS1729: 'StatusLabel' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Marksman.cs(75,42,75,49): error CS1729: 'Company' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Marksman.cs(93,44,93,52): error CS1729: 'Category' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Marksman.cs(100,51,100,63): error CS1729: 'Manufacturer' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Broker.cs(105,51,105,63): error CS1729: 'SearchFilter' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Broker.cs(109,47,109,59): error CS1729: 'SearchFilter' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Broker.cs(115,44,115,56): error CS1729: 'SearchFilter' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Broker.cs(119,46,119,58): error CS1729: 'SearchFilter' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Broker.cs(123,50,123,62): error CS1729: 'SearchFilter' does not contain a constructor that takes 1 arguments 1>C:\Users\Danny\code\ScopeIT\marksman\Broker.cs(127,47,127,59): error CS1729: 'SearchFilter' does not contain a constructor that takes 1 arguments 2>------ Skipped Build: Project: MarksmanSetup, Configuration: Release ------ 2>Project not selected to build for this solution configuration ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========

Then I was able to get it to build without errors by building SnipeSharp.dll from our fork of SnipeSharp (we have made some API changes): https://github.com/Scope-IT/SnipeSharp

Try following these steps: 1) Go to your marksman project, and remove the SnipeSharp reference 2) Clone our fork of SnipeSharp: https://github.com/Scope-IT/SnipeSharp 3) Build that project 4) Re-add the resulting SnipeSharp.dll as a reference to your marksman project

emike09 commented 5 years ago

Well that seemed to resolve it! Thanks for the help.

Now to figure out how to query the SMBIOSAssetTag from wbemtest. SELECT SMBIOSAssetTag FROM Win32_SystemEnclosure doesn't seem to pull the correct information.

emike09 commented 5 years ago

Figured that out as well. I've forked the project with the changes.

127: string assettag = GetOutputVariable("Win32_SystemEnclosure.SMBIOSAssetTag"); 143: AssetTag = appSettings["AssetTagPrefix"] + assettag, 328: mySentry.AddQuery("WMI", "SELECT SMBIOSAssetTag FROM Win32_SystemEnclosure");