Categories
Geeky/Programming

Cisco VPN – Launch a Hidden Constant PING Window on Connect

The other day I blogged about getting Cisco VPN to stay connect in Vista. The fix was a constant ping. It is all good but then you have this CMD window open all day in your taskbar, just taking up space, etc.

I decided to workaround it.

I created a .vbs (Visual Basic Script) called pingserver.vbs and put this in it:

Set WshShell = WScript.CreateObject("WScript.Shell")
cmd = "ping servername -t"
Return = WshShell.Run(cmd, 0, True)
set WshShell = Nothing

(replace servername with your name of the server you want to constant ping)

Then in Cisco VPN. Options Menu->Application Launcher. Check "enable" and browse to your VBS. Then when you connect it will run that VBS file, and you will have a hidden constant ping going to your server. Nice..

 

Categories
Geeky/Programming

VBA – Reading a Base64 Element into XML and using as Byte Array

Ok, more VBA

Getting a response back as Base64, but when trying to convert it from XML to binary data just having issues.. coming back as ASCII which converts wacked.

What you need to do:

Dim MyInfo As MSXML2.IXMLDOMNodeList
Set MyInfo = xmlDoc.getElementsByTagName(“MyBase64Element”)
MyInfo .Item(0).DataType = “bin.base64”

Dim image() As Byte
image = MyInfo .Item(0).nodeTypedValue

then you can use it in a byte array and convert to an image or whatever datatype you need.

The key here is overriding the type (probably Variant/String by default) to “bin.base64” and then making sure to use the “nodeTypedValue”

This one threw me for a loop for a little while 🙂

Technorati tags: , , , , , , ,
Categories
Geeky/Programming

MSXML2.IXMLDOMNodeList – Loading XML from files or strings

Again with the VBA, working with MSXML2.IXMLDOMNodeList objects. How do you load XML? Well MSDN shows you how to do it from an XML file..

Loading from an XML File:

Dim MyIXMLDOMNodeListVar As MSXML2.IXMLDOMNodeList
Dim xmlDoc As New MSXML2.DOMDocument30

xmlDoc.Load “c:myxml.xml”

If (xmlDoc.parseError.ErrorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox (“You have error ” & myErr.reason)
Else
   Set MyIXMLDOMNodeListVar = xmlDoc.getElementsByTagName(“MyElement”)
End If

Loading from XML string:

Dim MyIXMLDOMNodeListVar As MSXML2.IXMLDOMNodeList
Dim xmlDoc As New MSXML2.DOMDocument30
Dim myXml As String

myXml = “<MyElement>Steve Rules!</MyElement>”
xmlDoc.loadXML (myXml)

If (xmlDoc.parseError.ErrorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox (“You have error ” & myErr.reason)
Else
   Set MyIXMLDOMNodeListVar = xmlDoc.getElementsByTagName(“MyElement”)
End If

You will notice there isn’t much difference, except when you want to load from a string, you use xmlDoc.loadXml instead of just xmlDoc.Load .. I wish I could have found that in the documentation somewhere (maybe it’s there and I just didn’t look hard enough) 🙂

Technorati tags: , , , , ,
Categories
Geeky/Programming

VBA vs VB.NET – turn bytes into bitmaps

So, recently working on some things, I have noticed the HUGE difference between VBA and VB.NET, specifically with turning bytes into bitmaps.. (assume GiveMeBytes() returns a byte array that is a bitmap)

VB.NET:

Dim image As Byte() = GiveMeBytes()
Dim memStream As MemoryStream = New MemoryStream(image)
Dim bitImage As Bitmap = New Bitmap(System.Drawing.Image.FromStream(memStream))

bitImage.Save(“C:test.bmp”)

 

VBA:

Dim image() As Byte
image = GiveMeBytes()

Dim bitImage

bitImage = FreeFile
Open “c:test.bmp” For Binary Access Write As bitImage
Put #bitImage, , image()
Close #bitImage

Now, maybe there is an easier way in VBA/VB6 to do it, but this is the way I learned way back in the day. I am sure you can do something with the FileSystemObject (I am guessing)..

You notice that the VB.NET snippet mostly deals with converting bytes to MemoryStream to Bitmap, and the saving is 1 line, whereas the VBA is really nothing with converting but mostly deals with saving the file. Can we get the best of both worlds? I am not sure, but I still like the .NET implementation better, it just seems “cleaner” to me, and the VBA just seems “dirty”, but they both do the same thing.. (notice in the VBA I didn’t strongly type the bitImage Dim)

In conclusion…”viva .NET!” 🙂

Technorati tags: , , , , , , , , ,
Categories
Business Intelligence Geeky/Programming Product Reviews SQLServerPedia Syndication

Reporting Services Scripter: Sync Reporting Services Instances and Objects

The other day, I was tasked with moving all objects from one SQL Server Reporting Services instance to another. I know you can move the database itself, but then you run into issues with encryption keys etc. I just wanted to move the objects. I know that pretty much everything in SSRS is extensible, so I knew I could write something to do it, but before I went out and coded it, I Googled first to see if someone else had something. Turns out there is an awesome utility: Reporting Services Scripter. Works like a charm!

Technorati tags: , , ,
Categories
Geeky/Programming Random

Route: Saturday Night Programming after the bars..

OK, I have to admit, this is weak. But, if you want to learn how to create an infinite loop, with one word, this is it. Route.

I happened upon this maybe 5-6 years ago, when we ended up having to set static routes on computers because of some goofy office politics, but anyways..

Create a batch file. Name it route.bat. Edit it, type in the word route. save, exit, and run it. Infinite loop.

image

Fun stuff. Not bad for an after the bar exercise..

Technorati tags: , , , ,
Categories
Geeky/Programming

1729 – Saturday Night Programming before the bars: Natural Numbers…

Ok, so this afternoon I watched the movie “Proof” – really good movie. In the movie, they talk about the number 1729, about how it is the smallest number expressible as the sum of two cubes in two different ways. It also is a natural number – when its digits are added together, produces a sum which, when multiplied by its reversed self, yields the original number.

Just for the helluva it, I decided to write a little program in C# to do this. It would be nice if there was an easier way to reverse strings in .NET, maybe there is and I just don’t know. Anyways, I love how movies can get you into things you never thought you would get into.. now I only wonder what I will code up when I get back from the bars..

using System;
using System.Collections.Generic;
using System.Text;

namespace NaturalNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            // when its digits are added together, produces a sum which,
            // when multiplied by its reversed self, yields the original number:

            for (System.UInt64 i = 1; i < 9223372036854775808; i++)
            {
                string nums = i.ToString();

                System.UInt64 sum = 0;
                System.UInt64 product = 0;

                // get the sum of each digit of the number
                for (int b = 0; b < nums.Length; b++)
                {
                    sum += System.Convert.ToUInt64(nums[b].ToString());
                }

                string nums2 = sum.ToString();

                // reverse the sum
                char[] temp = nums2.ToCharArray();
                Array.Reverse(temp);
                nums2 = new string(temp);

                // multiply the sum times the reversed sum
                product = sum * System.Convert.ToUInt64(nums2);

                // if they equal we hit the jackpot
                if (product == i)
                {
                    Console.WriteLine(i.ToString() + " is a natural number");
                }

                if (i % 10000000 == 0)
                {
                    Console.WriteLine(i.ToString());
                }
            }
        }
    }
}
 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Technorati tags: , , , ,
Categories
Geeky/Programming

ForFiles – Delete files older than X amount of Days

Windows 2003 – ForFiles

FORFILES /P C:MyPath /S /M log*.xml /D -30 /C "cmd /c del @file"

/S – look at subdirectories

log*.xml – that is the file pattern, you could have it be like *.txt for example

/D -30 = files greater than 30 days

/C – thats the command you want to run

this is pretty much a one line command that could replace a ton of vbScripts, batch files, and other apps I have seen over the years to clean up files. Something for every sys admin’s toolbelt.

Categories
Geeky/Programming

IE7 – Adding Default Search Provider Through the Windows Registry

So, IE7 – cool right, new search bar and everything. And you can go here and add new search providers. You can also use what Microsoft gives you and do it this way. But alas, what if you want to add it without user intervention? Remotely over a network maybe? Or you just want to do it programatically the way any good geek would. You hit up the registry of course!

1. Create a GUID – use vs2003 or vs2005, or something
example = {AC854C16-CA1E-43f1-8513-0D2F36C726ED}

2. create a reg file

3. edit contents of reg file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerSearchScopes]
“DefaultScope”=”{AC854C16-CA1E-43f1-8513-0D2F36C726ED}”

[HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerSearchScopes{AC854C16-CA1E-43f1-8513-0D2F36C726ED}]
“DisplayName”=”What you Want as a Display Name”
“URL”=”http://yoursearchurl?params={searchTerms}”

4. run it 🙂

Categories
Geeky/Programming

WMIC in Windows

This is why I love computing, you learn something new all the time. WMIC (Windows Management Instrumentation Command-line tool) is something I have never even heard of until yesterday. It always seems when I am looking for a solution I find something in the blogosphere around the same time, but this is crazy. With this tool, you can query WMI info straight from the command line, this pretty much makes getting info on your machine 1000% times easier, especially from batch files, or programming interfaces. As an example, to go along with my “NumLock Debacle Fixer” in my previous posts, I used this

wmic SystemEnclosure get ChassisTypes

on the command line, and it throws me back a number. With a little research, I found what that means

10 = Laptop
12 = Docked
5 = Pizza Box (wtf??)

Anyways, I tested it and yeah, it gives me the correct info, so in my program, I shell out, get the output back, parse it out, and I have what I need, but the cool thing is, you can query any WMI info from the command line, which opens up a ton of options, especially for sysadmins and network guys. Along with utils in XP like reg.exe, you pretty much can write some powerful scripts/programs without using anything but windows utils. Of course there are API’s for programmers to do these things in code, but sometimes its more headache then it is worth, especially when you want to just write a quick batch file to do something.

What other tools or tricks have you found in xp? (shutdown -i, tasklist /s, etc)