Posts Tagged ‘vbscript’
Wrap VBScripts into .exe Format
To convert your VBScript to an .exe file, or rather make them look like one, there is a native Windows tool called IExpress which you can access through your menu’s searchbar.
Select Create new Self Extraction Directive file and choose Extract files and run an installation command afterwards. Enter a package title and decide whether you want the user to be prompted or not and if you want a licence to be shown. Now browse the executables you want to wrap and select the files for installation in the next window. If they are not displayed in the dropdown menu then type their name in again manually.
If you want multiple scripts to be installed, enter cmd /c script1.vbs && script2.vbs for example. After some more configuration the executable will be placed in the directory you specified in one of the last steps.
Timed Shutdown on Windows
You can time a shutdown on your computer easily by creating a short vbscript that contains either only the shutdown command, or a shutdown command with an integrated second timer. If you do not add a timer, you can also use Windows’ Schedule Tasks function to have the computer shutdown at a specific time. The vbscript to shutdown looks like this:
Set objShell = wscript.CreateObject(“wscript.Shell”)
objShell.run(“shutdown /s”)
If you want a timer, add
/t xxx
to the quoted expression in the second line, where x is the number of seconds to count down. Enter this code into a notepad and save the file as .vbs. Do not save it as text file.
Send Mails Via Remote Server With VBScript (Windows)
You can use MS Windows’ VBScript to write a script that is able to log into a remote mail server such as googlemail or any other with your account data and send mails from that server. This can be used to retrieve logs via attachments or to just automate mail processes. The bare script to send a mail looks as follows (the apostrophe after a line signals a comment to the lines content, it does not belong to the script. The data all go inside the doublequotes if there are any):
Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = “Type in the mail’s subject here”
objMessage.From = “ <the sender mail goes here, you need the login data for it>”
‘The mail address goes inside the tags
objMessage.To = “the receiver mail goes here”
objMessage.TextBody = “Here goes the actual mail message”
objMessage.Addattachment “Fill in the complete path to your attachment, otherwise leave complete line”
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
‘determines whether you use local smtp (1) or network (2)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “Fill in your smtp (outgoing) server”
‘You can find your provider’s server address somewhere on the homepage or by googling for smtp server lists
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = 1
‘Determines the authentication mode. 0 for none, 1 for basic (clear text), 2 for NTLM
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “should be the same as the sender mail – login data for your server”
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “your email’s password – login data for your server”
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
‘This is the default port used by most servers. Find out if yours is using a different one if there are problems
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = False
‘Use SSL? True or False
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60
‘Maximum time connection is tried to be established
objMessage.Configuration.Fields.Update
objMessage.Send
It is recommended not to use this script on a computer you are not the only user of, since your email and its password are openly visible. However you can just create a new one for that purpose. You can easily embed this script into any other VBScript, schedule it or do whatever you want with it.
Merge Lines in VBScript (Windows)
If you need to have multiple commands in one line in MS Windows’ VBScript, you can accomplish that by using the colon (:) operator. The following line of script will display two message-boxes after each other:
Msgbox”Hello.” : Msgbox”Hey!”
You can leave as much space as you want between the commands and the colon.
Break Lines in VBScript (Windows)
If you have the problem that you have really long lines in your VBScript that contain only one command, but need to be broken to be able to overview it, you can use the Underscore (_) operator. Placing a space character followed by an underscore at the end of the line will make Windows treat the next line as if it was part of the previous line.
However this does not work as easy for quoted expressions. In this case you have to close the quote, place the underscore and concatenate the next line to the previous one with an ampersand (&) like this (it does not make any sense to break the line here, it is only for demonstration):
Set objFSO = CreateObject(“Scripting.File” _
& “SystemObject”)
