Garacesh Posted January 26, 2012 Posted January 26, 2012 Okay, so long-story-short I've recently started an apprenticeship with a school as you might expect, that's involved delving into the Command Line more than I've previously done (the extent of my pre-apprenticeship CLI usage was mostly limited to ipconfig) - which has in turn gotten me somewhat inrigued into scripting. I knew batch files existed but never really bothered with them until now, and using a few sites online that list commands, combined with a little intuition (and trial-and-error logic) I've so far coded two batch files.. One's a script that Y/N promps to back up E:\ drive (usb flash drive), if N is returned, it asks for a separate location to back up. It then creates date-named folders and xcopy's the files over. The second's a (useless) script that asks for a number, starts at zero, and keeps adding 1 until it reaches that number. Admittedly I only wrote that one to discover if causing a coding loop was possible. So I'm just wondering what more experienced techies might use batch files for, out of interest. I've seen most scripts here are what might as well be Klingon, since (as of yet) I know no programming languages (although I might just give a bash at learning one)
saundersmatt Posted January 26, 2012 Posted January 26, 2012 Not batch scripts per-se, but two of my more advances scripts are: Enumerate staff/student home folders and delete any that are no longer associated with an AD user account, written in Python. Bulk attaching linked documents in SIMS.net to students via simulating keypresses/mouseclicks. Matt
MattHarwood Posted January 26, 2012 Posted January 26, 2012 I have one batch file that runs all the install files for Reader, Flash etc. so if I'm "cleaning up" a system and it's easier than reaching for PDQ Deploy, I'll run that locally. Also have one on login to add printers and shared drives, but I don't like doing that. It's something that was already here. Also have our login/logoff logs as batch files. PM me if you'd like a copy of them. As for learning a language - DO IT! It's extremely rewarding and useful. It's the equivalent of learning to grow and make your own food, not dependant on other people. Can't find an app to do something? Code it!
36Degrees Posted January 26, 2012 Posted January 26, 2012 The only batch file I use deletes the cached local copy of pupils profiles but I do have various VBScript files.
pete Posted January 26, 2012 Posted January 26, 2012 As others have implied - dirty hacks until I do it properly via powershell or python. Bulk attaching linked documents in SIMS.net to students via simulating keypresses/mouseclicks. *is intrigued and would like to subscribe to your newsletter*
jinnantonnixx Posted January 26, 2012 Posted January 26, 2012 Batch files? Tons of 'em. It depends what you want to do. For instance, if you need to create a lot of folders and assign specific security, it makes sense to use batch files as you're staying close to the native commands - e.g. md, icacls. If you want to create AD users, you might use LDAP from VBS, or Powershell. DOS/Windows batch files are really quite limited though, with flaky logic controls and hacks a plenty. Not so with Linux's Bash, however, you can actually write proper code in Bash.
Garacesh Posted January 26, 2012 Author Posted January 26, 2012 simulating keypresses/mouseclicks. With a batch file? This intrigues me... I was unaware you could do something like that.
LosOjos Posted January 26, 2012 Posted January 26, 2012 Not batch scripts per-se *SNIP* Bulk attaching linked documents in SIMS.net to students via simulating keypresses/mouseclicks. My money is on VBS
themightymrp Posted January 26, 2012 Posted January 26, 2012 I have various ones lying around but the majority of mine are VB scripts. However .bat files are a great way to ease yourself into scripting. The majority of my batch files tend to be for doing simple software installs based on certain criteria. For example: if not exist [i]path to reference file[/i] goto install exit :install path to install / relevant switches for silent install copy \\server\path\reference file to c:\path to reference file Just simple stuff really. My more advance scripts - dealing with creating AD accounts and folders - tend to be in VB as I'm not fully confident on Powershell just yet
LosOjos Posted January 26, 2012 Posted January 26, 2012 A lot of my scripts (mostly VBS) deal with automating repetitive SIMS tasks, e.g. converting my exported XML to Excel/Word, bulk setting of print options for exported marksheets, automated running of reports etc.
saundersmatt Posted January 26, 2012 Posted January 26, 2012 With a batch file? This intrigues me... I was unaware you could do something like that. My apologies, I'd meant to include a note like in the previous line about what language I use. For clarification it's an AutoIt script, using a lot of window controls (which was a royal pain to develop but much better than manually linking FFTLive exports to students)
Dos_Box Posted January 26, 2012 Posted January 26, 2012 Moving to Scripts forums. To the OP, have a real good nosy around in here, there are plenty of good examples you can hack apart and do 'stuff' with. *Edited to add: OK, which mod beat me to it?
gshaw Posted January 26, 2012 Posted January 26, 2012 Usually for installers to save typing long command lines and previously for login scripts... most of that done via GPP now
Garacesh Posted January 26, 2012 Author Posted January 26, 2012 Moving to Scripts forums. To the OP, have a real good nosy around in here, there are plenty of good examples you can hack apart and do 'stuff' with. Really? I'm sure I posted it in Scripts.. That's what I get for having multiple tabs open >.> Whoopsie. I'll make sure to have a good nosey around, but a lot of the stuff here confuses me as of current xD Possibly because I have no interaction with them before.. or any interaction with the software or setups they're written to work with..
OB1 Posted January 26, 2012 Posted January 26, 2012 I'm a Linux user myself, but have scripts for all sorts of things, stripping specific elements from large files, bulk creation/delete (careful with that last!), anything repetitive or involving a lot of information. My advice would be learn something like python or perl, both have pretty straightforward file handling and will teach you all the basics of programming quite quickly, which is really all scripting is. Most important of all, enjoy it! 1
featured_spectre Posted January 26, 2012 Posted January 26, 2012 Batch files for the following Building folder trees for new users (Home drive, English, maths, science etc) Adding the user to active directory Also do it for bulk users (new year groups).
sonofsanta Posted January 26, 2012 Posted January 26, 2012 Well I use Powershell to bulk-create new users (year 7s, controlled assessments), but I do that by creating a CSV with all the information in, based on a big Excel sheet with lots of text functions applied to generate paths and usernames. Then I tweak a few lines of powershell code to point at the right CSV and just copy and paste that, so not really a script file. In terms of actual BAT files, I think the only one I genuinely use is one that just pings all my servers when I run it so I can quickly check they're all up in the morning when I come in. Which is a pretty pathetic level of scripting tbh :/
Garacesh Posted January 27, 2012 Author Posted January 27, 2012 More useful than a looping (x)+1 script, though. Some interesting ideas I wouldn't have thought of.. Creating folders/trees isn't half bad, 'specially if you have to sort lots of things in lots of places by the same methods. As for adding users, well I've been shown how to do that once and it's really just copying another student and changing the values. Hadn't considered batch-adds for at the start of the school year, though..
Mr.Ben Posted January 27, 2012 Posted January 27, 2012 I use .bat scripts to create folders and a few other simple tasks. The majority of the scripting that I do is in .vbs now, but this is being replaced by powershell. In short - knowing how to do all three is great - you can pick the right tool for the job. 1
mrbios Posted January 27, 2012 Posted January 27, 2012 Used to use batch files for all sorts of things in the windows XP days, since rolling out 7 though i think i've only used batch files for two things and neither are client related. I've got one set for changing permissions on home folders, though that was a one time thing i hopefully shouldn't need to do again. I've got another that is attached to a task scheduler and runs setACL.exe to change permissions on a schedule for a particular set of folders to allow students access only at a specific time.
Rammie Posted March 30, 2012 Posted March 30, 2012 I use MS BATCH all the time, Garacesh, but as already mentioned, you need several different languages - horses for courses. Why BATCH? Well the most candid reason is to admit I spent a long time in the "early days" using DOS, so I'm really good at it. But more to the point, BATCH leverages very many command-line functions in the most apt and direct way. While you can achieve the same thing using VB, PowerShell etc, sometimes the method works out more complicated. Often I can achieve a task in five lines of BATCH that takes 25 in VB, but often it's the other way around too. However, I will say that debugging BATCH is extremely easy once you're familiar with it, because you can see exactly what's happening as it happens. I know the idea of learning several programming methods sounds really intimidating, Garacesh, but once you know one, you understand the methodology and the rest get easier. We've got BATCH scripts for creating users, purging files and profiles, software installs and cleanups, user activity, network device status, creating email groups, loads of things.
mac_shinobi Posted March 30, 2012 Posted March 30, 2012 (edited) I'm a Linux user myself, but have scripts for all sorts of things, stripping specific elements from large files, bulk creation/delete (careful with that last!), anything repetitive or involving a lot of information. My advice would be learn something like python or perl, both have pretty straightforward file handling and will teach you all the basics of programming quite quickly, which is really all scripting is. Most important of all, enjoy it! i was gonna say vbs or powershell? Original question, what do you use bat files for , only things I can think of 1. using the find and ipconfig command to only show the ip address of said computer 2. using wmic to show information about a computer i.e. model, make, serial number and other things i.e. computer name etc 3. using the net use command ( can be used in various ways to achieve different things ) such as starting, stopping services, resetting a password etc 4. renaming, copying and deletion of files and or directories with relevant switches when required ( sometimes use the RD command with /s and /q switches to fix the recycler issue ) 5. Launching and executing of other utils i.e. for re doing permissions Can't think of anything else although they can be used to add printers etc using the relevant rundll32 commands etc Edited March 30, 2012 by mac_shinobi 1
sted Posted March 30, 2012 Posted March 30, 2012 software installs file backup / copying (yes you can copy say ini files with gpp/vbs but gpp you have to spec them 1 by 1 as far as i can see and vbs is more code for same result) regedit to add/remove settings scheduled tasks
SkreeM1980 Posted April 23, 2012 Posted April 23, 2012 I think most people have hit the nail on the head, you use different scripting languages for different things, we have a lot of VBS for printer mapping and drive mapping, plus some other stuff with environment variables .. but we also do plenty with Batch files and have got some PS stuff but thats a massive learning curve for me. The last batch file i remember writing is to make Dameware Utilities available in SafeMode with networking. IT was the easist way to copy a folder and all containing values from one reg branch to another. 2 or 3 lines, in VBS it would have taken loads more.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now