Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the IF statement and computername ??

Status
Not open for further replies.

djlax152

IS-IT--Management
Jun 20, 2003
18
US
Okay according to out current domain sturcture i no longer have access to group policys. So i am trying to map my printers by way of a logon script. I have a naming scheme for my computers so this is what i want to do. I would like to script that uses an if statement that checks the computername and maps to the correct printer.

This is my script so far
The problem with this script
is that the computername that i am working on is 5001-Admin01 and it will not install the printers?? if i put a ( ' ) in front of my "IF" and my "End if" it ends up installing. Why would this script not map my printers if the computername is what it says it is in the script? Am i missing something ?

'Map Printers for Shenandoah
'Drew Dorben Jan 28th
'---------------------------'

Option Explicit

'Declaring Variables
Dim obj2200
Dim obj810c
Dim unc2200CL
Dim unc810ccl
Dim Objcomputername
Dim Computername

'Set type
Set obj2200 = CreateObject("Wscript.Network")
Set obj810c = CreateObject("Wscript.Network")
Set objcomputername = Wscript.CreateObject("Wscript.Network")

'Introducing values to variables
UNC2200cl = "\\5001-CL31-6488\2200"
unc810ccl = "\\5001-CL31-6488\810c"
computerName = objcomputername.ComputerName

'Script body

if Computername = 5001-admin01 Then
obj2200.AddWindowsPrinterConnection UNC2200cl
obj810c.addwindowsprinterConnection Unc810ccl
wscript.echo "Printers were connected successfully"

End if

'Confirmation

 
have you tried changing this line..
Code:
if Computername = 5001-admin01 Then

to...
Code:
if Computername = "5001-admin01" Then

I know it's kinda obvious, but when you're testing a string, you need quotes.
 
Yeah actually i made a mistake when i posted the topic.
It does actually look like

if Computername = "5001-admin01" Then
obj2200.AddWindowsPrinterConnection UNC2200cl
obj810c.addwindowsprinterConnection Unc810ccl
wscript.echo "Printers were connected successfully"

End if

Nothing happens when i double click on the vbs file it doesnt do anything
 
If this is VBS then I suggest you try the VBS forum (forum329)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
have you tried to debug this using either

Code:
MsgBox Computername
if Computername = "5001-admin01" Then
    obj2200.AddWindowsPrinterConnection UNC2200cl
    obj810c.addwindowsprinterConnection Unc810ccl
    wscript.echo "Printers were connected successfully"
    
End if

or..
Code:
Debug.Print Computername
if Computername = "5001-admin01" Then
    obj2200.AddWindowsPrinterConnection UNC2200cl
    obj810c.addwindowsprinterConnection Unc810ccl
    wscript.echo "Printers were connected successfully"
    
End if

What does that show for a result?

 
Okay for
msgbox computername I get a popup with
5001-ADMIN01

FOR debug.print i get
a windows script host ERROR

Line 27
Char 1
Object doesnt support this property or Method 'Debug.Print'
Code 800A01B6
Source Microsoft VBScript runtime error

Sorry about posting in the wrong category i thought this was the right one
 
well, don't use the debug.print then..

try this.. It looks like your cases aren't matching.

Code:
if ucase(Computername) = "5001-ADMIN01" Then

just make sure you always type your machine names in CAPS or if you use a variable for the machine name use something like this..

Code:
if Ucase(Computername) = UCase(variable) Then
 
As I said, that's the problem with being in the wrong forum!
Please post this question in the right forum and then RedFlag your original question to avoid confusing others.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top