roundup
(Fresh Scripter)
2010-11-05 01:07 PM
problem reading af file for use in script

Hi, are there someone who can please help me,
i facial turning blue an green.


I have a Printer.ini file for my printermappings that will
map printers if $bssid = $mac

I also have a function that locate the bssid of the accesspoint
the client is connected to, and use this to compare the location
of my printers so the client will get the printer mapped close to
him.

Printer.inf
00:1B:3F:8E:CD:21;Location1;Share1;Group1
00:16:B9:52:AF:BF;Location2;Share3;Group3
00:17:08:22:0B:C3;Location3;Share2;Group6
00:1B:3F:8E:CD:21;Location4;Share4;Group4
00:1C:2E:42:94:57;Location5;Share5;Group2


In this example i have 2 identical match (mac) and want to pass
the line argument to som variables for further use (printermapping) in my script.
It only works as long the @error = 0 when not it reads the same line again and again?


00:1B:3F:8E:CD:21;Location1;Share1;Group1
00:1B:3F:8E:CD:21;Location4;Share4;Group4

My problem is that the script will not loop through the end of my Printer.inf
to isolate the match found, here $bssid = $mac


Here is my script:
 Code:
$PrinterMapping = @LDRIVE + "\Printer.ini"
$ = Open(1, $PrinterMapping)
$aCurLine = Split(ReadLine(1),';')

$LoopCount = 0
 While @error = 0

$mac        = Trim($aCurLine[0])
$location   = Trim($aCurLine[1])
$share      = Trim($aCurLine[2])
$group      = Trim($aCurLine[3])

  If "$bssid" = "$mac"

? "BSSID: " $mac
? "Printer Placering: " $location
? "Printer Deling: " $share
? "Printer Gruppe: " $group
? @Error

$aCurLine = Split(ReadLine(1),';')

Else
 ? "Match not found"
 ? $bssid
 ? $mac
 ? $LoopCount
ENDIF

$LoopCount = $LoopCount + 1
sleep 3

  Loop


Kind regards
roundup


Mart
(KiX Supporter)
2010-11-05 02:07 PM
Re: problem reading af file for use in script

You need to place the last readline function at the end of the loop just above the actual Loop line.
You talk about and ini file and an inf file. What are you using ini or inf? The example you posted is not valid ini format.

Valid ini format is something like this:
 Quote:

[section1]
Value1=1
Value2=2
[section2]
Value1=2
Value2=89


Les
(KiX Master)
2010-11-05 02:24 PM
Re: problem reading af file for use in script

He is using ReadLine() so INI or INF or TXT matters not, nor does it matter that it doesn't follow INI format.

That said, I'm not sure why he would use ReadLine() and not use the features of a true INI format.

If "$bssid" = "$mac"
Why wrap vars in quotes?


Shanee
(Fresh Scripter)
2010-11-05 04:27 PM
Re: problem reading af file for use in script

Using the bssid function i posted the other day...and a standard ini file...this is quite simple.

 Code:
$mac = GetBSSID(1,@WkSta)
$location = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Location")
$share = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Share")
$group = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Group")

$null = MessageBox($mac+@CRLF+$location+@CRLF+$share+@CRLF+$group,"BSSID",0)

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


and i just created a sample info.INI file that looks like this...

 Code:
[00:1B:3F:8E:CD:21]
Location=Location1
Share=Share1
Group=Group1

[00:16:B9:52:AF:BF]
Location=Location2
Share=Share3
Group=Group3

[00:17:08:22:0B:C3]
Location=Location3
Share=Share2
Group=Group6

[00:1B:3F:8E:CD:21]
Location=Location4
Share=Share4
Group=Group4

[00:1C:2E:42:94:57]
Location=Location5
Share=Share5
Group=Group2

[00:25:9C:AD:43:D6]
Location=Location99
Share=Share98
Group=Group97


roundup
(Fresh Scripter)
2010-11-05 11:40 PM
Re: problem reading af file for use in script

Hi Shanee

Thanks again for your great help, as you probably already figured out
I am only a beginner.
I really appreciate your help and are very grateful if you can help me on track.


My question is now.

How do I transfer the variables from Printer.ini file for further use in kix?

In the script you've made for me that finds the BSSID the clients are connected to, must now run through Printer.ini file to find the printers to be mapped in the area of BSSID, the way is to locate the same BSSID in the Printer.ini file and determin which printers to be mapped on the client.

The following parameters are used:

BSSID to determine whether the client is near the printer to be allocated.

Group for investigate whether the user is a member or not and if true then map the printer, otherwise not, and it can be that a student do
not have access to a printer which has the same BSSID for the area!

The printer share for mappings (AddPrinterConnection)

The printer name to displayed to the user during mapping.

If there is only one printer then it must be set as default,
if there are more in the same area the the last one must be set as default or perhaps determine this in the Printer.ini file!?


ex Printer.ini

[00:1B:3F:8E:CD:21]
Location = Preparation
Name = HP LaserJet 5550
Share = Laserjet1
Group = Students
Default = HP LaserJet 5550

[00:1B:3F:8E:CD:21]
Location = Preparation
Name = HP LaserJet M4730
Share = Laserjet1
Group = Teacher
Default = HP LaserJet M4730

[00:16:B9:52:AF:BF]
Location = Cellular
Name = HP LaserJet 1320
Share = Laserjet7
Group = Teacher
Default = HP LaserJet 5550

[00:16:B9:52:AF:BF]
Location = Cellular
Share = Laserjet8
Group = Group6

etc. ..


I hope there are someone who can help me, from the modest kix beginner.


Kind regards
roundup


Les
(KiX Master)
2010-11-06 01:43 AM
Re: problem reading af file for use in script

Each [SECTION] name has to be unique.

roundup
(Fresh Scripter)
2010-11-06 01:57 PM
Re: problem reading af file for use in script

Hi

How do I resolve my problem if there are more printers
to be assigned to the same location as the access point (BSSID) when you write that each [SECTION] in a. ini must be unique?

Can I, as described above in the article use a Printer.txt file
instead containing the variables to be used for mapping my printers.

And here use Printer.txt to search from start to finish and find out what
printers to assign clients if the BSSID in the Printer.txt file is
identical to the access point (BSSID).

I have tried to start a script, first in the article, but it do not works
it stops if the $bssid is not equal to $mac, and then hangs
in the same line without continuing to the end of the file?

Surely it is possible to isolate these variables for use in KIX script
or what?

Printer.txt
BSSID;location;printer share;group membership;printer model info
00:1B:3F:8E:CD:21;Location1;Laserjet1;Teacher;HP LaserJet 5550
00:1B:3F:8E:CD:21;Location1;Laserjet2;Students;HP LaserJet 4500
00:17:08:22:0B:C3;Location2;Laserjet3;All;HP LaserJet 1320

etc....

What should I do to get it to work, when I can not use a a true INI format.

NB:
If only one printer is mapped, should this be set to default, if there is more than on printer, the last should be set as default.



Sincerely,
roundup


Shanee
(Fresh Scripter)
2010-11-06 04:23 PM
Re: problem reading af file for use in script

I see you problem. May I ask why you need a Share AND a Name since you only use the Share to use the AddPrinterConnection(). Also do all of these printers reside on the same server?

Shanee
(Fresh Scripter)
2010-11-06 04:54 PM
Re: problem reading af file for use in script

You could just put multiple shares under one section of the ini. like so...

 Code:
[00:25:9C:AD:43:D6]
Location = Location99
Group = Group97
Shares = Share98,Share99,Share100,Share101,Share102
Names = Printer 98,Printer 99,Printer 100,Printer 101,Printer 102


Then modify the script to split them into multiple items if a "," exists.

 Code:
$mac = GetBSSID(1,@WkSta)
$location = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Location")
$group = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Group")
$names = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Names")
$shares = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Shares")

If InStr($shares,",")
   $names = Split($names,",")
   $shares = Split($shares,",")
   If UBound($names) <> UBound($shares)
      $null = MessageBox("There seems to be an uneven Name to Share ratio for this user. Please verify printer.ini file for : "+$mac,"Name/Share Mismatch",0)
   Else
      $sharenum = 0
      For Each $share in $shares
         $name = $names[$sharenum]
         If InGroup($group)
            If AddPrinterConnection("\\server\"+$share) = 0
               If $sharenum = UBound($shares)
                  SetDefaultPrinter("\\server\"+$share)
               EndIf
            Else
               $null = MessageBox("There seems to have been a problem connecting to : "+$share,"Printer Error",0)
            EndIf
         EndIf
         $sharenum = $sharenum+1
      Next
   EndIf
Else
   If InGroup($group)
      If AddPrinterConnection("\\server\"+$shares) = 0
         SetDefaultPrinter("\\server\"+$shares)
      Else
         $null = MessageBox("There seems to have been a problem connecting to : "+$shares,"Printer Error",0)
      EndIf
   EndIf
EndIf


Still not sure what you would use the NAME variable for. Maybe this is supposed to be the server name?


AllenAdministrator
(KiX Supporter)
2010-11-06 04:59 PM
Re: problem reading af file for use in script

Possibly because SetDefaultPrinter has to have it...

There is a way around that though...

SetAsDefaultPrinter() -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=187517


How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1


Les
(KiX Master)
2010-11-06 05:26 PM
Re: problem reading af file for use in script

 Originally Posted By: Allen
Possibly because SetDefaultPrinter has to have it...
Ja, that could be one reason. Of course one could always make the name and the share the same. One could also assign both to the same key with a delimiter and then split it out.

i.e.
Printers = share1~name 1,share2~name 2,share3~name 3


Shanee
(Fresh Scripter)
2010-11-06 05:40 PM
Re: problem reading af file for use in script

Ahh both very good points...

So sample .ini file...
 Code:
[00:25:9C:AD:43:D6]
Location = Location99
Group = Group97
Shares = Share 98:Share98,Share 99:Share99,Share 100:Share100,Share 101:Share101,Share 102:Share102


Sample code to use .ini file...(changed setdefault to use name, changed share and name to one variable with a delimiter, also brought out the ingroup check since they all seem to depend on it.)
 Code:
$mac = GetBSSID(1,@WkSta)
$location = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Location")
$group = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Group")
$shares = ReadProfileString (@ScriptDir+"\info.ini", $mac, "Shares")

If InGroup($group)
   If InStr($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("There seems to have been a problem connecting to : "+$share,"Printer Error",0)
         EndIf
         $sharenum = $sharenum+1
      Next
   Else
      $name = Split($shares,":")[0]
      $share = Split($shares,":")[1]
      If AddPrinterConnection("\\server\"+$share) = 0
         $null = SetDefaultPrinter("\\server\"+$name)
      Else
         $null = MessageBox("There seems to have been a problem connecting to : "+$shares,"Printer Error",0)
      EndIf
   EndIf
EndIf


AllenAdministrator
(KiX Supporter)
2010-11-06 05:49 PM
Re: problem reading af file for use in script

Should be something like this, although I don't see where $server is ever defined.

Shanee's code (don't forget the = after $null )
 Code:
$null=SetDefaultPrinter("\\" + $server + "\" + $name)


or with SetAsDefaultPrinter(requires UDF)
 Code:
$null=SetAsDefaultPrinter("\\" + $server + "\" + $share)



Shanee
(Fresh Scripter)
2010-11-06 06:00 PM
Re: problem reading af file for use in script

Good catch, edited/corrected above posted code.

roundup
(Fresh Scripter)
2010-11-06 11:36 PM
Re: problem reading af file for use in script

1000 thanks for all your inputs.

I will test this as the first thing Monday morning, and of course comment if it works.

I am very grateful for all the great effort from all of you, and the many valuable solutions you all have contributed.

And a special thanks goes to a great coder Shanee for all the support and
coding, and last but not least the answer to my problem, and I know that our school will benefit from it.


Sincerely,
roundup


Shanee
(Fresh Scripter)
2010-11-06 11:43 PM
Re: problem reading af file for use in script

No problem. Hope it works. I haven't messed with kix much in a number of years, so it's nice to work on these kinds of problems to re-familiarize myself as well haha.

-Shane


roundup
(Fresh Scripter)
2010-11-08 02:00 PM
Re: problem reading af file for use in script

Hi Shanee


The script works perfectly, but now there is only one problem:

I have 2 printers in the same location, and the teachers group
are member of the students group, and should therefor have both
printers installed, no problem here, but the students should not
have the printer Xerox1 installed so they dont get confused when
printing to a printer they dont have print rights to, how do i
resolve this.

I was wondering if it was possible to integrate in your script, to define and check for group membership like the section for Names and Shares, like this:

Group = students,teachers


printer.ini
[00:16:B9:52:AF:BF]
Location = Preparation
Group = students
Names = HP LaserJet 1320nw - Support,Xerox WorkCentre 7345
Shares = LaserJet1,Xerox1


Kind regards
roundup



Working script:
 Code:
$location = ReadProfileString ($LogonServer + "\NETLOGON\printer.ini", $mac, "Location")
$group = ReadProfileString ($LogonServer + "\NETLOGON\printer.ini", $mac, "Group")
$names = ReadProfileString ($LogonServer + "\NETLOGON\printer.ini", $mac, "Names")
$shares = ReadProfileString ($LogonServer + "\NETLOGON\printer.ini", $mac, "Shares")

If InStr($shares,",")
   $names = Split($names,",")
   $shares = Split($shares,",")
   If UBound($names) <> UBound($shares)
      $null = MessageBox("Der er uoverensstemmelse mellem Names og Shares. Kontroller printer.ini filen under sektionen : "+$mac,0)
   Else
      $sharenum = 0
      For Each $share in $shares
         $name = $names[$sharenum]
         If InGroup($group)
            If AddPrinterConnection("\\" + $printserver + "\" + $share) = 0
               If $sharenum = UBound($shares)
                  $null = SetDefaultPrinter("\\" + $printserver + "\" + $name)

               EndIf
            Else
               $null = MessageBox("2 Der er et problem med at etablerer forbindelse til : "+$share,"Printer fejl",0)
            EndIf
         EndIf
         $sharenum = $sharenum+1
      Next
   EndIf
Else
   If InGroup($group)
      If AddPrinterConnection("\\" + $printserver + "\" + $shares) = 0
         $null = SetDefaultPrinter("\\" + $printserver + "\" + $names)         
      Else
         $null = MessageBox("2 Der er et problem med at etablerer forbindelse til : "+$shares,"Printer fejl",0)

      EndIf
   EndIf
EndIf


Shanee
(Fresh Scripter)
2010-11-08 06:37 PM
Re: problem reading af file for use in script

Ok, the easiest way that I can think of (maybe someone else has a more efficient way), would be to create different INI sections for the different groups. So if in teacher group, get all printers in that area, but if in student group then only get one printer in that area. I changed the INI to be like this...Where the same MAC area has different sections depending on the group the person is in. The modified code below will now check the approptiate section depending on which group that are in.

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

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


Modified code...
 Code:
$mac = GetBSSID(1,@WkSta)
If InGroup("Teacher")
   $mac = $mac+":teacher"
Else
   If InGroup("Student")
      $mac = $mac+":student"
   Else
      $null = MessageBox("User is not in any of the printer groups.","Printer fejl",0)
      Quit
   EndIf
EndIf
$location = ReadProfileString ($LogonServer+"\NETLOGON\printer.ini", $mac, "Location")
$shares = ReadProfileString ($LogonServer+"\NETLOGON\printer.ini", $mac, "Shares")
If InStr($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
Else
   $name = Split($shares,":")[0]
   $share = Split($shares,":")[1]
   If AddPrinterConnection("\\server\"+$share) = 0
      $null = SetDefaultPrinter("\\server\"+$name)
   Else
      $null = MessageBox("2 Der er et problem med at etablerer forbindelse til : "+$share,"Printer fejl",0)
   EndIf
EndIf

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


Glenn BarnasAdministrator
(KiX Supporter)
2010-11-08 08:35 PM
Re: problem reading af file for use in script

It's about time you guys headed in this direction.. \:D

Glenn


roundup
(Fresh Scripter)
2010-11-09 02:38 PM
Re: problem reading af file for use in script

Hi Shanee

1000 thanks for all your hard work.

I have not yet had time to test your change with respect to
group affiliation, but am sure it will work, therefore I close
the thread here.


"I will return again when I have problems." ;\)

Sincerely,
roundup


Glenn BarnasAdministrator
(KiX Supporter)
2010-11-09 03:02 PM
Re: problem reading af file for use in script

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


Shanee
(Fresh Scripter)
2010-11-09 10:41 PM
Re: problem reading af file for use in script

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


Glenn BarnasAdministrator
(KiX Supporter)
2010-11-10 01:05 AM
Re: problem reading af file for use in script

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


roundup
(Fresh Scripter)
2010-11-15 09:23 PM
Re: problem reading af file for use in script

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


Shanee
(Fresh Scripter)
2010-11-15 10:58 PM
Re: problem reading af file for use in script

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


LonkeroAdministrator
(KiX Master Guru)
2010-11-17 12:39 AM
Re: problem reading af file for use in script

lol, talk about platinum blatter.

Shanee
(Fresh Scripter)
2010-11-17 08:24 PM
Re: problem reading af file for use in script

HaHa, Yeah I know. But I'm usually bored at work anyways. Just now started messing about with Kix again.

Mart
(KiX Supporter)
2010-11-17 08:57 PM
Re: problem reading af file for use in script

 Originally Posted By: Shanee
HaHa, Yeah I know. But I'm usually bored at work anyways.
...


\:o

Do you want some of my workload?


Shanee
(Fresh Scripter)
2010-11-20 08:01 PM
Re: problem reading af file for use in script

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


AllenAdministrator
(KiX Supporter)
2010-11-20 08:43 PM
Re: problem reading af file for use in script

Citrixman... I remember you. Nearly a 6 year hiatus... welcome back.

How come you aren't using your original account?


Shanee
(Fresh Scripter)
2010-11-20 08:53 PM
Re: problem reading af file for use in script

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.

AllenAdministrator
(KiX Supporter)
2010-11-20 08:59 PM
Re: problem reading af file for use in script

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).


ShaneEP
(MM club member)
2010-11-20 09:05 PM
Re: problem reading af file for use in script

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.

Les
(KiX Master)
2010-11-20 09:20 PM
Re: problem reading af file for use in script

Welcome back CitrixMan!

ShaneEP
(MM club member)
2010-11-21 11:36 PM
Re: problem reading af file for use in script

Thanks!

roundup
(Fresh Scripter)
2010-11-24 12:43 PM
Re: problem reading af file for use in script

Hi Shane

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

Bedst regards
roundup


NTDOCAdministrator
(KiX Master)
2010-11-24 10:21 PM
Re: problem reading af file for use in script

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