Solved

Script to check computer name

Posted on 2007-04-02
5
1,677 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
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…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

21 Experts available now in Live!

Get 1:1 Help Now