Elevator

EriX920

Respected
I made this program for users to run specific programs with administrative privs. It will copy the cfg into the windows directory and encrypt the administrator password.

Simply run the exe that gets copied into the folder you specify and it should start the app with administrator privileges.

Main form:
Code:
Imports System.IO

Public Class configFrm

    Friend Shared apploc, pass, username, path As String
    Friend Shared authpath As String = "auth.cfg"
    Friend Shared count As Integer
    Friend Shared securepass As New Security.SecureString

    Private Sub configFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        main()
    End Sub

    Shared Sub main()
        Dim sr As StreamReader
        Try
            If File.Exists(authpath) Then
                sr = New StreamReader(authpath)
                While sr.Peek <> -1
                    Dim s As String = sr.ReadLine
                    ' Split string based on spaces
                    Dim words As String() = s.Split(New Char() {"-"c})
                    ' Use For Each loop over words and display them
                    Dim word As String
                    For Each word In words
                        apploc = encryption.Decrypt(words(0), "258fwdjfh2fhwf9jf")
                        If apploc.Contains(My.Application.Info.DirectoryPath) Then
                            apploc = encryption.Decrypt(words(0), "258fwdjfh2fhwf9jf")
                            username = words(1)
                            pass = encryption.Decrypt(words(2), "258fwdjfh2fhwf9jf")
                            For Each c As Char In pass
                                securepass.AppendChar(c)
                            Next
                            Process.Start(apploc, username, securepass, Nothing)
                        End If
                    Next
                End While
                sr.Close()
                configFrm.Close()
            ElseIf Not File.Exists(authpath) Then
                Exit Sub
            End If
        Catch ex As Exception
            sr.Close()
            MessageBox.Show(ex.Message, "Elevator", MessageBoxButtons.OK, MessageBoxIcon.Error)
            configFrm.Close()
        End Try
    End Sub

    Private Sub setBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles setBtn.Click
        Dim dir As String = String.Empty
        Dim sw As StreamWriter
        If passTb.Text = "" Then
            passTb.Width = 273
            invalidPass.SetError(passTb, "You must specify a password!")
            Exit Sub
        End If
        Try
            Dim itemstr As String
            For Each item In fileslv.Items
                Dim lvitem As New ListViewItem
                lvitem = item
                Dim itemName As String = lvitem.Text
                dir = itemName.Remove(itemName.LastIndexOf("\"), itemName.Length - itemName.LastIndexOf("\"))
                sw = New StreamWriter(dir & "\" & authpath, False)
                Try
                    File.Copy("elevatorm.exe", dir & "\" & My.Application.Info.AssemblyName & ".exe", True)
                Catch ex As Exception
                    MsgBox("Unable to copy elevator to the requested directory.")
                End Try
                itemstr = item.ToString.Remove(0, 15)
                sw.WriteLine(encryption.Encrypt(itemstr.Replace("}", ""), "258fwdjfh2fhwf9jf") & "-" & userTb.Text & "-" & encryption.Encrypt(passTb.Text, "258fwdjfh2fhwf9jf"))
                sw.Close()
            Next
            MessageBox.Show("Finished!", "Elevator", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            sw.Close()
            MessageBox.Show(ex.Message, "Elevator", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Exit Sub
        End Try
    End Sub

    Private Sub addfileBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addfileBtn.Click
        ofd.ShowDialog()
        If ofd.CheckFileExists = True Then
            path = ofd.FileName
            fileslv.Items.Add(path)
        End If
    End Sub

    Private Sub removefileBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles removefileBtn.Click
        Dim i As Integer
        For i = 0 To fileslv.Items.Count - 1
            If fileslv.Items(i).Selected = True Then
                fileslv.Items.Item(i).Remove()
            End If
        Next
    End Sub

    Private Sub passTb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles passTb.TextChanged
        If Not passTb.Text = "" Then
            invalidPass.Clear()
            passTb.Width = 288
        End If
    End Sub
End Class
 

Attachments

  • elevator.zip
    134.5 KB · Views: 2
Back
Top