Page 2 of 2 <12
Topic Options
#200546 - 2010-11-09 03:02 PM Re: problem reading af file for use in script [Re: roundup]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
This might be able to be simplified by the following:
 Code:
[00:25:9C:AD:43:D6]
Location=Preparation
Groups=students,teachers,aides

[students_00:25:9C:AD:43:D6]
Share=HP LaserJet 1320nw - Support:LaserJet1

[teachers_00:25:9C:AD:43:D6]
Shares= HP LaserJet 1320nw - Support:LaserJet1,Xerox WorkCentre 7345:Xerox1
In this manner, you can directly look up the BSID MAC and determine the location and allowed groups. Split the groups list and do an InGroup - if a group matches, then read the section that combines the group and MAC identities and map the shares listed there.

Trying to combine the group and MAC directly adds unnecessary overhead and complexity. it also provides more flexibility to expand beyond two hard-coded groups.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#200549 - 2010-11-09 10:41 PM Re: problem reading af file for use in script [Re: Glenn Barnas]
Shanee Offline
Fresh Scripter

Registered: 2006-10-13
Posts: 39
Loc: Tulsa, OK
I agree. This eliminates the need to edit the script to add further groups.

 Code:
$mac = GetBSSID(1,@WkSta)
$location = ReadProfileString ($LogonServer+"\NETLOGON\printer.ini", $mac, "Location")
$groups = ReadProfileString ($LogonServer+"\NETLOGON\printer.ini", $mac, "Groups")
$groups = Split($groups,",")

For Each $group in $groups
   If InGroup($group)
      $shares = ReadProfileString ($LogonServer+"\NETLOGON\printer.ini", $mac+":"+$group, "Shares")
      $shares = Split($shares,",")
      $sharenum = 0
      For Each $shareobj in $shares
         $name = Split($shareobj,":")[0]
         $share = Split($shareobj,":")[1]
         If AddPrinterConnection("\\server\"+$share) = 0
            If $sharenum = UBound($shares)
               $null = SetDefaultPrinter("\\server\"+$name)
            EndIf
         Else
            $null = MessageBox("2 Der er et problem med at etablerer forbindelse til : "+$share,"Printer fejl",0)
         EndIf
         $sharenum = $sharenum+1
      Next
   EndIf
Next


 Code:
[00:25:9C:AD:43:D6]
Location = Preparation
Groups = Student,Teacher,Admin

[00:25:9C:AD:43:D6:Teacher]
Shares = HP LaserJet 1320nw - Support:LaserJet1,Xerox WorkCentre 7345:Xerox1

[00:25:9C:AD:43:D6:Student]
Shares = HP LaserJet 1320nw - Support:LaserJet1

[00:25:9C:AD:43:D6:Admin]
Shares = HP LaserJet 1320nw - Support:LaserJet1,Xerox WorkCentre 7345:Xerox1,Other Admin Printer:Admin1

Top
#200550 - 2010-11-10 01:05 AM Re: problem reading af file for use in script [Re: Shanee]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
umm - yup!

Simplifies the logic and provides easier growth or adaptation by placing the control (group names) in the data instead of the code. \:\)

One note about your code - if a user is a member of multiple groups, then the printer for each group will be mapped. This may or may not be desireable. If it isn't, simply list the groups in order of importance. The code change is simple - Change the For loop slightly, using:
 Code:
$Tag = 1
For Each $Group in $Groups
  If InGroup($Group) And $Tag
    $Tag = 0       ; don't allow additional group comparison actions

    :

  EndIf
Next
The $Tag at the start allows an InGroup comparison to continue.. the first group match clears $Tag, preventing further group comparison If statements to succeed and process the printer map.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#200622 - 2010-11-15 09:23 PM Re: problem reading af file for use in script [Re: Glenn Barnas]
roundup Offline
Fresh Scripter

Registered: 2010-10-29
Posts: 11
Loc: Denmark
Hi Glenn

Can you show me how the finale kix-code will look like, with the use of you $Tag code please!?

Kind regards
roundup

Top
#200623 - 2010-11-15 10:58 PM Re: problem reading af file for use in script [Re: roundup]
Shanee Offline
Fresh Scripter

Registered: 2006-10-13
Posts: 39
Loc: Tulsa, OK
Sample .ini format
 Code:
[00:25:9C:AD:43:D6]
Location = Preparation
Groups = Teacher,Student,Admin

[00:25:9C:AD:43:D6:Teacher]
Shares = HP LaserJet 1320nw - Support:LaserJet1,Xerox WorkCentre 7345:Xerox1

[00:25:9C:AD:43:D6:Student]
Shares = HP LaserJet 1320nw - Support:LaserJet1

[00:25:9C:AD:43:D6:Admin]
Shares = HP LaserJet 1320nw - Support:LaserJet1,Xerox WorkCentre 7345:Xerox1,Other Admin Printer:Admin1

Kix script
 Code:
$mac = GetBSSID(1,@WkSta)
$location = ReadProfileString ($LogonServer+"\NETLOGON\printer.ini", $mac, "Location")
$groups = ReadProfileString ($LogonServer+"\NETLOGON\printer.ini", $mac, "Groups")
$groups = Split($groups,",")

$Tag = 1
For Each $group in $groups
   If InGroup($group) and $Tag
      $Tag = 0
      $shares = ReadProfileString ($LogonServer+"\NETLOGON\printer.ini", $mac+":"+$group, "Shares")
      $shares = Split($shares,",")
      $sharenum = 0
      For Each $shareobj in $shares
         $name = Split($shareobj,":")[0]
         $share = Split($shareobj,":")[1]
         If AddPrinterConnection("\\server\"+$share) = 0
            If $sharenum = UBound($shares)
               $null = SetDefaultPrinter("\\server\"+$name)
            EndIf
         Else
            $null = MessageBox("2 Der er et problem med at etablerer forbindelse til : "+$share,"Printer fejl",0)
         EndIf
         $sharenum = $sharenum+1
      Next
   EndIf
Next

FUNCTION GetBSSID(optional $device, optional $machine)
   $strComputer = IIF (VarType($machine)<2, @Wksta, $Machine)
   $objSWbemServices = GetObject("winmgmts:\\"+ $strComputer + "\root\wmi")
   $colInstances = $objSwbemServices.ExecQuery("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE Active=True")
   if $device<1
      $card_no=1
      $cards = "Please specify one of these devices to obtain it's BSSID :"
      for each $objInstance in $colInstances
         $cards = $cards+@CRLF+"Card "+$card_no+" = "+$objInstance.InstanceName
         $card_no=$card_no +1
      next
      $GetBSSID = $cards
      Return
   endIf
   $card_no=$device
   $x=1
   for each $objInstance in $colInstances
      if $x = $card_no
         $wifiAdapter = $objInstance.InstanceName
         $x = $x + 1
      endif
   next
   $last_signal = 0
   $bssid = ""
   $colInstances = $objSwbemServices.ExecQuery('SELECT * FROM MSNdis_80211_BaseServiceSetIdentifier WHERE Active = True AND InstanceName ="'+$wifiAdapter+'"')
   for each $objInstance in $colInstances
      $macbyte = 0
      for each $decval in $objInstance.Ndis80211MacAddress
         if $decval<17
            $bssid = $bssid + "0"
         endif
         $bssid = $bssid + DecToHex($decval)
         if $macbyte < 5
            $bssid = $bssid + ":"
            $macbyte = $macbyte + 1
         endif
      next
   next
   $colInstances = $objSwbemServices.ExecQuery ("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE Active = True AND InstanceName ='" + $wifiAdapter + "'")
   for each $objInstance in $colInstances
      $sigraw = $objInstance.Ndis80211ReceivedSignalStrength
      $signal = $sigraw + "dB"
   next
   $last_signal = $sigraw
   $GetBSSID = $bssid
ENDFUNCTION

Top
#200633 - 2010-11-17 12:39 AM Re: problem reading af file for use in script [Re: Shanee]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol, talk about platinum blatter.
_________________________
!

download KiXnet

Top
#200640 - 2010-11-17 08:24 PM Re: problem reading af file for use in script [Re: Lonkero]
Shanee Offline
Fresh Scripter

Registered: 2006-10-13
Posts: 39
Loc: Tulsa, OK
HaHa, Yeah I know. But I'm usually bored at work anyways. Just now started messing about with Kix again.
Top
#200641 - 2010-11-17 08:57 PM Re: problem reading af file for use in script [Re: Shanee]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: Shanee
HaHa, Yeah I know. But I'm usually bored at work anyways.
...


\:o

Do you want some of my workload?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#200666 - 2010-11-20 08:01 PM Re: problem reading af file for use in script [Re: Mart]
Shanee Offline
Fresh Scripter

Registered: 2006-10-13
Posts: 39
Loc: Tulsa, OK
Haha, well I used to be in the IT field so I know the kind of workload you're referring to. But now I work in an optical lab making lenses for glasses. Just a random job as I work towards my electrical engineering degree. Sometimes it's busy and sometimes not so much.

btw...this was me back in the day..
http://www.kixtart.org/forums/ubbthreads.php?ubb=showprofile&User=2761

Top
#200667 - 2010-11-20 08:43 PM Re: problem reading af file for use in script [Re: Shanee]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Citrixman... I remember you. Nearly a 6 year hiatus... welcome back.

How come you aren't using your original account?

Top
#200668 - 2010-11-20 08:53 PM Re: problem reading af file for use in script [Re: Allen]
Shanee Offline
Fresh Scripter

Registered: 2006-10-13
Posts: 39
Loc: Tulsa, OK
Didn't have the same email account anymore, and to be honest I couldn't even remember what it was until I re-registered and went thru the user list for possible id's lol. Maybe I'll try to get it working again now that I know what it is.
Top
#200669 - 2010-11-20 08:59 PM Re: problem reading af file for use in script [Re: Shanee]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I'm sure Rich or Jooel can help you out with that.

My account name back then was likely Alpo. There was a post just a few months back talking about how long people had been trolling around here... and when I say "6 years" since you were here... it's just mind boggling that I have been here that long (and longer).

Top
#200670 - 2010-11-20 09:05 PM Re: problem reading af file for use in script [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Haha well I had to re-create the hotmail account I used to have, but it atleast let me email the pw to myself again. It is weird indeed, just to think it's been that long since I was active on here. Just goes to show the power of the Kix, that it is still so useful today.
Top
#200671 - 2010-11-20 09:20 PM Re: problem reading af file for use in script [Re: ShaneEP]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Welcome back CitrixMan!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#200675 - 2010-11-21 11:36 PM Re: problem reading af file for use in script [Re: Les]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Thanks!
Top
#200745 - 2010-11-24 12:43 PM Re: problem reading af file for use in script [Re: ShaneEP]
roundup Offline
Fresh Scripter

Registered: 2010-10-29
Posts: 11
Loc: Denmark
Hi Shane

Thanks, again I thank you for your good feedback and excellent support.

Bedst regards
roundup

Top
#200759 - 2010-11-24 10:21 PM Re: problem reading af file for use in script [Re: ShaneEP]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hey guy, welcome back CitrixMan - glad to see you back.

Not the busy fast posting it once was but still cool to be around.

Cheers

Top
Page 2 of 2 <12


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.07 seconds in which 0.027 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org