Jump to content

Recommended Posts

Posted

Hi there

 

i'm looking at learning a few new things and wanted to know how to create scripts. Things like startup/logon scripts for various things.

 

Is there anywhere at all that tells you how to start scripting or any book thats a good beginners guide?

 

My current boss just says he cobbles them together from other peoples scripts off the internet but i'd like to understand how to write them an what things mean.

 

Thanks

Posted (edited)
Hi there

 

i'm looking at learning a few new things and wanted to know how to create scripts. Things like startup/logon scripts for various things.

 

Is there anywhere at all that tells you how to start scripting or any book thats a good beginners guide?

 

My current boss just says he cobbles them together from other peoples scripts off the internet but i'd like to understand how to write them an what things mean.

 

Thanks

 

I am all self taught [ which means I have really bad habits ] - but I would start at the very basic level of batch stuff, then work your way to say VBS, WSH, Powershell, Kix - there are loads of others and you will find your favorite. My favorite is AutoIT and I tend to do most things in that although I must get down and start doing some powerhshell at some point - but at the moment I can't be arsed....

 

http://www.robvanderwoude.com/

http://www.robvanderwoude.com/books.php

 

Is a good starting point.

 

Books which I use and have learnt a great deal from:

 

Windows Administration at the command line

Windows Powershell programming

Windows Admin Scripting Little Black Book, Second Edition

 

Happy scripting.

Edited by mattx
Posted
is this not what edugeek is for? have a play if you think it should work and it doesnt then ask one of the very kind people on here. I have taught myself alot of it from other edugeekers helping me when i am trying to put them together. i have just started moving onto PHP which is even more complicated!
Posted

For VBS I use this: VbsEdit - Award-winning VBScript Editor - VBS editor - VBScript debugger - VBS debugger or this: .:: NOTEPAD++ ::. which also supports many other scripting languages.

VbsEdit comes with a script repository which is appears to be mostly taken from Microsoft's Script Center

 

You might find this VBScript Tutorial useful though it's more geared towards the web.

 

Microsoft have their own guide and reference: VBScript

 

Three tips for scripting/programming:

1. Keep your code clean and easily readable - I use indents a lot so I can easily see the blocks/loops/conditionals etc...

2. Use comments. Give each function/subroutine a quick description of what it does and comment complex statements. Don't be afraid to go overboard. You can always trim or remove them once your happy with your script.

3. Debugging - with complex VBS I usually use message boxes to display what's being held in variables so I can check the program is doing what it's supposed to. I comment them with "debug" so I can easily find and remove them afterwards.

Posted (edited)
For VBS I use this: VbsEdit - Award-winning VBScript Editor - VBS editor - VBScript debugger - VBS debugger or this: .:: NOTEPAD++ ::. which also supports many other scripting languages.

VbsEdit comes with a script repository which is appears to be mostly taken from Microsoft's Script Center

 

You might find this VBScript Tutorial useful though it's more geared towards the web.

 

Microsoft have their own guide and reference: VBScript

 

Three tips for scripting/programming:

1. Keep your code clean and easily readable - I use indents a lot so I can easily see the blocks/loops/conditionals etc...

2. Use comments. Give each function/subroutine a quick description of what it does and comment complex statements. Don't be afraid to go overboard. You can always trim or remove them once your happy with your script.

3. Debugging - with complex VBS I usually use message boxes to display what's being held in variables so I can check the program is doing what it's supposed to. I comment them with "debug" so I can easily find and remove them afterwards.

 

ref debugging when dealing with the file system object ( FSO ) I used a text file to output what files / folders it found and also output which ones it should of deleted as text data so it didnt actually delete the files so I could get the script to work as I wanted (more or less ) before trying it

Edited by mac_shinobi
Posted (edited)
At the risk of starting a religious war, the best starting point is the Microsoft scripting site - Script Center

 

They ought to know how to use their scripting technologies :-)

 

lol @ part highlighted in bold

 

I put the computer performance one because I use that a lot and it has examples which are more or less walked through numerically etc and it has a lot of examples with ref to wmi, fso, etc

Edited by mac_shinobi
Posted
At the risk of starting a religious war,

 

The best thing would be to start with a platform independent language such as Python, because what you learn there will apply to Windows, OSX, Unix, Linux which greatly broadens your horizons.

 

 

My current boss just says he cobbles them together from other peoples scripts off the internet

 

That's what Open Source code is all about - someone writes some code, and we are all free to use it and adapt it.

Posted
The best thing would be to start with a platform independent language such as Python, because what you learn there will apply to Windows, OSX, Unix, Linux which greatly broadens your horizons.

 

 

 

 

That's what Open Source code is all about - someone writes some code, and we are all free to use it and adapt it.

 

No, start with Batch, because it's easy. :D

Posted
No, start with Batch, because it's easy. :D

 

Quite right - [ I stated this in my first posting on this ] - it will give you a good understanding to start with, just DON'T use GOTO - learn how to use loops etc otherwise you will end up with spaghetti code - and trust me you don't want to go there....

Posted
Things like startup/logon scripts for various things. My current boss just says he cobbles them together from other peoples scripts off the internet but i'd like to understand how to write them an what things mean.

 

That sounds like a perfectly good way to start - pick some real task you need to actually do ("learning" tasks really don't work outside a formal classroom environment for programming) and do it, even if you cobble together lines pasted from the Internet someplace. Then figure out how your script works, line by line - follow your program through as if you're the computer executing the code.

 

--

David Hicks

Posted
brilliant, thanks everyone for the advice some good information there and some great links to work through. Now all I need is some time.....lol
Posted

Do you have any programming knowledge at all?

 

Without meaning to sound annoying... could be worth while learning the basis of things like variables, constants, functions, loops, conditional statements & data types first... it may make it easier to understand what is going on rather than diving in - the best site i found at uni was learning pseudocode... i found it easier to then 'visualise' the code if that makes any sense.

Posted

i did a years worth of vb whilst at college so i have an idea about variables constants, loops etc but its well worth me having a look over them again and having a look at that site.

Cheers for that!

Posted

not to side track as I have used constants but what is the point of them ie

 

const strShareOne = "HP_Colour"

MapPath "\\server\" & strShareOne

As apposed to

 

MapPath "\\server\HP_Colour"

Obviously am making the commands up but just to give you an idea

 

Unless someone can post back a good example of when and why you would use constants whether in vbscript, vb .net or whatever

Posted

There's 2 reasons really - the first is about the fact that it's something that you might want to use loads of times and you don't want to have to change the value throughout the script. The second is the fact that you're saying that the value can't be changed - this avoids making errors where you accidentally change something.

 

Take an example, you're writing a script which is going to connect printers on a server. Let's suppose the server is called server1. You could list all your printers as "\\server1\printer1" "\\server1\printer2" etc but then when you get a new server you have to change all those references. If you have const sServer="\\server1\" at the beginning and then lines like mapprinter sSever & "printer1" then all you have to do is update the const value at the start.

 

It can also make scripts more readable - you don't get bogged down in long string literals but you have a meaningful name (although that's also true for using variable names)

Posted
There's 2 reasons really - the first is about the fact that it's something that you might want to use loads of times and you don't want to have to change the value throughout the script. The second is the fact that you're saying that the value can't be changed - this avoids making errors where you accidentally change something.

 

Take an example, you're writing a script which is going to connect printers on a server. Let's suppose the server is called server1. You could list all your printers as "\\server1\printer1" "\\server1\printer2" etc but then when you get a new server you have to change all those references. If you have const sServer="\\server1\" at the beginning and then lines like mapprinter sSever & "printer1" then all you have to do is update the const value at the start.

 

It can also make scripts more readable - you don't get bogged down in long string literals but you have a meaningful name (although that's also true for using variable names)

 

I did something like that for a printer script I did on here somewhere where I used const values for the share names as the print server was only one server so I made the share names const values.

 

Thanks for the clarification

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