Solved

VBS script

Posted on 2009-03-30
1
544 Views
Last Modified: 2012-05-06
Hello,
i'm new with typing VBS and i would like create VBS script which is get the model number ( for ex. dell latitude 630) and if the VBS script found that the machine type is Dell 630 then execute one batch file. I would like to also do this just one time on each dell 630 machine. I hope that my explenation is clear if not please let me know.

Thank you for your help
0
Comment
Question by:jarmo666
1 Comment
 
LVL 14

Accepted Solution

by:
rejoinder earned 125 total points
ID: 24022684
Try this.  You may need to uncomment the line;
'wscript.echo strModel
to see what text is being compared.
Change the line;
strEXE = """C:\Some Batch File.bat"""
Change the variable to point to the batch file, vbs or whatever.
There are two other variables that will be searched to see if the script has run;
Const strResistryLoc  = "SOFTWARE\Helpdesk"
Const strTestRegistry = "Dell-Batch-File"
These point to the local users registry but can be modified to the local machine.  Anyway, each time the script is run, it will look for a preset registry entry.  If found it will compare the number against the version number on line 7.  If the registry key is less than or equal to the script version number, the script will end.  Otherwise, the script will execute and set the value in the registry.
Const wbemFlagReturnImmediately = &h10

Const wbemFlagForwardOnly = &h20

Const strResistryLoc  = "SOFTWARE\Helpdesk"

Const strTestRegistry = "Dell-Batch-File"

Const HKEY_CURRENT_USER = &H80000001

Const HKEY_LOCAL_MACHINE = &H80000002

Const Version = 1
 

strComputer = "."
 

if NOT FindRegKey(strComputer) then

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

    Set colItems = objWMIService.ExecQuery("SELECT Model FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)

    For Each objItem In colItems

        strModel = trim(objItem.Model)

    Next

    

    'wscript.echo strModel

    

    if lcase(strModel) = lcase("Dell Latitude 630") then

        set objShell = wscript.createobject("wscript.shell")

        strEXE = """C:\Some Batch File.bat"""

        objShell.run strEXE,0,TRUE

    end if

    CreateRegKey(strComputer)

End if
 

Function FindRegKey(Computer)

    Set objReg   = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\default:StdRegProv")

    strKeyPath   = strResistryLoc

    strValueName = strTestRegistry

    objReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

    if IsNull(strValue) then

        strValue = 0

    end if

    if Version > CInt(strValue) then

        FindRegKey = False

    else

        FindRegKey = True

    end if

End Function

 

Sub CreateRegKey(Computer)

    Set objReg   = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\default:StdRegProv")

    strKeyPath   = strResistryLoc

    strValueName = strTestRegistry

    strValue     = CSTR(Version)

    Return       = objReg.CreateKey(HKEY_CURRENT_USER, strKeyPath)

    objReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now