Solved

VBS script

Posted on 2009-03-30
1
567 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

724 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