1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VB Script to Run a Batch File and Utilize a Text File

Discussion in 'Software Development' started by ncktravis, Aug 10, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. ncktravis

    ncktravis Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    11
    Backround: I am a college student majoring in Information Technology with a focus in programming. I also work for my school's IT department as an IT associate. I have 4 years of experience dealing with hardware and software and have studied Net+ and A+ certification books.

    Problem: At my school my boss, the IT Director, wants to schedule a batch file to run weekly that will delete items from the desktop and folders of the "Student" account on all of the student computers. He asked us associates to go around to every student computer with this batch file on a thumb drive and schedule the task. Seems simple enough right? The problem is we are talking upwards of 300 computers throughout the campus. I proposed a solution to him where we would use a script that would essentially consult a text document with the names of all of the student computers in it, then run the file.

    I am 99% this can be done, I just have a very small amount of programming experience. If anyone has an answer or knows of an easier way to accomplish this I appreciate it. Thanks in advance. :)

    EDIT: All student workstations are running Windows XP SP2
     
  2. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    By the sound of it it could be done; the question is whether it's the best way of doing it.
    1: How do you propose to get these computers to execute the VBS? Taking it round on a flash drive isn't a great improvement ;).


    Other questions about your scheme:
    Why use both batch and VBS instead of just one or the other? (worst case scenario VBS can simply execute each of the shell commands in the batch file.)
    How involved do you want to be in writing the script?
     
  3. ncktravis

    ncktravis Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    11
    I'm almost certain there is an automated way to get this job done, like you said perhaps using a batch file or script isn't the best way and Bill Gates has an easier way to do it built into MS Server.

    I've been searching through countless web sites and trying to research and the conclusion I came to is a VBS may be the least painstaking way of going about this. I actually just recently came upon a thread on another site where someone was looking to shutdown every computer on their domain with a few clicks using a shutdown batch. Similar situation, just a different end result. We already have the simple batch file, I wasn't sure if it could just be edited to run on all of the workstations named in a text file or if I would have to use a VBS for that. As far as how involved I'd like to get in writing this script, I've done simple programming, and this is a simple objective. So I'm hoping it won't have to be too involved, but I'm not afraid to get my hands dirty so to speak. :)
     
  4. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,384
    If all user accounts are named 'student' and all are XP...why not write the bat to execute from any machine on the network with proper credentials...like so (as an example)...

    del \\computer1\c$\documents and settings\student\desktop\*.*
    del \\computer2\c$\documents and settings\student\desktop\*.*
    del \\computer3\c$\documents and settings\student\desktop\*.*

    ...

    And then schedule it.

    Of course this assumes that the 300 are on the same network and that you have the proper credentials. Obviously, you'll want to test...
     
  5. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    It's impossible to give specific advice without knowing how the network is actually set up.
    I would imagine that students are in a specific group for security policies et cetera, and I would therefore imagine that you could ignore the whole text file stage and just put some extra lines on the end of the logon script that I imagine members of said group already run.

    Incidentally, I love writing scripts and programs, but in the real world there can be a time when it's genuinely not worth it. In terms of time alone the time taken to design, test, and deploy an automated solution could be longer than getting a bunch of guys to wander round the school with USB sticks. In terms of experience writing software would do you a lot more good than plugging in flash drives, which is why it probably is in your interest to get your hands dirty.
     
  6. ncktravis

    ncktravis Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    11
    @Chris I think that should do it, I didn't even think of that. Of course it will have to be run with administrative credentials, which I have. Every computer is connected to the same network, and doing it that way I can easily exclude staff computers.

    @Josiah That is very true, programming is definitely what my concentration is, and I wouldn't mind, in fact would love to get my hands dirty. I knew it could be automated in some way, somehow.

    As far as I'm concerned I think I've got my solution. Time to go test it out.

    Cheers
     
  7. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    Remember that you have to test your solution in all the situations it could encounter.
    The last thing you want is that it fails on one line (because a computer has been shut down for example) and then exits instead of doing the rest of the script.

    Also, use a loop. :D
     
  8. ncktravis

    ncktravis Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    11
    Right, I could set it to ping each target computer, and if found online it would then delete the files, if not, well then it wouldn't?

    Or would a computer being offline even have an effect on the process? Other than the fact that that computer or computers wouldn't have their items being deleted?
     
  9. Ent

    Ent Josiah Trusted Advisor

    Joined:
    Apr 11, 2009
    Messages:
    5,408
    That's one good check. You really do have to think about what kinds of situations you'll encounter.
    Another possible problem I'd foresee is the possibility that a file is still in use and/or locked.
     
  10. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,384
    Yes! Error handling is a must. I wouldn't ping though, just write something for if the path is not found. Also, I would log what's being deleted for trends analysis (security, productivity, etc). Don't forget to have fun also. :)
     
  11. ncktravis

    ncktravis Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    11
    That is also true, it'll definitely be an all day affair if not longer. But once completed, and tested/tweaked to function properly it will be simple to add/del computers from the bat. For example if the school receives a new shipment of workstations it is much faster to edit a file than to individually schedule a task.
     
  12. ncktravis

    ncktravis Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    11
    @Chris Could I get an example of what that would look like including the loop, etc?
     
  13. ckphilli

    ckphilli

    Joined:
    Apr 29, 2006
    Messages:
    4,384
    I'm actually on my phone waiting for a meeting, sorry. But if you haven't gotten it by tomorrow or if Ent doesn't do it I'll put something up for you.
     
  14. ncktravis

    ncktravis Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    11
    I'm attempting to work this out myself, but if I had something to check against it would make my night a tad easier.
     
  15. ncktravis

    ncktravis Thread Starter

    Joined:
    Aug 10, 2012
    Messages:
    11
    Not a problem, I'm going to see what I can do. Here's to a night of trial and error.
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1064605