Archive for the ‘Windows 7’ Category

Create a Self-signed SSL Certificate on Windows

Thursday, November 24, 2011 posted by CSch

SSL (Secure Socket Layer) is used for encryption and decryption, processing of S/MIME signed or encrypted mails, generation of certificates and more. To use it on Windows (32 and 64 bit versions), download the OpenSSL tools from code.google.com/p/openssl-for-windows/downloads/list.
Uncompress it anywhere you like and start it by double-clicking the openssl.exe executable in the \bin folder.

If you create files with OpenSSL, they will appear in the \bin directory by default.
To create a self-signed SSL certificate, you first need a key. Create it like this:

genrsa -des3 -out server.key 4096

Type in your desired key (password) and confirm it. Next, you need a certificate request. Create it as follows and give the path to the config file in the -config option (it should be in the directory where you unpacked the files to):

req -config C:\path\to\openssl.cnf -new -key server.key -out server.csr

Next, sign the certificate request:

x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

The -days option specifies how long the certificate will be valid - mine will be for one year. Now you have a signed certificate.
However if you want to use it with programs as Thunderbird or similar, you will need the certificate to be in the .p12 format. To accomplish this, enter following:

pkcs12 -export -in server.crt -inkey server.key -name "Your Full Name" -out server.p12

Save Power On Screen Lock (Windows 7)

Wednesday, November 23, 2011 posted by CSch

The reason to lock your screen (Windows key + L) usually is that you leave your computer, meaning it would be reasonable to turn off everything else there is on your computer as the sound or your screen as well. MonitorES is a utility that does this for you whenever you lock your screen.

It turns off the screen, mutes your computer, pauses any media playing and changes your IM status to "Away" if you want it. Download it on http://code.google.com/p/monitores/

Tag Your Soundfiles Fast with Mp3Tag (Windows)

Monday, November 21, 2011 posted by CSch

Mp3Tag is a program on Windows that lets you import the most common sound files you have got on your computer and quickly change their tags like artist, name etc. It is that fast because it enables you to select a whole group of items at once and change the tags they have in common in one action.

Download Mp3Tag on http://www.mp3tag.de/en/download.html

Follow the installation instructions and start the program:

Select the files to tag by either dragging and dropping them on the white item panel or selecting a directory in the system panel. After each tag action, save the current file state. Mp3Tag is able to gather tags from various internet databases to help you get the correct information.

How to Call Functions in Powershell (Windows)

Friday, November 18, 2011 posted by CSch

Functions in Powershell are called without any comma or parenthesis, although they are defined using them. The correct way to call a function with two variable parameters would be:

test $local1 $local2

The wrong way is:

test($local1, $local2)

If you put parentheses around your parameters, your input is treated as array and thus the processing might not run as you expect. If you want the input to be an array and to be converted to a string inside the function, use the out-string cmdlet. Type out-string -? for more information.

Timed Shutdown on Windows

Thursday, November 17, 2011 posted by CSch

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)

Wednesday, November 16, 2011 posted by CSch

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)

Tuesday, November 15, 2011 posted by CSch

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)

Monday, November 14, 2011 posted by CSch

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")

There is a feature in NTFS data system that lets you easily hide your files from nosy people using your computer which is called Alternate Data Streams. What they basically do is to hide files behind others, using them as a "container", but they only are executable if you enter a specific syntax in your command line. I will show you in a few examples.
I have the text document mysecrets.txt which I want to hide inside the legal.txt document. They are both placed directly on my C:\ drive to simplify things. To achieve that, I open a command line and type in:

type C:\mysecrets.txt >C:\legal.txt:mysecrets.txt

With the type command, you can stuff any file into an alternate data stream. Next you give the file to hide, followed by a greater-than sign, followed by the the path where you want to hide the file - here, give the file you want to stuff things in, a colon, and the hidden file's name (this can basically be any, you call the hidden file by this given name then). The colon is the trademark of an alternate data stream, every file separated from another file with a colon will become the first file's alternate data stream.

Text files are not the only files you can hide away with alternate data streams, basically you can do it with any file, even executables. However you cannot open every file from an alternate data stream - starting executables for example has been disabled for security's sake because, as you might have noticed, AltDS can be used to build pretty evil malware. To open a hidden file, you just pick the program to do so and open it the usual way through the command line, for example like this:

notepad C:\legal.txt:mysecrets.txt

You can also do this for videos, music, whatever, just pick the appropriate application. For executables however, this is no longer possible. However there are some slightly more complicated workarounds to do this. You can either have a symlink of the hidden file made, which is then executable and deletable afterwards, or write commands into the hidden file which can be executed by the shell, creating another executable or whatever you want to do with it.
Be aware however that alternate data streams will be lost after moving their containers to another server! It is not possible to mail multi-streamed files, even if the receiving file system is NTFS formatted.
To uncover alternate data streams on Windows Vista or later, direct your command line tool to the folder you want to check and enter

dir /r C:\path\to\your\folder

You cannot hide whole folders in alternate data streams, except if they are compressed.
The easiest way to delete alternate data streams is to copy the whole file onto another data system via explorer, ftp or mail. However there is also software to detect and deal with them.

While scripting, you may encouter the problem that you have an expression that uses double-quotes as tags and therefore cannot use any double-quotes inside these tags. You can circumvent this problem by using ASCII codes to add certain keys. This is done by tagging out, joining with ASCII code and joining with the tagged expression again. Look at the following Visual Basic Script code:

set objshell = wcript.createobject("wscript.shell")
objshell.run "C:\Windows\system32\cmd.exe /K cd " & Chr(34) &
"C:\Users\howtoforge\Desktop\A Folder" & Chr(34) & ""

The double-quotes inside the run command are represented by the expression Chr(34) that adds the ASCII character with the ID 34, which is double-quotes. This expression is outside the regular quotes and is joint with the command with an Ampersand (&). Thus the above line would result in following line being entered into cmd:

cd "C:\Users\howtoforge\Desktop\A Folder"