Solved

Script to check computer name

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

Industry Leaders: 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

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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