Showing posts with label vb.net 2010. Show all posts
Showing posts with label vb.net 2010. Show all posts

Wednesday, January 11, 2012



Runas Touch Screen Application
















Purpose:
One of the problems I had at work was the ability to run an application as a different user on a touch screen computer. So I wrote an application that dynamically creates buttons based on what it reads from a text file called paths.txt. This program does support arguments and should be able to figure out how to break up the path to find them.

To install just extract the application and paths.txt to a folder and runas away.

Requirements:
.net 4 framework
osk.exe in the usual place if you want to use the onscreen keyboard

TODO:
Add some more error checking with reading the text file
Clean code
Maybe allow this to work with domain user if someone wants.



Paths.txt 

name,path
------------------------------------------------------------------------------
Add\Remove Programs,rundll32.exe shell32.dll,Control_RunDLL Appwiz.cpl
Command Prompt,C:\Windows\System32\cmd.exe
Datetime,rundll32.exe shell32.dll,Control_RunDLL TimeDate.cpl
Display Properties,rundll32.exe shell32.dll,Control_RunDLL Desk.cpl
Notepad,C:\Windows\Notepad.exe
System Properties,rundll32.exe shell32.dll,Control_RunDLL Sysdm.cpl
Taskmgr,taskmgr
Control Panel,rundll32.exe shell32.dll,Control_RunDLL
------------------------------------------------------------------------------

Download Link: 
RunasUserTS.zip

Source code:
Leave a message and I will work on uploading the source

Tuesday, November 22, 2011


This is an example of a vb.net 2010 console application i wrote to send emails off an open relay.


Imports System.Net.Mail

Module Module1

    Sub Main()
        'Arguments
        Dim inputArgumentEmailto As String = "/emailto="
        Dim inputArgumentSubject As String = "/subject="
        Dim inputArgumentSMTP As String = "/smtp="
        Dim inputArgumentBody As String = "/body="
        Dim inputArgumentEmailFrom As String = "/emailfrom="
        Dim inputArgumentQuestion As String = "/?"

        '  Dim inputQuestion As String = ""
        Dim inputEmailto As String = ""
        Dim inputSubject As String = ""
        Dim inputSMTP As String = ""
        Dim inputBody As String = ""
        Dim inputEmailFrom As String = ""

        Dim strTestArgs As Boolean
     
     

        For Each s As String In My.Application.CommandLineArgs

            If s.ToLower.StartsWith(inputArgumentQuestion) Then
                ' if /? is an argument then post help

                Console.WriteLine("Email Application")
                Console.WriteLine("Created by Tony Unger 11/22/2011")
                Console.WriteLine("Ver. 1.0")
                Console.WriteLine("This requires an open relay")
                Console.WriteLine("------------------------------")
                Console.WriteLine("Parameters")
                Console.WriteLine("")
                Console.WriteLine("/emailto=")
                Console.WriteLine("/subject=")
                Console.WriteLine("/smtp=")
                Console.WriteLine("/body=")
                Console.WriteLine("/emailfrom=")
                Console.WriteLine("")
                Console.WriteLine("Example:")
                Console.WriteLine("/emailto=toTony@asdf.com")
                Console.WriteLine("/subject=**Alert")
                Console.WriteLine("/smtp=192.168.1.1")
                Console.WriteLine("/emailfrom=FromTony@asdf.com")
                Console.WriteLine("/body=body")
                Console.WriteLine(" ""/body=This is an alert"" ")

                Exit Sub

            End If

            'Sets arg to string values
            If s.ToLower.StartsWith(inputArgumentEmailto) Then
                inputEmailto = s.Remove(0, inputArgumentEmailto.Length)
            End If

            If s.ToLower.StartsWith(inputArgumentSubject) Then
                inputSubject = s.Remove(0, inputArgumentSubject.Length)
            End If

            If s.ToLower.StartsWith(inputArgumentSMTP) Then
                inputSMTP = s.Remove(0, inputArgumentSMTP.Length)
            End If

            If s.ToLower.StartsWith(inputArgumentBody) Then
                inputBody = s.Remove(0, inputArgumentBody.Length)
            End If

            If s.ToLower.StartsWith(inputArgumentEmailFrom) Then
                inputEmailFrom = s.Remove(0, inputArgumentEmailFrom.Length)
            End If

        Next

        'Checks if all args are there
        If inputEmailto = "" Then
            Console.WriteLine("/emailto= is required")
            strTestArgs = True
        End If
        If inputSubject = "" Then
            Console.WriteLine("/subject= is required")
            strTestArgs = True
        End If
        If inputSMTP = "" Then
            Console.WriteLine("/smtp= is required")
            strTestArgs = True
        End If
        If inputBody = "" Then
            Console.WriteLine("/body= is required")
            strTestArgs = True
        End If
        If inputEmailFrom = "" Then
            Console.WriteLine("/emailfrom= is required")
            strTestArgs = True
        End If


        ' If any args are missing exit sub
        If strTestArgs = True Then
            Exit Sub
        End If
        'Email
        EmailtoSupport(inputEmailto, inputSubject, inputSMTP, inputBody, inputEmailFrom)
    End Sub

    Public Sub EmailtoSupport(inputEmailto As String, inputSubject As String, inputSMTP As String, inputBody As String, inputEmailFrom As String)


        Try
            Dim Mail As New MailMessage
            Mail.Subject = inputSubject
            Mail.To.Add(inputEmailto)
            Mail.From = New MailAddress(inputEmailFrom)
            Mail.Body = inputBody

            Dim SMTP As New SmtpClient(inputSMTP)
            SMTP.Port = "25"
            SMTP.Send(Mail)
            Console.WriteLine("Email Sent!")

        Catch ex As Exception
            If ex.Message.ToString = "Failure sending mail." Then
                Console.WriteLine("There was a failure sending the email.")
                Console.WriteLine("check your smtp address")
                Console.WriteLine("This program will only use port 25")
            Else
                Console.WriteLine(ex.Message.ToString)
            End If

        End Try
    End Sub

End Module

Powershell: Microsoft Graph to add new roles to application registration

PowerShell Script Bulk add new roles to application registration in azure. Update $roles with ,Us...