Post to your Twitter Account using VB.net

That’s right guys and gals, you can very easily and quickly post to your twitter account using Visual Basic.net.  The function below is a fully functional VB.net 2008 Twitter Posting function.

Simply call the function below as follows:

PostonTwitter(“username”,”password”,”what i want to post”)

 

Public Sub PostonTwitter(ByVal userName As String, ByVal password As String, ByVal updateMessage As String)
Dim wc As Net.WebClient = New Net.WebClient()
wc.Credentials = New Net.NetworkCredential(userName, password)
Net.ServicePointManager.Expect100Continue = False
Dim updateMessageBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(“status=” + updateMessage)
‘Use UTF8 to get it properly encoded if you use characters like ç ã etc…
wc.UploadData(“http://twitter.com/statuses/update.xml”, updateMessageBytes)
End Sub

Windows Home Server Programming

There is an awful lot of crap to wade through when you want to program a console application with a tab and settings section.

Here is an extremely basic breakdown of what you’ll need before starting to program.

1. Microsoft Visual Studio 2008

2. Microsoft Windows SDK available at:  http://go.microsoft.com/fwlink/?LinkId=94640 (Specifically the ORCA tool)

3. A Windows Home Server… of course.

4. Idea for a project… (here is a link to the sample project the MSDN site stepped me through creating)

5. Lastly the HomeServerExt.dll and Microsoft.HomeServer.SDK.Interop.v1.dll files copied from your WHS c:\program files\Windows Home Server directory.

 

Once you have all of these things, you’ll be ready to program… I think… I’m gotten thru all of the project stuff, created my installer, but I didn’t have the Windows SDK before hand.  I’m downloading/installing it now in order to do the final step of using ORCA to edit the msi file so WHS will recognize it as an Add-In.

For additional references and info on programming for your home server… checkout Microsofts website:  http://msdn.microsoft.com/en-us/library/cc952481.aspx

Restart Notice

Here is a copy-cat program of my NTBackupStatus application. It is a stripped down version where if triggered shoots off an email to me… that’s it. I have it setup in Scheduled Tasks on each of the servers I manage. This task is configured to run only when the system starts up, in other words when the server restarts because they should be on 24×7.

The Premise: To help me monitor unexpected server restarts.

How It Works: This program utilizes a settings ini file which stores smtp information and login info to send the emails.

I’ve uploaded it for everyone to use on their own servers… Have Fun.

As usual, I provide no warranties and no responsibility for anything that goes wrong… However post your comments and I’ll try to help as best I can.

To Install:
Extract the zip file and copy the “HethTools” directory to the root of the C:\ Drive. Then update the RestartNotice.ini file as needed. Lastly, add a scheduled task to run the RestartNotice.exe program at system startup.

Click here to Download Source and Executable

NT Backup Status

So, I manage 4 Windows 2003 Servers for my customers. I have full control and decision making abilities on nearly every aspect of these servers. The biggest problem is my limited budget. Therefore often write my own programs to do various things to help in the daily administration of these systems.

The Premise: To help me monitor their backup solutions I have written NT Backup Status. It is a very simple VS 2008 VB command line application that is triggered via Scheduled Tasks every day at 8am.
I am using NTBackup to archive my customers data. This daily backup task is set to stop no matter what at 7 hours after it starts at 1am. That way my customers are not impacted by a slow unresponsive server during business hours.

How It Works: The first thing this application does is to read in the latest backup log from NTBackup. It then scans the contents for indications of failure and if found triggers an email to me.
This program utilizes a settings ini file which stores smtp information and login info to send the emails as well as the directory where NTBackup saves its log files.

I’ve uploaded it for everyone to use on their own servers… Have Fun.

As usual, I provide no warranties and no responsibility for anything that goes wrong… However post your comments and I’ll try to help as best I can.

To Install:
Extract the zip file and copy the “HethTools” directory to the root of the C:\ Drive. Then update the NTBackupStatus.ini file as needed. Lastly, add a scheduled task to run the NTBackupStatus.exe program at your desired time… typically after NTBackup has finished it’s job.

Click here to Download Source and Executable

Retrieve Username

There comes a time in almost every program when you want to know who is the currently logged in user… here’s a little function to do that…

Declare Function GetUserName Lib “advapi32.dll” Alias _
“GetUserNameA” (ByVal lpBuffer As String, _
ByRef nSize As Integer) As Integer

Public Function retUserName() As String
Dim iReturn As Integer
Dim userName As String
userName = New String(CChar(” “), 50)
iReturn = GetUserName(userName, 50)
retUserName = userName.Substring(0, userName.IndexOf(Chr(0)))
End Function

Recursive File Copier Function

Have you ever had the need for a function to copy every file in a directory… wait no longer… here is a recursive way to copy files:

Sub CopySelectedFiles(ByVal strSourceDirectory As String, ByVal strDestDirectory As String, ByVal strSearchString As String)
  Dim dirInfo As New DirectoryInfo(strSourceDirectory)
  Dim fsInfo As FileSystemInfo

  For Each fsInfo In dirInfo.GetFileSystemInfos
    Dim strDestFileName As String = Path.Combine(strDestDirectory, fsInfo.Name)

    If TypeOf fsInfo Is FileInfo And fsInfo.Name.IndexOfAny(strSearchString) > -1 Then
      File.Copy(fsInfo.FullName, strDestFileName, True) ' 'This will overwrite files that already exist
    Else
      CopySelectedFiles(fsInfo.FullName, strDestFileName, strSearchString) 'we have found a subdirectory
    End If
  Next
End Sub


					

Recursive File Search Code

Below is the first function I’m publishing… It uses my favorite programing feature… recursion. Recursion is a tricky thing to do right. So many loops, so many variables, etc… This function searches for a file and all sub-directories of your root/starter directory.

VB.net Source Code:

Public Function SearchForFile(ByVal strSourceDirectory As String, ByVal strSearchString As String) As String
  On Error Resume Next
  Dim ret As String = ""
  Dim dirInfo As New DirectoryInfo(strSourceDirectory)
  Dim fsInfo As FileSystemInfo

  For Each fsInfo In dirInfo.GetFileSystemInfos
    If TypeOf fsInfo Is FileInfo And _
      fsInfo.Name.IndexOfAny(strSearchString) > -1 Then
      'FOUND IT...
      If fsInfo.Name = strSearchString Then
        'return directory where file is located...
        ret = strSourceDirectory
        Exit For
      End If
    Else
      'recurrsively search this sub-folder...
      ret = SearchForFile(fsInfo.FullName, strSearchString)
      If ret <> "" Then Exit For
    End If
  Next

  If ret <> "" Then If Right(ret, 1) <> "\" Then ret = ret & "\"
  SearchForFile = ret
End Function