Search code examples
wmic

WMIC - how to use Lenovo SetBiosSetting method


I have a prob calling SetBiosSetting method using WMIC (and also C#)

wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting "SecurityChip,Active"

wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting SecurityChip,Active

wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting ("SecurityChip,Active")

that gives "Invalid Number of Parameters." error, but why ?

Lenovo BIOS Deployment Guide: http://download.lenovo.com/ibmdl/pub/pc/pccbbs/thinkcentre_pdf/hrdeploy_en.pdf

Any Idea ? I cant use VBS or PowerShell ...

Thanks,Martin


Solution

  • Try this in C#:

            ManagementScope scope = new ManagementScope(@"\\.\root\wmi");
    
    
            //
            // Make change(s)
            //
            SelectQuery queryRead = new SelectQuery("SELECT * from Lenovo_SetBiosSetting");
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, queryRead))
            {
                using (ManagementObjectCollection queryCollection = searcher.Get())
                {
                    foreach (ManagementObject queryItem in queryCollection)
                    {
                        ManagementBaseObject inParams = queryItem.GetMethodParameters("SetBiosSetting");
                        inParams["parameter"] = "WakeOnLAN,Disable";
    
                        ManagementBaseObject outParams = queryItem.InvokeMethod("SetBiosSetting", inParams, null);
                        string result = outParams["return"] as string; // "Success"
                    }
                }
            }
    
    
            //
            // Commit to BIOS
            //
            queryRead = new SelectQuery("SELECT * from Lenovo_SaveBiosSettings");
            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, queryRead))
            {
                using (ManagementObjectCollection queryCollection = searcher.Get())
                {
                    foreach (ManagementObject queryItem in queryCollection)
                    {
                        ManagementBaseObject inParams = queryItem.GetMethodParameters("SaveBiosSettings");
                        inParams["parameter"] = "";
    
                        ManagementBaseObject outParams = queryItem.InvokeMethod("SaveBiosSettings", inParams, null);
                        string result = outParams["return"] as string; // "Success"
                    }
                }
            }
    

    The PowerShell for this is:

    (gwmi -class Lenovo_SetBiosSetting -namespace root\wmi).SetBiosSetting("WakeOnLAN,Disable")