UNSOLVED

JohnRChick

updated

21 years ago

J

JohnRChick

94 Posts

0

2725

April 30th, 2005 18:00

Dos If Statements

Hey. I'm trying to create a startup script for a couple computers on my network. I want the script to do different things depending on the name of the computer. I tried: If net name == John.... and I get an error about name being unexpected. Am i doing the format correctly, or is this not possible?
 
Thanks
John
  • chuket

    1388 Posts

    127

    0

    Posted May 1st, 2005 23:00

    I'm no expert on VBS files but this will run on WinXP and possibly on 98. To play with the file on your computer, change/(substitute) " john" to your username on your computer. This will only give you a start on what you're trying to accomplish. This file only gives a greeting/instructions to the user. If you want it to do more than that, a book on VBS files would probably be needed. Copy/Paste the text below to Notepad and 'save as' Anyname .vbs to the desktop.
     
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    'uc = ucase(WshNetwork.UserName)
    u = (WshNetwork.UserName)
    'The following line can be rem'd out after debugging " ' "
    WScript.echo u
    Set wshShell = WScript.CreateObject("WScript.Shell")
    If Not u = "john" Then x = MsgBox ("This computer is not John's", 16, "Computer Identity")
    If  u = "john" then x = MsgBox ("Welcome to the Network, "+ u  & (Chr(13)) & "" & (Chr(13)) & "This is a test of the text" & (Chr(13)) & "that can be displayed" & (Chr(13)) & "for the user named John", 64, "Welcome " +u)
    WScript.quit

    Message Edited by chuket on 05-01-2005 09:03 PM

  • jwatt

    4446 Posts

    127

    0

    Posted May 2nd, 2005 05:00

    Here's a minor tweak to chuket's script that will make it retrieve the name of the computer rather than the name of the logged-in user:

    Set WshNetwork = WScript.CreateObject("WScript.Network")
    'uc = ucase(WshNetwork.UserName)
    ' u = (WshNetwork.UserName)
    u = WshNetwork.ComputerName
    'The following line can be rem'd out after debugging " ' "
    WScript.echo u
    Set wshShell = WScript.CreateObject("WScript.Shell")
    If Not u = "john" Then x = MsgBox ("This computer is not John's", 16, "Computer Identity")
    If u = "john" then x = MsgBox ("Welcome to the Network, "+ u & (Chr(13)) & "" & (Chr(13)) & "This is a test of the text" & (Chr(13)) & "that can be displayed" & (Chr(13)) & "for the user named John", 64, "Welcome " +u)
    WScript.quit


    That changes the value of the variable "u" from the user name to the computer name.

    Jim