One of my favorite objects is the Wscript.Network object. It's a very simple way to access certain environment variables in a VBScript.
To invoke this object, this line must be inserted near the top of your script (certainly before you reference properties of this object):
Set WshNetwork = CreateObject("Wscript.Network")
What you can do with this is query the properties of username, computername and userdomain. You can also do things like add a network drive and add a printer (as well as deleting them). This is great for a much more flexible login script processing than standard batch.
For example, if you want to map a drive:
WshNetwork.MapNetworkDrive "x:" \\SERVERNAME\SHARE
maps a drive, and the commands to add a printer and make it the default are:
WshNetwork.AddWindowsPrinterConnection \\printserv\DefaultPrinterWshNetwork.SetDefaultPrinter \\printserv\DefaultPrinter
These code snippets apply to Windows 2000 and higher - other parameters may be necessary for earlier systems.
A complete technical description of this object can be found here: http://msdn2.microsoft.com/en-us/library/s6wt333f(vs.85).aspx, but here is a listing of the properties and methods:
Properties
Methods
I hope this is helpful for you. Let me know!
Sitting in training today, the class topic was scripting. Now, most of you admins out there have done scripting in one form or another - whether it was batch or VBScript or even the new PowerShell. I've done it - I've done it a lot, but most of the people in the class have not, which surprised me.
"Hmm," I thought, "I should post some of my scripts on-line." That was an hour ago and the beginning, I hope, of a new outlet for me. On my personal blog, I whine about the weather and being sick and my manager, but that's personal. Now, I will attempt to relate my technological trials and sucesses in the field.
The idea I had which started this was that I could post some of the techniques I have used to do various administrative tasks in the field for my customers on this site - especially so that I can have a good place to come back to when I forget how I did it! I will include some VBScript and some PowerShell commands that I have learned, but the postings will not be restricted to that. I will also show interesting tips for configuring and maintaining some of the technologies that our customers employ.
Of course, by posting some of these things I might be posting things that are available elsewhere, but it's my hope that I can present the material in such a manner that will be simple and easy to understand. I will also try to be as brief as possible so that you are not flooded with too much extra information. I'll even try to post some backup references.
I hope you enjoy my ramblings and that they are helpful to you.