Jump to content

Recommended Posts

Posted
MONAD does look good. I have been using the beta for some time and it's quite easy to pick up and seems a lot more functional than anything else MS have offered in the past.
Posted

I'd like to rewrite the logon script sop that printer allocation is based on the OU the computers sit in - I guess thats possible - can anyone point to a site that has a few examples of similar - my Google came back with a zillion hits.

 

Cheers

Posted
Personally I'm looking forward to rewriting all my scripts in the new MS shell (MONAD) which is slated to replace WSH. There's a beta out now.

 

I'm considering using Python for my scripting needs.

Posted

I assign printers based on computer OU membership. Basically, it's all done using the ADSI extensions.

 

You can get the full computer path from ADSystemInfo.ComputerName and then check for the presence of particular OUs.

 

dim oAdSysInfo, sCompPath
set oAdSysInfo = CreateObject("AdSystemInfo")
sCompPath = oAdSysInfo.ComputerName
if InStr(1, sCompPath, "OU=ICT Suite", 1) then 
 ' Code here to map printer(s) for ICT Suite
end if

Posted

I've heard lots of good things about python , never tried it myself. Maybe one of you could point me in the direction of where to get it from, how to configure it, tutorials etc etc , that would be nice as I would like to give it a go.

 

As for scripting, try admin script editor here :

 

http://www.adminscripteditor.com/main.asp

 

Just on my lunch break so not much time to look around for printer scripts etc. I posted on here with my printer script on the same thread as RIC's printer script so would be worth while checking that out as I did a select case with some other things:)

Posted

As I think I mentioned earlier, my logon script is a bit stupidly big, but the essence of what you need to do is here. I've added some comments

 

' Declare object variables
dim oAdSysInfo, sCompPath

' Create the AdSystemInfo object
set oAdSysInfo = CreateObject("AdSystemInfo")

' Create the Wscript.Network object
set oWshNet = CreateObject("Wscript.Network")

' Obtain the full path to the computer account
sCompPath = oAdSysInfo.ComputerName

' Check to see if the computer is in (or below) a particular OU
if InStr(1, sCompPath, "OU=ICT Suite", 1) then
 ' Add a printer connection based on computer OU membership
 oWshNet.AddWindowsPrinterConnection "\\ServerName\PrinterShareName"
end if

 

Hope this helps

Posted

I havent really used InStr that much , InStrRev I used once. This is a long shot but if you dont ask you dont get ( And in some cases at least with me I dont get even when I ask lol ) but any chance you could incorporate that into this script so that It works with my script.

 

Preferably put the Check to see if the computer is in an OU into a function so that I can call it when needed.

 

Please find my script attached as a txt file :)

Posted

Gecko.. Please don't take this the wrong way, but from looking at your script (and the fact that you've asked me to help you with it) I'm guessing that you're still learning VB Script. I think the best way of learning is by doing, so rather than rewrite your script, I'll try to help you along the way as follows...

 

The InStr function is just like the InStrRev function, except that it starts looking for the for the substring from the beginning of the source string, rather than from the end, so...

TwoPos = InStr("12345678987654321", "2")

...returns the value 2

 

Whereas...

TwoPos = InStrRev("12345678987654321", "2")

...returns the value 14

 

Here's the function to determine if a computer is in an OU. You can just add the function to the end of your existing script.

Function IsComputerInOu(sOU)
 dim oAdSysInfo, sComputerDN
 set oAdSysInfo = CreateObject("AdSystemInfo")
 sComputerDN = oAdSysInfo.ComputerName
 IsComputerInOu = (InStr(1, sComputerDN, "OU=" & sOU, vbTextCompare) > 0)
End Function

 

Usage: IsComputerInOU()

Returns: True if computer account is in or below an OU with the name 'OU Name'

Example:

If IsComputerInOu("IT1") Then
 oWshNet.AddPrinterConnection("\\cse2k01\KyoceraM")
end if

 

The function works because of what is returned by the AdSystemInfo.ComputerName method. This returns not just the Computer Name, but the Distinguished Name (DN) (see RFC 1779) of the computer account object. If you imagine that your computer is call IT1-01, that it is in an OU called IT1, which in turn is in an OU called Computers, which is in the domain School.Local, then the Distinguished Name (DN) of the computer account object would be

cn=IT1-01,ou=IT1,ou=Computers,dc=School,dc=Local

 

It's then a simple matter to use InStr to see if, for instance the string 'ou=IT1' exists in the full DN string. If it does, then computer account is in (or below) the IT1 OU.

Posted

I understand that ( glad you chose to do it this way actually because you are totally right about learning more when you do it ) so defintly no hard feelings there and appreicate the help as well ;)

 

With regards to this :

 

Whereas...

Code:

TwoPos = InStrRev("12345678987654321", "2")

 

would return 14

 

Surely it would return 2 and not 14 since it is going from the end to the begining and if you look at the string of numerical values you will see that the number 2 is the 2nd one in from the end even though there is another 2 at the beginging.

 

Might be wrong on that point but just wanted to confirm :)

Posted
What can python be used for and does it have a steep learning curve ?

 

Off the top of my head:

 

- Shell scripting on various flavors of *nix.

- Scripting language for various applications (XChat, the IRC client I use for example).

- Scripting language for some games. Large chunks of Eve Online and Unreal Tournament are written in Python.

- Alternative to PHP/Perl/ASP/etc for running your website.

- Entire applications can be written in python. The Eric Python IDE I linked to above is written in Python (somewhat paradoxical!)

 

Now as far as scripting under windows goes. It can do anything VB scripts can. AD intergration, WMI queries, you name it.

Posted

well I will be darned.

 

I tested it out and for this vbscript :

 

TwoPos = InStrRev("12345678987654321", "2")

MsgBox TwoPos

 

It returns 16

 

how come it ignores the first 2 at the end if its supposed to search it from the end to the start ?

 

Me.Confused = Very True lol.

 

So the 2nd parameter in InStrRev, does that make it search for the value number 2 or what does that do because in my InStrRev in my printer script it is something along the lines of :

 

InStrRev(strComputer,-1,1)

 

or something to that extent ( Not exactly sure what difference the numerica values make but they must make a big difference.

 

Would be nice to know exactly what differences the different numbers make exactly !!

Posted

IT doesnt ignore the second "2":

 

InStrRev doesnt "count" from the end it just returns the position of the matching character but performs its search in reverse order. Each characters position is determined from left to right starting from one, therefore, when doing a InStrRev in your example, it finds the first instance of the character "2", which is in the 16th position in the string, therefore returns 16

Posted

Thats not what i said at all,

 

InStrRev searches from right to left, but it returns the position of the result it finds based on the standard positioning number system, for example:

 

intPosition = InStrRev("this is a string", "i")

 

would return 14, as the first "i" encountered when checking from right to left is the 14th character (in the word "string" and including the spaces in the count) when counting from left to right.

 

Hope this makes sense

Posted

That example makes sense that you posted elusive but with regards to this example :

 


TwoPos = InStrRev("123456789876543[b]2[/b]1", "2")    '<----
MsgBox TwoPos

 

The first number 2 going from right to left that I have made bold ( hopefully it is bold lol )

 

Is the 2nd character starting from the end on the right side. Unless in that example it does the counting from the begining.

 

So in essence you are saying it finds it from right to left but does the counting from left to right and NOT right to left. Hopefully Im on the right wave length now lol.

Posted
nps mate glad i could help, i will let you in on my secret tho, i do code in other languages including C#.NET, mIRC scripting language, have done some MS basic as a kid and do write the odd batch file.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...