Intro to VB Script: a beginners guide by cammel8
***((((ALERT: Although there are a lot of steps. this is actually quite easy. I just explain everything in detail for the beginners. If you just want the code jump to the last step and you will find the full code there.))))***

I play a lot of Xbox live and always have to disable the internet on my computer because it hogs bandwidth. Mainly because I am downloading or uploading things all the time. The problem isn't shutting it off but it is turning it back on that I forget, making it to where I loose out on all that upload/download time.

So I decided to create a program to do it for me. I was going to write it in Vb.net but I just recently had to nuke and pave my operating system on my computer because of a bad storm frying my hard drive, and haven't reinstalled VB.net yet so I just figured this would give me a reason to play with vbscript.

I also made an image in paint to display in the background so i knew it was running.

 
Remove these adsRemove these ads by Signing Up

Step 1: Figure out what you want to do.

The first thing I always do is make a plan.

What do I want the program to do?

A) I want to be able to open the script and it will automatically shut off the connection.
B) I want it to display a giant display in the background so there is no mistake that the internet is off, this way I don't forget to turn it back on.
C) I want it to give me a choice to turn it back on and then wait for a response.
D) I want it to make sure i turn it back on so i don't forget.
E) Then once I actually do say yes to turn it back on, the script turns it back on and then closes the background.
F) Exit everything.
muttyfutty says: Oct 1, 2009. 11:29 PM
If you want to send the 'enter' key you just type {enter} can you do the same with for example, {F1} or {alt} also, can you move or exchange a shortcuts target? Thanks alot, Mike
cammel8 (author) says: Oct 2, 2009. 11:12 PM

I was going to answer this with a long drawn out answer but then i realized I could just do this...

http://www.scriptlogic.com/Kixtart/htmlhelp/Functions/sendkeys.htm

This site should answer both your answers in one site. Hope it helps and if it doesnt answer your question message me and I will try to help you further.
muttyfutty says: Oct 3, 2009. 1:54 AM
Thanks
techwiz24 says: Aug 10, 2009. 6:07 AM
could you use this to disconnect a network drive, display a picture, and then ask to reconnect the network drive? and by network drive, I mean an external hdd. when it reconnects, I also need it to name the external hdd, like HDD1e. I can get everything except the CMD commands for it. I think you can use diskpart, but am not sure,
cammel8 (author) says: Aug 10, 2009. 12:09 PM
well if i had to wager a guess I would have to say yes you can probly do it, however I have no way of chacking it to see if it works cause i dont have a networked external drive to check it on. if i had to wager a guess on how to do it i would have to say : picture.... this part wouldnt change. changing name of drive try maybe "label" disonecting and reconecting drive.... Try "mountvol" I dont have time to play with it now but I will play later and see if I can do it for you. Short of that if you want to try on your own just type "Mountvol /?" in a command window and it will give you all the info you need to work with it. you can use the "/?" help switch after any command and it will give youhelp on that command. If I can get it to work I will make a new instrucatable for it tonight.
techwiz24 says: Aug 10, 2009. 2:56 PM
thank you!!!
cammel8 (author) says: Aug 10, 2009. 10:39 PM
Try checking this out.... I finished your script tonight. hope this helps ya. http://www.instructables.com/id/VBScript-Working-with-mounted-drives
erikals says: Jul 1, 2009. 7:54 PM
this is really cool if only there was a way to integrate the disable internet function into a fake virus... is that possible, a fake virus without shutdown?
cammel8 (author) says: Jul 14, 2009. 2:43 PM
yeah you could do it relatively easy. Just take the shutdown command out of the code.
erikals says: Jul 17, 2009. 9:21 PM
thanks
DJP4VEP says: Apr 21, 2009. 1:20 AM
ok i need help. i have created a vbscript that is a fake virus but at the end i want the computer to shutdown after 60 seconds. i have tried putting "shutdown.exe -s -t 60 -c "Hard drive dump complete. Please contact you administrator"" but it doesnt work. can you help me please. thanks
cammel8 (author) says: Apr 21, 2009. 3:32 PM
Sorry I didn't realize you were trying to comment as well. Sorry.

If I had to wager a guess I would have to say It may have something to the way the comment is nested in the line of code. You can't have a set of "" nested inside another like you have it. The computer sees the second " and thinks it is the end of the line and regards the rest as a comment or something.

If I had to guess I would say it should be like this

"shutdown.exe -s -t 60 -c 'Hard drive dump complete. Please contact your administrator'"

Notice the differentiation between ' and " in the strshutdown line. I think it may work but you have to make sure you have correctly nested the comment or it will either ignore it or skip the line completely. Which I believe is the problem now.

Have you tried the code without the comment and see if it works. Also try putting in a force close command (-f). It may be that you are not forcing the programs that are running to close and it aborts because it can't shutdown without them programs closing.

But like I said to begin with I think it has to do with the way it is nested. I think also that if you are using the sendkeys command to do this it may give you lots of problems nesting, even with the use of single quotes nested in doubles.

If that's the case you should be able to use it in as string and the direct to the string something like this.

Dim objShell
Dim strShutdown

strShutdown = "shutdown -s -t 60 -f -c 'Hard drive dump complete. Please contact you administrator'"

set objShell = CreateObject("WScript.Shell")

objShell.Run strShutdown

Wscript.Quit

If none of these help let me know and I will see what I can figure out. I haven't actually tested any of these codes but in theory they should work. I have been doing them mainly from memory and don't really have time to test them properly. But it should at least give you some ideas on where to look.

Hope this helps.
cammel8 (author) says: Apr 21, 2009. 2:33 PM
One way I know of to guarantee a shutdown, is to shutdown the lsass.exe file. Once it is closed the computer will shut down within either 30 seconds or a minute... I can't remember, But it cant be stopped. Wont hurt anything as far as I know. Try that.
stephenniall says: Apr 19, 2009. 12:26 PM
Oo cool lol nce desktop
zetsway says: Apr 15, 2009. 11:27 AM
I really enjoyed this. Keep up the good work.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!