Solved

Script to check computer name

Posted on 2007-04-02
5
1,683 Views
Last Modified: 2008-11-21
I need a quick VBScript that basically looks for a computer name.  When the VBScript is ran if the computer name is "k-tsvr2" then DO NOTHING if it is anything BUT k-tsvr2 then launch a batch file.
0
Comment
Question by:chrisryhal
5 Comments
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 18839164
Why do you need a vbscript... why not just use the batch file?

If "%computername%" == "k-tsvr2" GOTO End
REM --- DO EVERYTHING HERE
REM --- ETC
REM --- ETC
:End
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 18839188
Because I have a HUGE VBScript and want the code in there.  
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18839275
One way...

Dim objNet:Set objNet=CreateObject("Wscript.Network")
If objNet.ComputerName="k-tsvr2" Then Wscript.quit
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 250 total points
ID: 18839291
Probably should test for case though...

Dim objNet:Set objNet=CreateObject("Wscript.Network")
If lcase(objNet.ComputerName)="k-tsvr2" Then Wscript.quit
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 250 total points
ID: 18887120
Yeah, that will work.  You could also change that to
If lcase(objNet.ComputerName) <> "k-tsvr2" Then
  'Do everything else here
End If

This way you don't force the code to quit if you want to put stuff after this block.
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 to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

929 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

12 Experts available now in Live!

Get 1:1 Help Now