If there is always only one IP Address, and at login that address is already determined, and both of your shown WMIC queries return actual values, i.e. they are never empty, then I would say it could certainly be made more efficient.
The reason is that WMIC.exe is historically a relatively slow command to run, so you could speeed things up by only calling it once. Given that idea, you may as well retrieve your IP Address using it too, instead of running and parsing another command utility, IPCONFIG.
So this idea would run WMIC only once, and parse it in just a single FOR loop, instead of the five FOR loops you've implemented:
Code: Select all
@For /F Tokens^=6-10^ Delims^=^" %%G In ('
( Echo(NICConfig Where IPEnabled^='TRUE' Get IPAddress /Format:MOF ^&
Echo(BIOS Get SerialNumber /Format:MOF ^&
Echo(CSProduct Get Name /Format:MOF^) ^| %SystemRoot%\System32\wbem\WMIC.exe
') Do @If "%%K" == "" (If Defined SN (Set "PC=%%G") Else Set "SN=%%G"
) Else Set "IP=%%I"
@( Echo Event,Date,Time,Device,User,IP,SN,Model
I've also used the full path to the location of the WMIC utility, as leaving it out would mean that the file would need to be searched within the current directory, and if not located there within each location listed within %PATH%, in order first to last, until found. I have also included the extension for the utility too, as missing it out means that each extension listed within %PATHEXT%, in order first to last, would need to be suffixed during such a search, until a match is found. Obviously both of these tasks must consume unnecessary time and resources, which I'd deem inefficient.