?
Solved

Script to check computer name

Posted on 2007-04-02
5
Medium Priority
?
1,716 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
[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
5 Comments
 
LVL 96

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 1000 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

771 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