Mombu the Microsoft Forum

  Mombu the Microsoft Forum > Microsoft > Windows 2003 Server (TECHNET) > Is it possible to use a predefined variable for group name as foll


User Name
Password
REGISTER NOW! Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread Display Modes
1 1st May 19:47
river
External User
 
Posts: 1
Default Is it possible to use a predefined variable for group name as foll



My goal is to define names at the beginging of the script so I do not have to
edit the script when a name changes. Is it possible to speicfy a groupname
variable as I have done for the printer name.


This scritp works:


On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)


strUNCPrinter = "\\00wa1svr02\wa1-it-01"


For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

Select Case strGroupName
Case "prnDefault WA1-IT-01"
objNetwork.SetDefaultPrinter strUNCPrinter

End Select
Next

This script does not work

On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)


GroupName = "prnDefault WA1-IT-01
strUNCPrinter = "\\00wa1svr02\wa1-it-01"


For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

Select Case strGroupName
Case "prnDefault WA1-IT-01"
objNetwork.SetDefaultPrinter strUNCPrinter

End Select
Next
  Reply With Quote
SPONSORED LINKS BY GOOGLE

 


2 3rd May 22:23
al dunbar
External User
 
Posts: 1
Default Is it possible to use a predefined variable for group name as foll



How do you expect to process different names without editing the script to
change the name defined at the beginning??

how does it fail to work?

above line is missing the final double-quote. But, beyond that, once you
have defined this variable, you never use it again.

Now, had you changed the above line to:


then it might have had the effect you were looking for.

As for the strGroupName variable used in both scripts, it is created and
then used immediately and only once. How is this:


Any better than this:

/Al
  Reply With Quote
3 3rd May 22:25
river
External User
 
Posts: 1
Default Is it possible to use a predefined variable for group name as


I just realized I made and error while posting a portion of my script and
ended up posting an incorrect version. Let me try this again. And let me say
my scripting abilities are very limited, i am still learning here.

I am trying to define a list of resources at the head of the script so when
those names change I can just edit the start of the script.

Example:

strUNCPrinter1 = "\\00wa1svr02\wa1-it-01"

objNetwork.SetDefaultPrinter strUNCPrinter1

I thought maybe I could do that with the group name also

GroupName1 = "prnDefault WA1-IT-01"


For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN

Select Case strGroupName
Case "GroupName1"
objNetwork.SetDefaultPrinter strUNCPrinter

If I do not define a name in the begining and use the groupname in the line

Select Case strGroupName
Case "prnDefault WA1-IT-01"

I have no issues.

I am probably trying to make a change that just makes this more complicated
than it needs to be.
  Reply With Quote
4 3rd May 22:26
al dunbar
External User
 
Posts: 1
Default Is it possible to use a predefined variable for group name as


As are we all ...


Ah, that is kind of what I thought. The idea makes sense, as it can be
devilishly hard to change literal constants throughout a script without
causing yourself some grief.


You certainly can. But I would recommend that all of these values be defined
at the very top of your script so you will be sure to make all of the
required changes when you modify the script for the next run.


Here is your first mistake - a simple one and fairly common for beginners
and/or people converting from other scripting technologies such as kixtart.
Putting the name of a variable in parenthesis causes it to be treated
literally. That is it becomes a string whose value is, coincidentally, the
same as the NAME of a variable. But it does not reference that variable in
any way. As written, your script will set the default printer when it finds
a group whose name is, literally, "GroupName1"; it will NOT do anything when
it runs across a group whose name is the same as the value assigned to the
variable whose name is GroupName1.

That is a rather wordy explanation that may or may not help. Here is a
simpler one: when you want to work with the value represented by a variable,
DO NOT ENCLOSE IT IN QUOTES.

If you change your line above to this:


I suspect that you will find that it works in the way you desire.


Note that even if you DO define the variable, the above works because
"prnDefault WA1-IT-01" is the actual value you are looking for.


No. In fact what you are trying to do is a good thing. You just need a
little help with some of the details. Make the change I suggested above to
the case statement, and let us know how it goes.


One other question, in anticipation of what might be another
misunderstanding on your part: I see you have given your variables slightly
different names this time from the first post you made, strUNCPrinter1 and
GroupName1 instead of strUNCPrinter and GroupName. What, in your mind, does
the "1" represent? /Al
  Reply With Quote
SPONSORED LINKS BY GOOGLE

 


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes







Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
Also visit Ogoun the Usenet Archive
666