• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1728
  • Last Modified:

Script to check computer name

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
chrisryhal
Asked:
chrisryhal
2 Solutions
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
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
 
chrisryhalAuthor Commented:
Because I have a HUGE VBScript and want the code in there.  
0
 
sirbountyCommented:
One way...

Dim objNet:Set objNet=CreateObject("Wscript.Network")
If objNet.ComputerName="k-tsvr2" Then Wscript.quit
0
 
sirbountyCommented:
Probably should test for case though...

Dim objNet:Set objNet=CreateObject("Wscript.Network")
If lcase(objNet.ComputerName)="k-tsvr2" Then Wscript.quit
0
 
RobSampsonCommented:
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now