Jump to content

RunOnceEx WMIC IF statement


Recommended Posts

I'm trying to deploy XP SP2 with a base install of applications and am doing so through RunOnceEx That part works, but I want to install additional software on a particular laptop, workstation. I only have four types of Dell machines.

At the end of RunOnceEx I'd like to do a query using WMIC - wmic baseboard get product and do an if statement. Basically if wmic output matches 0KU184 (that's a Latitude D630) it should run another batch file that would install D630 specific applications if it doesn't match then it should compare it to all the other codes I have (for D630, GX620,...).

I really don't know how to better describe it, since my knowledge of wmic and even more if statements is very low. It should be something like this:

if "wmic baseboard get product"=="0KU184" run d630.bat if not see if it matches 0KX350 (D620) and so on and so on. I have 10 codes like that (for the four Dell machine types).

Any assistance would be greatly appreciated.

Link to comment
Share on other sites


Something like this perhaps!

@echo off
for /f "skip=1" %%? in ('wmic baseboard get product') do (
if %%?' equ 0KU184' (call d630.cmd) else (
if %%?' equ X0X0X0' (call gx620.cmd) else (
if %%?' equ X0XX0X' (call xxnnn.cmd) else (
if %%?' equ 0X0X0X' (call xnnn.cmd) else (
echo/ no match found&&ping -n 6 127.0.0.1>nul)))))

Link to comment
Share on other sites

I've put together this:

@echo off
for /f "skip=1" %%? in ('wmic baseboard get product') do (
if %%?' equ 0TD761' (call d620.cmd) else (
if %%?' equ 0KX350' (call d620.cmd) else (
if %%?' equ 0JK187' (call d620.cmd) else (
if %%?' equ 0FT292' (call d620.cmd) else (
if %%?' equ 0KU184' (call d630.cmd) else (
if %%?' equ 0HH807' (call gx620.cmd) else (
if %%?' equ 0F8096' (call gx620.cmd) else (
if %%?' equ 0FH884' (call gx620.cmd) else (
if %%?' equ 0WF810' (call 745.cmd) else (
if %%?' equ 0RF705' (call 745.cmd) else (
if %%?' equ 0KG317' (call 745.cmd) else (
echo/ no match found&&ping -n 6 127.0.0.1>nul)))))

but for some reason it won't return anything (most of the time). I tried multiple OS's, computers.

Even the before posted code sometimes just doesn't provide any results. Also if I just run wmic I get nothing. Restarting cmd prompt helps with just wmic, but the batch files just don't provide the result on a consistent basis.

Any idea what's wrong?

Link to comment
Share on other sites

In the first instance you will need to fix the code you've supplied!

You've failed to close all of the paraetheses.

The last line should say

  echo/ no match found&&ping -n 6 127.0.0.1>nul))))))))))))

Link to comment
Share on other sites

Thank you yet again Yzöwl.

I changed it accordingly and the batch file still wouldn't run properly. It seems that the batch file name of wmic.cmd has something to do with it. I rename that to anything else and it works as it should.

Link to comment
Share on other sites

Thank you yet again Yzöwl.

I changed it accordingly and the batch file still wouldn't run properly. It seems that the batch file name of wmic.cmd has something to do with it. I rename that to anything else and it works as it should.

Try to avoid naming program files or batch files after files on the system that already exist, unless you're passing the entire path to the file when calling it :).

Link to comment
Share on other sites

Try to avoid naming program files or batch files after files on the system that already exist, unless you're passing the entire path to the file when calling it :).

Lesson learned ;)

I came across another problem. Hopefully I won't make a mess if I continue with it in this post.

This is my RunOnceEx (I left out most of it since the middle part isn't all the important. All the software installs without issues) which is executed from cmdlines.txt:

@echo off
cwnd /hide @

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

REG ADD %KEY% /V TITLE /D "Installing Applications" /f

REG ADD %KEY%05 /VE /D ".NET Framework 1.1 + SP1 + KB928366" /f
REG ADD %KEY%05 /V 1 /D "%systemdrive%\install\applications\dotnet11\dotnetfx.exe /q /c:\"install /q\"" /f
REG ADD %KEY%05 /V 2 /D "%systemdrive%\install\applications\dotnet11\NDP1.1sp1-KB867460-X86.exe /q" /f
REG ADD %KEY%05 /V 3 /D "%systemdrive%\install\applications\dotnet11\NDP1.1sp1-KB928366-X86.exe /q" /f

REG ADD %KEY%\105 /VE /D "Windows Media Player 10.0" /f
REG ADD %KEY%\105 /V 1 /D "%systemdrive%\install\applications\WMP10\mpsetupedp.msi /quiet /norestart" /f

REG ADD %KEY%\110 /VE /D "Installing model specific applications" /f
REG ADD %KEY%\110 /V 1 /D "%systemdrive%\install\models.cmd" /f

EXIT

My models.cmd (which is situated in %systemdrive%\install):

@echo off
for /f "skip=1" %%? in ('wmic baseboard get product') do (
if %%?' equ 0TD761' (call d620.cmd) else (
if %%?' equ 0KX350' (call d620.cmd) else (
if %%?' equ 0JK187' (call d620.cmd) else (
if %%?' equ 0FT292' (call d620.cmd) else (
if %%?' equ 0KU184' (call d630.cmd) else (
if %%?' equ 0HH807' (call gx620.cmd) else (
if %%?' equ 0F8096' (call gx620.cmd) else (
if %%?' equ 0FH884' (call gx620.cmd) else (
if %%?' equ 0WF810' (call 745.cmd) else (
if %%?' equ 0RF705' (call 745.cmd) else (
if %%?' equ 0KG317' (call 745.cmd) else (
echo/ no match found&&ping -n 6 127.0.0.1>nul))))))))))))

And for example d620.cmd (also in %systemdrive%\install):

@echo off
cwnd /hide @

SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx

REG ADD %KEY% /V TITLE /D "Installing Latitude D620 Specific Applications" /f

REG ADD %KEY%05 /VE /D "Cisco VPN Client 4.8.01.0300" /f
REG ADD %KEY%05 /V 1 /D "%systemdrive%\install\applications\VPN\vpnclient_setup.msi REBOOT=Supress /qb" /f

REG ADD %KEY%10 /VE /D "iPass 3.51 Build 107" /f
REG ADD %KEY%10 /V 1 /D "%systemdrive%\install\applications\iPass\iPassClient.exe -s -a -s" /f

REG ADD %KEY%15 /VE /D "Cleaning Up and Rebooting" /f
REG ADD %KEY%15 /V 1 /D "%systemdrive%\install\cleanup.cmd" /f

EXIT

I'm testing this in Virtual PC 2007. The problem is models.cmd or d620.cmd aren't being executed properly during the install. I replaced one of the codes for the d620 in models.cmd with equ Virtual' so the above d620.cmd should be in my RunOnceEx.cmd but it is not.

If I manually run models.cmd after all is done, the entries in RunOnceEx do appear and subsequently the software installs without problems.

Any suggestions? Doesn't RunOnceEx run twice, have I made some other error somewhere and fail to see it,...?

Link to comment
Share on other sites

The way you currently have it set up is that the Model specific stuff is being set for installation on the next reboot after your initial first logon session.

Yes, but it doesn't appear in RunOnceEx (everything that is specified in d620.cmd). Shouldn't it be there after 1st logon? Then I'd just need another reboot and everything would install. I'll make it restart automatically once it does that)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...