Category Archives: .NET

MDT / SyncThing / SnipeIT / API Asset Tracking / Logmein One2Many

I’ve been working on a system to deploy a Master Windows 10 image from MDT to remote sites that have no direct LAN to LAN connection. And also update the Asset Registry at the same time.

MDT / WDS / PXE Server

The MDT / WDS / PXE server is hosted on the HQ LAN, this can only PXE / Litetouch computers on the same LAN.


SyncThing SyncTrayzor makes it possible to share the DeploymentShare which hosts the MDT image with other sites by making a receive only sync on the remote file servers. Setup the DeploymentShare$ on the remote site as you would be on the local LAN and install Deployment Workbench / ADK for completeness.

This gives the Option to use the LiteTouch script to upgrade computers remotely

SnipeIT + API

SnipeIT is a free open source application for asset management – by itself it’s a manual process to enter assets and track them. It does have an API to use however which allows you to automate this process.

Marksman creates a new asset in SnipeIT from the local computer details but cannot update an asset already in the system.

Recon (Created by me but unreleased as of yet) updates the asset details in SnipeIT from the local computer details.

This can be run as a one off, inside the Litetouch process (So when a computer is imaged the asset details are automatically put in to SnipeIT).

Logmein One2Many

Logmein One2Many allows you to run an exe file on all controlled computers, so putting in Marksman and Recon you can update your computer asset database with one click.

Get files in folder and the date in

I’m using this in a project that monitor files on a server folder.
This folder contains any failures that have not processed on the server.
I then display this on a screen with the filename and date to make sure we know what it is and the time it happened.

           Dim files() As String = IO.Directory.GetFiles("X:\Path\To\Files")

            For Each file As String In files

                'Get the date and time modified of this file
                FDate = IO.File.GetLastWriteTime(file)
                'tidy the filename up by removing the .ext of the name
                file = Replace(file, ".ext", "")

                testBox.Text = testBox.Text + file + " " + FDate + Environment.NewLine


Get Current logged on Username – – using advapi32.dll

Note this codes about 6 years old as of 2014 – I’m sure there are better ways of doing this now but this worked at the time and is still live in one of my projects.

I needed to identify the currently logged on user running my application to make an audit file and also show only user options that the logged on user was setup for.

Here’s the code…

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

   Public Function GetUserName() As String
        'Gets currently logged on user - username
        Dim iReturn As Integer
        Dim userName As String
        'put the username in a string limit 50 chars
        userName = New String(CChar(" "), 50)
        'put the length of the username in an Integer iReturn
        iReturn = GetUserName(userName, 50)
        'Tidy up various formatting if required with the replace function like remove the .
        userName = userName.Replace("."c, " "c)
        'Return the username back
        GetUserName = userName.Substring(0, userName.IndexOf(Chr(0)))

    End Function

Scraping webpages and displaying data from it…

When you are working on a project to get data from a webpage but you don’t have access to the back-end database or a API to get any values out.

The workaround I use until something changes is Web scraping.

I have a project with this problem – it’s another VB.NET one.

My Scraping code goes along like this –

'Get the URL / Navigate a browser window too it (this is hidden in my project

'Convert the HTML of the page to a string using the body.outerhtml function
webPage1 = WebBrowser.Document.Body.OuterHtml

'Use the InString function to search for a term in the webPage1 string
If InStr(webPage1, "term to search") <> 0 Then
'get the position of the term to search
            StringSearch = InStr(webPage1, "term to search")
'pick some deatails out of the page using the position + x and capture the next n letters
            ScrapedText = Mid(webPage1, StringSearch + x, n)
'tidy up anything we don't like out of the returned string 
            ScrapedText = ScrapedText.Replace(".", "")
'now we have the scraped text we can use it in our app

        End If

Ta-da – workaround using scraping.

Resizing using smartsize with AxMsRdpClient (Microsoft Terminal Services Control Type Library COM)

I’ve been using the AxMsRdpClient from Microsoft Terminal Services Control Type Library COM (Imported from AxInterop.MSTSCLib) in a project through Visual Studio 2010 using VB.NET

and found the only way to re-size the RDP window via smart size is after making a connection at full size to the RDP and then forcing the size down.

This took me a good hour to work out since I can’t find any examples of this online.

I’m sharing this as it may help someone else looking to work with AxMsRdpClient

Private Sub ConnectScreen1_Click(sender As System.Object, e As System.EventArgs) Handles ConnectScreen1.Click
        ''Check if we are already connected to a RDP session - If so Return 
        If AxMsRdpClient8NotSafeForScripting1.Connected = 1 Then Return

        ''specify the server the RDP is going to connect up
        AxMsRdpClient8NotSafeForScripting1.Server = Settings.Default.RDP1
        AxMsRdpClient8NotSafeForScripting1.Height = 768
        AxMsRdpClient8NotSafeForScripting1.Width = 1024
        AxMsRdpClient8NotSafeForScripting1.ConnectingText = "Connecting..."

        ''enable smart sizing
        AxMsRdpClient8NotSafeForScripting1.AdvancedSettings7.SmartSizing = True

        ''connect up the RDP session
        ''now resize
        AxMsRdpClient8NotSafeForScripting1.Height = 580
        AxMsRdpClient8NotSafeForScripting1.Width = 760
    End Sub