<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
  <channel>
    <title>The Jar</title>
    <link>http://jar.yosephine.com/</link>
    <description>Scripts and stuff I</description>
    <language>en-us</language>           
    <generator>Nucleus CMS v3.32</generator>
    <copyright>Ã¯Â¿Â½</copyright>             
    <category>Weblog</category>
    <docs>http://backend.userland.com/rss</docs>
    <image>
      <url>http://jar.yosephine.com//nucleus/nucleus2.gif</url>
      <title>The Jar</title>
      <link>http://jar.yosephine.com/</link>
    </image>
    <item>
 <title>Christmas wallpaper for everyone, but just for Christmas</title>
 <link>http://jar.yosephine.com/index.php?itemid=25</link>
<description><![CDATA[Hello again, it's been a while since my last post.<br />
<br />
Today i will post some Christmas spirit for all you system admins to share in your network.<br />
<br />
Since last Christmas we have had a special script called from within our logonscript. This special script will change the wallpaper for the users to a random wallpaper from a set of Christmas wallpapers on our server. The script changes the wallpaper only during December. After that it will change the wallpaper back to whatever it was before the change. As this script is called every time the user logs on it will change the wallpaper once for every logon. The change will not be visible to the user immediately, but it will show upon the next logon. This is because Windows has already loaded the wallpaper setting when the script is run, so the change always comes one logon later. The nice thing with this script is that it changes the background upon every logon during December, so users will be presented with various nice Christmas wallpapers. And when the new year comes, the original wallpaper of the user is restored. The script saves the original wallpaper in a file so it can restore it later. The script is not very nicely written, as all this has been done on my own time. <br />
The script works both on Windows XP and Windows 7.<br />
For you to be able to use this in your organization or on your personal Windows computer you will need to edit the following:<br />
<br />
The strBackupFile variable. Currently it points to <i>"c:\temp\wallpaper_username.bak"</i>. I have chosen to save the user's original wallpaper setting in a file called c:\temp\wallpaper_username.bak, in which the "username" will be changed to the user's username. So if my username is Frank the original wallpaper setting will be saved in a file called c:\temp\wallpaper_Frank.bak. If you wish to save the setting somewhere else you need to edit this text to something else.<br />
<br />
The strWPLocation specifies the UNC path to the folder where you have all your nice Christmas wallpapers stored. Users should have appropriate access to this folder to be able to apply the wallpapers. The wallpapers need to be named 1.bmp, 2.bmp, 3.bmp... for this script to work. If you wish to use jpg, png or something else you will need to do a find/replace of all the ".bmp"-strings in the script.<br />
<br />
The intWallpapers should be changed to the number of wallpapers you have in the shared folder. The script uses a crude randomizing function to randomly select any of the wallpapers in the folder.<br />
<br />
Once you have set these variables to suit your environment and need you are ready to go.<br />
As I mentioned earlier we call this script from the logon script. you may run it manually or whatever. Once you run it nothing seems to happen, but you will find the .bak file in the c:\temp folder and on next reboot your background has changed!<br />
<br />
Happy Christmas!<br />
<br />
Option Explicit<br />
<br />
Dim objReg, objFSO, objFolder, objFile, objShell<br />
Dim strComputer, strKeyPath, strValue, variable, strBackupFile, strWPLocation, intWallpapers<br />
const HKEY_CURRENT_USER = &H80000001<br />
const ForWriting = 2<br />
const ForReading = 1<br />
<br />
strComputer = "."<br />
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") <br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
strKeyPath = "Control Panel\Desktop"<br />
strBackupFile = "c:\temp\wallpaper_" & EnvString("username") & ".bak"<br />
strWPLocation = "\\server\share\Christmaswallpapers\"<br />
intWallpapers = 17<br />
<br />
'Check if it's Christmas:<br />
If DatePart("m",now) = 12 Then<br />
	'Wscript.Echo "It's Christmas."<br />
	'Check if wallpaper has already been changed:<br />
	If not objFSO.FileExists(strBackupFile) Then<br />
		'Wscript.Echo "Wallpaper has not been changed."<br />
		'Get current wallpaper:<br />
		objReg.GetStringValue HKEY_CURRENT_USER, strKeyPath, "Wallpaper", strValue<br />
		'Wscript.Echo "Current wallpaper is " & strValue<br />
<br />
		'Save the current wallpaper setting to a file:<br />
		'Wscript.Echo "Saving current wallpaper setting."<br />
		On Error Resume Next<br />
		Set objFile = objFSO.OpenTextFile(strBackupFile, ForWriting, True)<br />
		If Err.Number Then<br />
			Wscript.Quit<br />
		End If<br />
		On Error GoTo 0<br />
		objFile.WriteLine strValue<br />
		objFile.Close<br />
		<br />
		'Change the wallpaper to Christmas:<br />
		'Wscript.Echo "Changing wallpaper."<br />
		Randomize<br />
		objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, "Wallpaper", (int(intWallpapers*Rnd+1)) & ".bmp"<br />
	Else<br />
		'Wallpaper has been changed, but it's still Christmas, so change to another Christmasy wallpaper!<br />
		'Wscript.Echo "Changing wallpaper."<br />
		Randomize<br />
		objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, "Wallpaper", (int(intWallpapers*Rnd+1)) & ".bmp"<br />
		<br />
	End If<br />
<br />
Else<br />
	'Wscript.Echo "It's NOT Christmas."<br />
	'Check if wallpaper has already been changed:<br />
	If objFSO.FileExists(strBackupFile) Then<br />
		'Wscript.Echo "Wallpaper is still Christmas."<br />
		'Change wallpaper back to original:<br />
		'Wscript.Echo "Changing back wallpaper to original."<br />
		Set objFile = objFSO.OpenTextFile(strBackupFile) & ".bak", ForReading, True)<br />
		strValue = objFile.Readline<br />
		objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, "Wallpaper", strValue<br />
		objFile.Close<br />
		<br />
		'Delete wallpaper backup file:<br />
		'Wscript.Echo "Deleting wallpaper setting file"<br />
		objFSO.DeleteFile(strBackupFile)		<br />
	End If<br />
End If<br />
<br />
<br />
<br />
Function EnvString(variable)<br />
'This function returns a particular environment variable’s value.<br />
' for example, if you use EnvString("username"), it would return<br />
' the value of %username%.<br />
    set objShell = WScript.CreateObject( "WScript.Shell" )<br />
    variable = "%" & variable & "%"<br />
    EnvString = objShell.ExpandEnvironmentStrings(variable)    <br />
    Set objShell = Nothing    <br />
End Function<br />
]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=25</comments>
 <pubDate>Wed, 30 Nov 2011 09:08:10 -0500</pubDate>
</item><item>
 <title>SSH Hammering prevention</title>
 <link>http://jar.yosephine.com/index.php?itemid=23</link>
<description><![CDATA[I have a Windows 7 computer running an SSH server. I don't trust RDP, so I won't allow connections over RDP from the Internet. Instead I have chosen to trust SSH for remote access. I therefore tunnel RDP over SSH to be able to use Remote Desktop. This works for me and I can access my home computer from almost any Internet-connected computer.<br />
The thing that worries me, however, is the fact that so many password guessing attacks are being made all the time, and the SSHD itself doesn't provide an adequate protection against these. I can limit the amount of failed logon attempts before the server closes the line, but the attacker can just reconnect and try again. I can naturally also make sure that I don't permit root logon and restrict which accounts are allowed to log on remotely. Also, I could allow only certain hosts to connect, but this doesn't work either, as I often need to access my computer from whatever computer.<br />
With thousands of script kiddies hammering my box hour after hour I'm not comfortable with only the above security measures. <br />
<br />
I want to be able to block computers that have performed several unsuccessful logon attempts within a short time frame. In other words, I want to block attacks like these:<br />
<br />
<i>Invalid user apache from 79.29.80.124<br />
input_userauth_request: invalid user apache<br />
Failed password for invalid user apache from 79.29.80.124 port 50074 ssh2<br />
Received disconnect from 79.29.80.124: 11: Bye Bye<br />
Invalid user root from 79.29.80.124<br />
input_userauth_request: invalid user root<br />
Failed password for invalid user root from 79.29.80.124 port 50901 ssh2<br />
Received disconnect from 79.29.80.124: 11: Bye Bye<br />
Invalid user root from 79.29.80.124<br />
input_userauth_request: invalid user root<br />
Failed password for invalid user root from 79.29.80.124 port 50915 ssh2<br />
Received disconnect from 79.29.80.124: 11: Bye Bye<br />
Invalid user network from 79.29.80.124<br />
input_userauth_request: invalid user network<br />
Failed password for invalid user network from 79.29.80.124 port 52613 ssh2<br />
...</i><br />
<br />
So I wrote a script!<br />
<br />
This is just a beginning of something that could prove useful. The script is designed to be run every hour, ten minutes, whatever, and reads the sshd log and checks for failed logon attempts. The script employs a threshold and any IP that has a failed logon attempt count above the threshold will be blocked from accessing the server. The blocking is performed by adding a blocking rule to the Windows firewall. The script currently never removes any of these rules, so they might build up. Maybe in the future I will enhance the script to employ a method for removing rules over a certain age.<br />
I put the script to run every hour in my Task Scheduler.<br />
Option Explicit<br />
Dim intSize, i, intTreshold<br />
Dim strTimestamp, strRunning, strServiceName, strComputer, strLogPath, strLogName, strLine<br />
Dim objWMIService, colListOfServices, objService, objState<br />
Dim colState, objFSO, objTextFile, objShell, objWshScriptExec<br />
Dim boolMatch<br />
Dim arrLine<br />
Dim arrIPList(), arrIPList2()<br />
<br />
Const ForReading = 1<br />
<br />
strComputer = "."<br />
<br />
'Block IP if failed logon attempts is more than the number below:<br />
intTreshold = 10<br />
<br />
'Path and filename to sshd.log:<br />
strLogPath = "C:\Cygwin\var\log\"<br />
strLogName = "sshd.log"<br />
<br />
'Enter name of sshd service here:<br />
strServiceName = "sshd"<br />
<br />
intSize = 0<br />
<br />
<br />
strTimestamp = DatePart("yyyy",Now) _<br />
		& Right("0" & DatePart("m",Now), 2) _<br />
		& Right("0" & DatePart("d",Now), 2) _<br />
		& Right("0" & DatePart("h",Now), 2) _<br />
		& Right("0" & DatePart("n",Now), 2)<br />
<br />
'Stop service in order to release file lock on log file:<br />
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & <br />
<br />
strComputer & "\root\cimv2")<br />
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where <br />
<br />
Name = '" & strServiceName & "'")<br />
For Each objService in colListOfServices<br />
	objService.StopService()<br />
	strRunning = 1<br />
	do while (strRunning = 1)<br />
		Wscript.sleep 5000<br />
		Set colState = objWMIService.ExecQuery ("Select * from Win32_Service <br />
<br />
Where Name = '" & strServiceName & "'")<br />
		for each objState in colState<br />
			Wscript.Echo objState.DisplayName  & VbTab & objState.State<br />
			if (objState.State = "Stopped") Then<br />
				strRunning=0<br />
			end if<br />
		Next<br />
	Loop<br />
Next<br />
<br />
'rename log file:<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
objFSO.MoveFile strLogPath & strLogName , strLogPath & strTimestamp & ".log"<br />
<br />
'Start service:<br />
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & <br />
<br />
strComputer & "\root\cimv2")<br />
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where <br />
<br />
Name = '" & strServiceName & "'")<br />
For Each objService in colListOfServices<br />
	objService.StartService()<br />
	strRunning = 0<br />
	do while (strRunning = 0)<br />
		Wscript.sleep 5000<br />
		Set colState = objWMIService.ExecQuery ("Select * from Win32_Service <br />
<br />
Where Name = '" & strServiceName & "'")<br />
		for each objState in colState<br />
			Wscript.Echo objState.DisplayName  & VbTab & objState.State<br />
			if (objState.State = "Running") Then<br />
				strRunning=1<br />
			end if<br />
		Next<br />
	Loop<br />
Next<br />
<br />
'Parse log file for failed logon attempts and put IP addresses & attempt count in arrays:<br />
Set objTextFile = objFSO.OpenTextFile(strLogPath & strTimestamp & ".log", ForReading)<br />
ReDim Preserve arrIPList(intSize)<br />
ReDim Preserve arrIPList2(intSize)<br />
Do Until objTextFile.AtEndOfStream<br />
	strLine = objTextFile.ReadLine<br />
	if instr(strLine,"Failed password for") <> 0 Then<br />
		arrLine = Split(Replace(Replace(strLine," invalid user ",""),"Failed password for","")," ")<br />
		boolMatch = 0<br />
		For i = 0 to intSize<br />
			If arrLine(2) = arrIPList(i) Then<br />
				boolMatch = 1<br />
				arrIPList2(i) = arrIPList2(i) + 1<br />
			End if<br />
		Next<br />
		If boolMatch = 0 Then<br />
			intSize = intSize + 1<br />
			ReDim Preserve arrIPList(intSize)<br />
			ReDim Preserve arrIPList2(intSize)<br />
			arrIPList(intSize) = arrLine(2)<br />
			arrIPList2(intSize) = 1<br />
		End If<br />
	End If<br />
Loop<br />
<br />
Set objShell = CreateObject("WScript.Shell")<br />
For i=0 to intSize<br />
	If arrIPList2(i) > intTreshold Then<br />
		Set objWshScriptExec = objShell.Exec("netsh advfirewall firewall add rule name=SSHBLOCKER_" & strTimestamp & " dir=in action=block remoteip=" & arrIPList(i))<br />
	End If<br />
Next ]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=23</comments>
 <pubDate>Wed, 27 Oct 2010 07:52:23 -0400</pubDate>
</item><item>
 <title>The problem with Java Runtime Environment...</title>
 <link>http://jar.yosephine.com/index.php?itemid=20</link>
<description><![CDATA[The problem with Java Runtime Environment is that security holes and flaws are constantly found and new patched versions and updates pop up way too often. This causes a lot of work for the person(s) in charge of keeping the Java up to date on the computers. This is especially true if the company has business critical applications that rely on JRE and if the company therefore does not allow the JRE on the workstations to update themselves automatically or if the level of permissions granted to the users is too low for using JRE's autoupdate feature.<br />
I happen to work at such a place. As we have about 1500 computers, most of which need to have JRE installed, there's a lot of work keeping the JRE's on the workstations up to date. Even though we have a workstation management system for deploying the new Java it's a lot of work. To ease the burden of keeping the JRE environment up to date I made a simple script to remove all old versions of Java and install the new veresion.<br />
The script checks what version(s) of Java is installed. It then removes all versions, except the most recent version. If the most recent version isn't installed it will install it. Furthermore, the script will copy the deployment.config file to the workstation. This file points the Java installation on the workstation to use settings from a central settings file. This might be useful in a corporate environment. <br />
Please click on "Read more..." to read more :)The script will need administrative privileges to work. Also, the location of the JRE installer file must be a trusted location (in Internet Options). Otherwise the client will get the annoying "Open file security warning" dialog box.<br />
<br />
The script looks somewhat like this:<br />
*----CUT HERE---*<br />
Option Explicit<br />
Dim msiObject, msiProduct, strProdList, strProdInfo, msiProdVersion,appName1, appName2, InstallerPath<br />
Dim CommandShell, cmdline, strDontUninstallThis, boolNewJavaExists, fso, objShell, variable, newfolder, ConfigFile<br />
Const msiInstallStateDefault = 5<br />
    <br />
appName1 = "java"                                           'Application name (or part of name) to search for and uninstall.<br />
appName2 = "j2se"                                           'Name of another application to search for and uninstall (some old java versions are shown in Add/remove programs as j2se)<br />
strDontUninstallThis = "java(tm) 6 update 18"    'Here we put the name of the version that should NOT be uninstalled.<br />
InstallerPath = "\\Servername\sharename\jre-6u18-windows-i586-s.exe"    'Change this to reflect the path where you have saved the JRE installer file.<br />
ConfigFile = "\\servername\sharename\deployment.config"                        'Change this to reflect the path where you have saved the deployment.config file.<br />
boolNewJavaExists = False<br />
<br />
strProdList = ""<br />
Set msiObject = Wscript.CreateObject("WindowsInstaller.Installer")<br />
<br />
For Each msiProduct In msiObject.Products<br />
     If InStr(LCase(msiObject.ProductInfo(msiProduct, "ProductName")), LCase(appName1)) Then                  <br />
	If not (LCase(msiObject.ProductInfo(msiProduct, "ProductName")) = LCase(strDontUninstallThis)) Then<br />
	        set CommandShell = createobject("wscript.shell")<br />
	        cmdline = "msiexec /X " & msiProduct & " /qn"<br />
	        CommandShell.run cmdline, 1, true<br />
	Else<br />
		boolNewJavaExists = True<br />
	End If<br />
     ElseIf InStr(LCase(msiObject.ProductInfo(msiProduct, "ProductName")), LCase(appName2)) Then<br />
	If not (LCase(msiObject.ProductInfo(msiProduct, "ProductName")) = LCase(strDontUninstallThis)) Then<br />
	        set CommandShell = createobject("wscript.shell")<br />
	        cmdline = "msiexec /X " & msiProduct & " /qn"<br />
	        CommandShell.run cmdline, 1, true<br />
	Else<br />
		boolNewJavaExists = True<br />
	End If<br />
	<br />
     End If<br />
Next<br />
<br />
If (boolNewJavaExists = False) Then<br />
	set CommandShell = createobject("wscript.shell")<br />
	cmdline = Chr(34) & InstallerPath & Chr(34) & " /s AgreeToLicense=YES IEXPLORER=1 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0"<br />
	CommandShell.run cmdline, 1, true<br />
End If<br />
<br />
set fso=CreateObject("Scripting.FileSystemObject")<br />
If fso.FileExists(ConfigFile) Then<br />
	If not fso.FolderExists(EnvString("windir") & "\sun\") Then<br />
		newfolder = fso.CreateFolder(EnvString("windir") & "\sun\")<br />
	End IF<br />
	If not fso.FolderExists(EnvString("windir") & "\sun\java\") Then<br />
		newfolder = fso.CreateFolder(EnvString("windir") & "\sun\java\")<br />
	End IF<br />
	If not fso.FolderExists(EnvString("windir") & "\sun\java\deployment\") Then<br />
		newfolder = fso.CreateFolder(EnvString("windir") & "\sun\java\deployment\")<br />
	End IF<br />
	fso.CopyFile ConfigFile, EnvString("windir") & "\sun\java\deployment\"<br />
End If<br />
<br />
Function EnvString(variable)<br />
'This function returns a particular environment variable’s value.<br />
' for example, if you use EnvString("username"), it would return<br />
' the value of %username%.<br />
    set objShell = WScript.CreateObject( "WScript.Shell" )<br />
    variable = "%" & variable & "%"<br />
    EnvString = objShell.ExpandEnvironmentStrings(variable)    <br />
    Set objShell = Nothing    <br />
End Function<br />
*----CUT HERE---*<br />
<br />
In addition to the script you will need the JRE installer, which can be downloaded from <A href="http://www.java.com/getjava/"> Sun's </A> website.<br />
<br />
Also, you will need to create a deployment.config file, which could look somewhat like this:<br />
<br />
*----CUT HERE---*<br />
deployment.system.config=file:\\\\Servername\\sharename\\deployment.properties<br />
deployment.system.config.mandatory=FALSE<br />
*----CUT HERE---*<br />
<br />
Finally you will need a deployment.properties file, which you should save on some server share. The file might look something like this:<br />
<br />
*----CUT HERE---*<br />
deployment.javaws.shortcut=NEVER<br />
deployment.javaws.autodownload=NEVER<br />
deployment.javaws.autodownload.locked<br />
deployment.cache.max.size = 200<br />
*----CUT HERE---*<br />
<br />
You may save all files in the same network share. Just make sure it's readable from the computers. The script can be run locally on each workstation e.g. using some workstation management system. You can also run it remotely e.g. using psexec.exe.]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=20</comments>
 <pubDate>Mon, 1 Feb 2010 02:53:35 -0500</pubDate>
</item><item>
 <title>Monitoring e-mail service availability</title>
 <link>http://jar.yosephine.com/index.php?itemid=18</link>
<description><![CDATA[I just found a bunch of scripts from way back in time. One of them is particularly interesting. It is a script that monitors the availability of the e-mail service. This might be useful for some of you, so I decided to share it here. The script monitors the availability of the e-mail service by sending an e-mail message, and then making sure that the message arrived in the mailbox it was sent to. If the message doesn't arrive within a predefined time, an SMS will be sent using Microsoft's SMS sender program. This means that you need to have a mobile phone connected to your computer, but the script could be modified to start any program if the message didn't arrive on time. I wouldn't recommend sending an e-mail though...<br />
<br />
The script uses w3sockets (socketreg.exe & socket.dll) from http://www.dimac.net. I won't post those files here, but you can download them from <A href="http://www.dimac.net">here</A>.<br />
<br />
Also, the script uses Microsoft's SMS sender for sending the SMS messages using a mobile phone connected to the computer that runs the script. The SMS sender program can be found <A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06a4f997-7f69-4891-8929-37b9041924a2&displaylang=en">here</A>.<br />
<br />
The SMS sender program is kind of problematic. When you send an SMS it will throw a notification on the screen. I've used pskill.exe (part of the pstools, available <A href="http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx">here</A>) to kill the SMS sender program and its notifications.<br />
<br />
And finally, the script itself is shown below...<br />
<br />
'This script sends e-mail using SMTP, and then checks that the messages have arrived in the Excgange server mailbox using POP3.<br />
'The purpose of the script is to monitor SMTP mail flow and alert if there is a problem in the mail flow.<br />
'The script is dependent upon the socket.dll, which should be registered on the server (by running SocketReg.exe).<br />
'The required files should be kept in the same dir as this script, in order to be available.<br />
'This script also utilizes Microsoft's free smssender.exe to send alerts using a mobile phone connected to the computer.<br />
'Also pskill.exe is used to kill the smssender.exe's notification.<br />
<br />
'The following variables may be changed:<br />
arrSMTPServers = array("SERVER1", "SERVER2")				'Put your servers here<br />
intSMTPPort = 25							'Set the port to use for sending SMTP mail<br />
strFromAddr = "youraddress@yourdomain.com"				'Set the sender address for the messages<br />
strToAddr = "destinationaddress@yourdomain.com"				'Set the recipient address for the messages<br />
strPOPServer = "popserver.yourdomain.com"						'Set the POP server<br />
intPOPPort = 110							'Set the POP server port<br />
strSMSSender = "c:\Program files\Microsoft SMS Sender\smssender.exe"	'Path to smssender.exe<br />
strPhoneNumber = "5551234"						'Phone number to send alert messages to<br />
strPSKill = "c:\temp\pskill.exe"					'Path to pskill.exe<br />
strExpectedGreeting = "Microsoft Exchange"               'Expected greeting text of POP server<br />
strPOPUser = "username"                                          'Username for the POP mailbox<br />
strPOPPass = "password"                                       'Password for the POP mailbox<br />
<br />
'Do not change anything below this line!<br />
'---------------------------------------<br />
<br />
Dim arrID() 						'Array, containing the ID's for the messages to send.<br />
On Error Resume Next<br />
arrPath = Split(strSMSSender, "\")<br />
strSMSexe = arrPath(Ubound(arrPath))<br />
<br />
For i=0 to Ubound(arrSMTPServers)<br />
	'Generate ID's for the messages to send:<br />
	ReDim Preserve arrID(i) <br />
	arrID(i) = fGenerateID<br />
	'Send message:<br />
	subSendMail arrSMTPServers(i), intSMTPPort, strFromAddr, strToAddr, arrID(i), arrID(i)<br />
Next<br />
<br />
'Sleep for a while to allow time for the messages to be scanned and delivered:<br />
Wscript.sleep 20000<br />
<br />
For i=0 to Ubound(arrSMTPServers)<br />
	'Read mailbox, and search for our messages:<br />
	If fReadPOPMsgs (arrID(i), strPOPServer, intPOPPort, strExpectedGreeting, strPOPUser, strPOPPass) = 1 Then<br />
		Wscript.echo "Inbound SMTP route through " & arrSMTPServers(i) & " is OK!"<br />
	Else<br />
		Wscript.echo "Inbound SMTP route through " & arrSMTPServers(i) & " is DOWN!"<br />
		Set objShell = WScript.CreateObject("WScript.Shell")<br />
		objShell.Run (Chr(34) & strSMSSender & Chr(34) & " /p:" & strPhoneNumber & " /m:" & Chr(34) & "Inbound SMTP route through " & arrSMTPServers(i) & " is DOWN!" & Chr(34)),0<br />
		wscript.sleep 30000<br />
		objShell.Run (Chr(34) & strPSKill & Chr(34) & " " & strSMSexe)<br />
	End If<br />
Next	<br />
<br />
fDelPOPMsgs strPOPServer, intPOPPort, strExpectedGreeting, strPOPUser, strPOPPass<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
'***************** subSendMail() **********************<br />
Sub subSendMail(server, port, sender, recipient, subject, body)<br />
Set objEmail = CreateObject("CDO.Message")<br />
objEmail.From = sender<br />
objEmail.To = recipient<br />
objEmail.Subject = subject<br />
objEmail.Textbody = body<br />
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2<br />
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = server<br />
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = port<br />
objEmail.Configuration.Fields.Update<br />
objEmail.Send<br />
End Sub<br />
<br />
'***************** fGenerateID() **********************<br />
Function fGenerateID()<br />
Randomize<br />
b = 0<br />
ID = ""<br />
Do while b <= 40<br />
	ID = ID & Int(10 * Rnd)<br />
	b = b + 1<br />
Loop<br />
fGenerateID = ID<br />
End Function<br />
<br />
<br />
<br />
'***************** fReadPOPMsgs() **********************<br />
Function fReadPOPMsgs(identifier, strPOPServer, intPOPPort, strExpectedGreeting, strPOPUser, strPOPPass)<br />
Dim oSocket, iErr, sSocketText<br />
sSocketText = ""<br />
a = 1<br />
strStat = ""<br />
Set oSocket = CreateObject("Socket.TCP")<br />
oSocket.DoTelnetEmulation = True<br />
oSocket.TelnetEmulation = "TTY"<br />
oSocket.Host = strPOPServer & ":" & intPOPPort<br />
On Error Resume Next <br />
oSocket.Open<br />
iErr = Err.Number<br />
 If iErr <> 0 Then <br />
  fReadPOPMsgs = 0<br />
  Exit Function <br />
 End If <br />
sSocketText = oSocket.GetLine<br />
If InStr(sSocketText, strExpectedGreeting) = 0 Then WScript.Echo sSocketText<br />
<br />
oSocket.SendLine "user " & strPOPUser<br />
sSocketText = oSocket.GetLine<br />
If InStr(sSocketText,"OK") = 0 Then WScript.Echo sSocketText<br />
<br />
oSocket.SendLine "pass " & strPOPPass<br />
sSocketText = oSocket.GetLine<br />
If InStr(sSocketText,"User successfully logged on") = 0 Then WScript.Echo sSocketText<br />
<br />
oSocket.SendLine "stat"<br />
sSocketText = oSocket.GetLine<br />
strStat = sSocketText<br />
arrStat = Split(strStat, " ")<br />
<br />
Do while Int(arrStat(1)) >= a<br />
   sSocketText = ""<br />
   oSocket.SendLine "retr " & a<br />
   Do while sSocketText <> "."<br />
	sSocketText = oSocket.GetLine<br />
	If InStr(sSocketText, identifier) <> 0 Then fReadPOPMsgs = 1<br />
	'WScript.Echo sSocketText<br />
   Loop<br />
   a = a + 1<br />
Loop<br />
oSocket.SendLine "quit"<br />
<br />
<br />
<br />
oSocket.Close<br />
On Error GoTo 0<br />
'fReadPOPMsgs = 0<br />
<br />
End Function<br />
<br />
'***************** fDelPOPMsgs() **********************<br />
Function fDelPOPMsgs(strPOPServer, intPOPPort, strExpectedGreeting, strPOPUser, strPOPPass)<br />
Dim oSocket, iErr, sSocketText<br />
sSocketText = ""<br />
a = 1<br />
strStat = ""<br />
Set oSocket = CreateObject("Socket.TCP")<br />
oSocket.DoTelnetEmulation = True<br />
oSocket.TelnetEmulation = "TTY"<br />
oSocket.Host = strPOPServer & ":" & intPOPPort<br />
On Error Resume Next <br />
oSocket.Open<br />
iErr = Err.Number<br />
 If iErr <> 0 Then <br />
  fReadPOPMsgs = 0<br />
  Exit Function <br />
 End If <br />
sSocketText = oSocket.GetLine<br />
If InStr(sSocketText, strExpectedGreeting) = 0 Then WScript.Echo sSocketText<br />
<br />
oSocket.SendLine "user " & strPOPUser <br />
sSocketText = oSocket.GetLine<br />
If InStr(sSocketText,"OK") = 0 Then WScript.Echo sSocketText<br />
<br />
oSocket.SendLine "pass " & strPOPPass <br />
sSocketText = oSocket.GetLine<br />
If InStr(sSocketText,"User successfully logged on") = 0 Then WScript.Echo sSocketText<br />
<br />
oSocket.SendLine "stat"<br />
sSocketText = oSocket.GetLine<br />
strStat = sSocketText<br />
arrStat = Split(strStat, " ")<br />
a=1<br />
Do while Int(arrStat(1)) >= a<br />
   sSocketText = ""<br />
   oSocket.SendLine "dele " & a<br />
   sSocketText = oSocket.GetLine<br />
'   wscript.echo sSocketText<br />
   a = a + 1<br />
Loop<br />
oSocket.SendLine "quit"<br />
<br />
<br />
<br />
oSocket.Close<br />
On Error GoTo 0<br />
fDelPOPMsgs = 0<br />
<br />
End Function]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=18</comments>
 <pubDate>Thu, 10 Sep 2009 07:02:44 -0400</pubDate>
</item><item>
 <title>Ok, they found me...</title>
 <link>http://jar.yosephine.com/index.php?itemid=16</link>
<description><![CDATA[I wondered why the traffic was suddenly up to 2GB per day, until I noticed my blog's comment-function was being misused by mass-posting various spam messages into the comment-field.<br />
<br />
With 6000+ spams I figured it was best to just bulk-erase them all. Sorry for removing all nice comments as well. <br />
<br />
For the time being the comment-section is closed :(]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=16</comments>
 <pubDate>Sun, 26 Jul 2009 18:13:51 -0400</pubDate>
</item><item>
 <title>HTA</title>
 <link>http://jar.yosephine.com/index.php?itemid=14</link>
<description><![CDATA[I've mostly been using vbscripts to accomplish various system administration tasks. It's a good tool for automating tasks. While you can get nice message- and input boxes with vbscript I've been missing a real graphical user interface though. A while ago I stumbled upon something called HTA (HTML Applications), and thought it sounded interesting. I didn't have time to study it any further at the time, though, so I just added the site to my favorites folder, where it's been sitting dormant for some months now. A couple of days ago I found it again and took a closer look, and WOW! That's cool. Microsoft has a really nice little two chapter introduction to this <a href="http://www.microsoft.com/technet/scriptcenter/topics/htas/tutorial1.mspx"><B>here</B></a>. <br />
<br />
I've created a small and simple helpdesk application for our users in just a couple of hours. The hta does some basic diagnostics (Checking if the computer is on the network, checking that e-mail servers are available, checking CPU load, etc.), shows basic computer information (Computer name, make, model, memory, hard drive, serial number etc), and allows the user to send support requests to the support team. The nice thing with this method of sending support requests is that the hta can automatically add some relevant information to the support request (such as computer name and IP address), that the user doesn't necessarily understand to add themselves.<br />
<br />
I may be posting the hta here if someone requests it, and more importantly, if I have the time to tidy it up a bit. For now the application is in English only, but I just might add different languages (Swedish, Finnish, German). ]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=14</comments>
 <pubDate>Fri, 29 May 2009 09:47:13 -0400</pubDate>
</item><item>
 <title>Please find me, Googlebots, crawlers, people, anyone...</title>
 <link>http://jar.yosephine.com/index.php?itemid=12</link>
<description><![CDATA[I'm getting frustrated. My excellent blog isn't getting any hits. I guess this is the problem with a privately owned and hosted blog like this. Maybe I should have started this blog on one of the numerous free blog sites on the Internet.<br />
<br />
Well, anyway I should probably start investigating how I can get some publicity for my fine blog. The only thing is that I don't find that very interesting. <br />
<br />
A quick search on one of the leading web search engines led me to some kind of link exchange program, which can be found here:<br />
SubmitLinksFree.com - the high quality <a href="http://www.submitlinksfree.com">Links Directory</a> for webmasters.<br/><br />
<a href="http://www.addyourlink.org" id="RDA18E5">Add Your Link</a> - Web Directory. Add your link today.<BR><br />
-Sorry, I had to include those links to be allowed to submit my link to the site. Let's see if it helps. I'm expecting to get numerous hits within the next 24 hours ;)]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=12</comments>
 <pubDate>Thu, 28 May 2009 15:00:31 -0400</pubDate>
</item><item>
 <title>Replacing the printer server can be a pain</title>
 <link>http://jar.yosephine.com/index.php?itemid=10</link>
<description><![CDATA[So we had this old Windows printer server that needed to be replaced. The server had about 200 printer queues shared to about a thousand computers. A new printer server was set up and new printer shares were made. At the same time we decided to deploy a new printer naming policy, so the printer queues got new names on the new server. Now the only problem was to replace the printer queue connections on the 1000+ workstations from the old server to the corresponding queues on the new server. As our users haven't got that good computing skills we realized we couldn't just post instructions to the users on how to replace the old queues with the new ones. After some thinking I came up with the idea to use a script to replace the old queues with the new ones on the workstations.<br />
<br />
The script works as follows:<br />
First you need to make a file containing a list of old queues and their corresponding new queues. Let the file be named filename.txt in this example. Here's what filename.txt could look like:<br />
<br />
\\OldServer\OldPrinterQueueName,\\NewServer\NewPrinterQueueName<br />
\\OldServer\AnotherOldQueue,\\NewServer\AnotherNewQueue<br />
\\AnotherOldServer\AThirdQueue,\\AnotherNewServer\AThirdQueue<br />
<br />
As you probably can see, each line comprises an old queue and a new queue, separated by a comma. That's all. You may make the list as long as you want as long as each line contains just this comma-separated pair of printer queues. No comments, no other text is allowed, just the comma-separated pairs of queues, one pair per line.<br />
<br />
Then you need to edit the script and insert the full UNC path of the file you just created. If you named the file "filename.txt", saved it on a share called "ShareName" on a server, named "Server", then you would enter "\\Server\ShareName\FileName.txt" as the value of the strFile variable in the script.<br />
<br />
Finally you should make sure this script runs for each user in your environment. This can be done e.g. by calling it from the logon script. As the script might take some time to run you might want to make sure it runs only once for each user. This, in turn, may be accomplished e.g. by adding a few lines in your users' logon script(s), checking if a certain file exists in the user's profile. If the file exists, the logon script will skip calling the printer change script. If the file doesn't exist the logon script should call the printer change script and create this certain file in the user's profile to avoid that the printer change script is run the next time the user logs on.<br />
<br />
Ok, that's probably all you need to know about the script. Here's the script code. You may use it free of charge as long as I'm given the appropriate credit. You may also change it as you wish, but you may not remove my name from it.<br />
<br />
<br />
' Script that changes the user's printer(s) to other(s) printer(s) according to a csv list of printers.<br />
' The list of printers should contain comma separated printer pairs, one pair at each line, like this:<br />
' \\server1\printer1,\\server2\printer2<br />
' where \\server1\printer1 is the printer that shall be replaced, <br />
' and \\server2\printer2 is the printer that shall replace the beforementioned printer.<br />
' The script can be called from a e.g. the logon script and the script can replace several different printers. <br />
' Just add more lines to the list of printers and the script will go through them all.<br />
' The script also notes which printer is the default printer and sets the replacing printer as default printer.<br />
' Created by Dennis Nyholm 23.7.2008<br />
<br />
'Fill in the filename of the list of printers here:<br />
strFile = "\\servername\sharename\filename.txt"<br />
<br />
Const ForReading = 1<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
Set objTextFile = objFSO.OpenTextFile(strFile, ForReading)<br />
Do Until objTextFile.AtEndOfStream<br />
	strLine = objTextFile.Readline<br />
	arrprt = Split(strLine, ",")<br />
	Sourceprt = arrprt(0)<br />
	Destprt = arrprt(1)<br />
	'Wscript.Echo Sourceprt & " => " & Destprt<br />
	strComputer = "."<br />
	'Set error handling on:<br />
	'On Error Resume Next<br />
	Set objNetwork = CreateObject("Wscript.Network")<br />
<br />
	Set objWMIService = GetObject("winmgmts:" _<br />
	    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")<br />
	Set colInstalledPrinters =  objWMIService.ExecQuery _<br />
	    ("SELECT * FROM Win32_Printer")<br />
	For Each objPrinter in colInstalledPrinters<br />
		'Wscript.Echo "Printer Name: " & objPrinter.Name<br />
		If LCase(objPrinter.Name) = LCase(Sourceprt) Then<br />
			Wscript.Echo objPrinter.Name & " will be replaced by " & Destprt<br />
			'Install replacing printer:<br />
			objNetwork.AddWindowsPrinterConnection Destprt<br />
<br />
			'Check default printer:<br />
			Set WshShell = WScript.CreateObject("WScript.Shell")<br />
			strDefaultPrinter = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")<br />
			arrDefaultPrinter = Split(strDefaultPrinter, ",")<br />
<br />
			'Check if this is the default printer:<br />
			If LCase(arrDefaultPrinter(0)) = LCase(objPrinter.Name) Then<br />
				'Wscript.Echo "Is default printer"<br />
				'Set the printer as default:<br />
				objNetwork.SetDefaultPrinter Destprt<br />
			End If <br />
<br />
			'Remove old printer:<br />
			objNetwork.RemovePrinterConnection Sourceprt<br />
		End If<br />
<br />
	Next<br />
Loop<br />
<br />
]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=10</comments>
 <pubDate>Tue, 26 May 2009 05:49:48 -0400</pubDate>
</item><item>
 <title>Instant VNC session</title>
 <link>http://jar.yosephine.com/index.php?itemid=8</link>
<description><![CDATA[Ever wanted to remotely assist someone with their problem only to find out that the remote help program isn't installed on the remote user's computer. Here's a simple solution for that problem. I call it instant VNC session. A script installs the VNC service onto the remote computer and 'instantly' opens a VNC session to it. This can be handy when Remote Assistance or any other remote help software hasn't been installed on the remote computer, or when the installed program just doesn't work. The beautiful thing with this instant VNC script is that upon disconnect it will clean up after itself. No service or files will be left on the target computer. Obviously you will need to have admin privileges to the remote computer for this to work! (Otherwise it would be an evil H4x0R backdoor thingie...)<br />
Oh, and the password for the VNC session is "secret" (without the quotes). You can (and probably should) change it by editing the instantVNC.vbs script.<br />
<br />
How to use:<br />
<br />
1) Download <a href="http://jar.yosephine.com/stuff/instantvnc.zip"><b>this</b></a> file.<br />
2) Extract the content of the file to any desired folder on your PC.<br />
3) Run the RUNME.BAT file<br />
<br />
The script will ask for some details, such as the name or IP address of the computer you wish to remotely control. After this it will install the VNC service onto the target computer and launch the VNC client that will allow you to view and control the remote computer. This should work on Windows XP. Haven't tested in Vista, but probably won't work there.]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=8</comments>
 <pubDate>Mon, 25 May 2009 11:24:47 -0400</pubDate>
</item><item>
 <title>Finding files on any computer in the Active Directory</title>
 <link>http://jar.yosephine.com/index.php?itemid=5</link>
<description><![CDATA[Have you ever been searching for a file that you know is on one of your computers in the AD, but you fail to remember which computer the file resides on. I've had that problem on several occasions, so one day I made a vbs script that searches through all the computers in the AD for the bugger. It might take some time for this script to find your file, because it searches through the computers one by one. Maybe I'll create a new version sometime that searches for the file on several computers in parallel. The script will remember which computers it wasn't able to search, so switched off computers will be retried. <br />
<br />
There are a number of things that could have been done better in this script. Now you can e.g. only search by exact file name, including extension (e.g. filename.exe) or substitute the file name or extension with wildcards (e.g. filename.* or *.exe). You're welcome to improve the script. If you decide to do so, please post the improved version here for everyone (including me) to enjoy.<br />
<br />
Oh, and all scripts on this site (including this one) may be used by anyone for free, as long as you include the credits in the script code.<br />
<br />
Well, enough babbling. Click on Read More to see the script.'ADFileFind.vbs by Dennis Nyholm (jar@yosephine.com) 16.7.2006<br />
<br />
On Error Resume Next<br />
<br />
Set strDomainName = "yourdomain"<br />
Set strDomainExt = "net"<br />
<br />
If Wscript.Arguments.Count < 1 Then<br />
	Wscript.Echo "Too few arguments!"& Chr(10) & Chr(13) & "Usage: cscript ADfilefind.vbs <filename.ext>"<br />
	Wscript.Quit<br />
End If<br />
<br />
Set ArgObj = Wscript.Arguments<br />
ArrFilename = split(ArgObj(0), ".")<br />
<br />
Wscript.Echo "Filename=" & ArrFilename(0)<br />
Wscript.Echo "Extension=" & ArrFilename(1)<br />
<br />
Const ADS_SCOPE_SUBTREE = 2<br />
Const MBCONVERSION= 1048576<br />
Const ForReading = 1<br />
Const ForWriting = 2<br />
<br />
Set objConnection = CreateObject("ADODB.Connection")<br />
Set objCommand =   CreateObject("ADODB.Command")<br />
objConnection.Provider = "ADsDSOObject"<br />
objConnection.Open "Active Directory Provider"<br />
<br />
Set objCOmmand.ActiveConnection = objConnection<br />
objCommand.CommandText = "Select Name, Location from 'LDAP://DC=" & strDomainName & ",DC=" & strDomainExt & "' Where objectClass='computer'"  <br />
objCommand.Properties("Page Size") = 2000<br />
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE <br />
Set objRecordSet = objCommand.Execute<br />
objRecordSet.MoveFirst<br />
Err.Clear<br />
<br />
Set FSO = CreateObject("Scripting.FileSystemObject")<br />
Set objFile = FSO.CreateTextFile("Workfile.txt", True)<br />
objFile.Close<br />
Set objFile = FSO.OpenTextFile("Workfile.txt", ForWriting)<br />
<br />
<br />
Do Until objRecordSet.EOF<br />
<br />
    objFile.WriteLine objRecordSet.Fields("Name").Value<br />
    objRecordSet.MoveNext<br />
Loop<br />
objFile.Close<br />
<br />
Do<br />
strCompsLeft = 0<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
Set objTextFile = objFSO.OpenTextFile("Workfile.txt", ForReading)<br />
<br />
Set objFSO2 = CreateObject("Scripting.FileSystemObject")<br />
Set objTextFile2 = objFSO2.CreateTextFile("Workfile2.txt", True)<br />
objTextFile2.Close<br />
<br />
Do Until objTextFile.AtEndOfStream<br />
    strComputer = objTextFile.Readline<br />
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")<br />
    If Err.Number = 0 Then<br />
      Wscript.Echo Chr(10) & Chr(13) & strComputer & ": "<br />
      If ArrFilename(0) = "*" Then<br />
        Set colFiles = objWMIService.ExecQuery ("Select * From CIM_DataFile Where Extension = '" & ArrFilename(1) & "'")<br />
      ElseIf ArrFilename(1) = "*" Then<br />
        Set colFiles = objWMIService.ExecQuery ("Select * From CIM_DataFile Where FileName = '" & ArrFilename(0) & "'") <br />
      Else<br />
        Set colFiles = objWMIService.ExecQuery ("Select * From CIM_DataFile Where FileName = '" & ArrFilename(0) & "' and Extension = '" & ArrFilename(1) & "'")<br />
      End If<br />
      For Each objFile in colFiles<br />
        Wscript.Echo objFile.Name<br />
      Next<br />
    Else<br />
      Set objTextFile2 = objFSO2.OpenTextFile("Workfile2.txt", ForWriting)<br />
      objTextFile2.WriteLine strComputer<br />
      obj.TextFile2.Close<br />
      Err.Clear<br />
      strCompsLeft = strCompsLeft + 1<br />
    End If<br />
Loop<br />
objTextFile.Close<br />
<br />
objFSO.DeleteFile("Workfile.txt")<br />
<br />
Set objFile = FSO.CreateTextFile("Workfile.txt", True)<br />
objFile.Close<br />
Set objFile = FSO.OpenTextFile("Workfile.txt", ForWriting)<br />
Set objTextFile2 = objFSO2.OpenTextFile("Workfile2.txt", ForReading)<br />
Do Until objTextFile2.AtEndOfStream<br />
  strTextLine = objTextFile2.Readline<br />
  objFile.WriteLine strTextLine<br />
Loop<br />
objFile.Close<br />
objTextFile2.Close<br />
Set objFSO = CreateObject("Scripting.FileSystemObject")<br />
objFSO.DeleteFile("Workfile2.txt")<br />
Wscript.Echo "Computers left: " & strCompsLeft<br />
Loop]]></description>
 <category>General</category>
<comments>http://jar.yosephine.com/index.php?itemid=5</comments>
 <pubDate>Mon, 25 May 2009 10:20:02 -0400</pubDate>
</item>
  </channel>
</rss>
