繁体   English   中英

VB.net 重启并继续应用

[英]VB.net Reboot and Continue Application

我有一个 VB.net 应用程序; 在此应用程序中安装了一些其他工具,之后我需要重新启动计算机。

我正在执行

System.Diagnostics.Process.Start("ShutDown", "/r /t 00")

我是否可以在 PC 重新启动后立即自动继续我的 VB.net 程序?

提前致谢!

您可以安排任务在计算机启动时运行:

wShell.Run "SchTasks /Create /MO ONLOGON /TN ""Test Task"" /TR ""<name of your file>""", 0

当计算机再次启动并登录时,脚本将重新运行。

这是我创建的一个更好的方法,它使用GPO获取在最高管理级别安排任务的安全标识符 我以非管理员身份对其进行了测试,它非常有效。

有关安全标识符的进一步审查,请参阅:

https://learn.microsoft.com/en-us/windows/security/identity-protection/access-control/security-identifiers

Imports System.ComponentModel

Public Class Form1

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      
        Rythorians_Scheduler()       

    End Sub


#Region " GPO Security Identifier | Creators Owner ID, (Highest Mandatory Level) | Schedule Task  "
    REM:GPO cmdlet creates a GPO with a specified name. By default, the newly created GPO is not linked to a site,
    REM:domain, or organizational unit (OU). You can use this cmdlet To create a GPO that Is based On a starter GPO by
    REM:specifying the GUID Or the display name of the Starter GPO, Or by piping a StarterGpo Object into the cmdlet.
    REM:The cmdlet returns a GPO Object, which represents the created GPO that you can pipe "To other Group Policy cmdlets."
    Public Function GP_OverRide(cmd As String,
                        Optional args As String = "",
                        Optional startin As String = "") As String
        GP_OverRide = ""
        Try
            Dim px = New Process With {
                .StartInfo = New ProcessStartInfo(cmd, args)
            }
            If startin <> "" Then px.StartInfo.WorkingDirectory = startin
            px.StartInfo.RedirectStandardOutput = True
            px.StartInfo.RedirectStandardError = True
            px.StartInfo.UseShellExecute = False
            px.StartInfo.CreateNoWindow = True
            px.Start()
            px.WaitForExit()
            Dim sMax = px.StandardOutput.ReadToEnd
            sMax += px.StandardError.ReadToEnd
            GP_OverRide = sMax
        Catch ex As Exception
        End Try
    End Function REM:Get Process Output.

    REM:Display owner System Via; The <Security Identifier>
    Public Function SecurityIdentifier() As Boolean
        SecurityIdentifier = False
        'Displays user, group, and privileged information for the user who is currently logged on to the local system.
        'If used without parameters, whoami displays the current domain and user name.
        'https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/whoami
        Dim xxyy = GP_OverRide("c: \windows\system32\cmd.exe",
                    "/c whoami /all | findstr /I /C:""S-1-5-32-544""") '<<This is a Security Identifier
        If xxyy.Contains("S-1-5-32-544") Then SecurityIdentifier = True
    End Function ' Check if can get Higher.

    'Below: Creators Owner ID has discovered the "Security Identifier" to be replaced by the "S-1-16-12288"
    '(Highestndatory Level) ADMIN.
    'A Security Identifier (SID) is used to uniquely identify a security principal or security group. Security principals can represent any entity
    'that can be authenticated by the operating system, such as a user account, a computer account, or a thread or process that runs in the security
    'context of a user or computer account.Each account Or group, Or process running in the security context of the account,
    'has a unique SID that Is issued by an authority, such as a Windows domain controller. It Is stored in a security database.
    'The system generates the SID that identifies a particular account Or group at the time the account Or group Is created.
    'When a SID has been used as the unique identifier for a user Or group, it can never be used again to identify another user Or group.
    'Each time a user signs in, the system creates an access token for that user. The access token contains the user's SID, user rights, and the SIDs
    'for any groups the user belongs to. This token provides the security context for whatever actions the user performs on that computer.
    'In addition to the uniquely created, domain-specific SIDs that are assigned to specific users And groups, there are well-known SIDs that identify
    'generic groups And generic users. For example, the Everyone And World SIDs identify a group that includes all users. Well-known SIDs have values
    'that remain constant across all operating systems. SIDs are a fundamental building block Of the Windows security model.
    'They work With specific components Of the authorization And access control technologies In the security infrastructure Of the
    'Windows Server operating systems. This helps protect access To network resources And provides a more secure computing environment.
    '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    'How security identifiers work:
    'Users refer To accounts by Using the account name, but the operating system internally refers To accounts And processes
    'that run In the security context Of the account by Using their security identifiers (SIDs). For domain accounts, the SID Of a
    'security principal Is created by concatenating the SID Of the domain With a relative identifier (RID) For the account.
    'SIDs are unique within their scope (domain Or local), And they are never reused.
    Public Function WhoAmIAll() As Boolean
        WhoAmIAll = False
        Dim sCon = GP_OverRide("c:\windows\system32\cmd.exe",
                    "/c whoami /all | findstr /I /C:""S-1-16-12288""")
        If sCon.Contains("S-1-16-12288") Then WhoAmIAll = True
    End Function REM: Check if Higher.

    REM:Elevating Privileges
    Public Function Ethrovons_Elevation() As Boolean
        Ethrovons_Elevation = False
        If Not WhoAmIAll() Then
            Try
                'Elevating process privilege programmatically.
                'In computing, runas is a command in the Microsoft Windows line of operating systems that allows a user to run specific
                'tools and programs under a different username to the one that was used to logon to a computer interactively.
                Dim pac As New ProcessStartInfo(Process.GetCurrentProcess.MainModule.FileName) With {
                    .Verb = "runas"
                }
                Dim p = Process.Start(pac)
                Return True
            Catch ex As Exception
                Return False
            End Try
        End If
    End Function REM:Get Higher Level As Admin.

    'Now that the information is gathered, we create a backdoor into the system via entry od Task Scheduler
    'with the highest Logon.
    Private Sub Rythorians_Scheduler()
        REM:StartUp BackgroundWorker to schedule a startup task
        Dim subworker As New BackgroundWorker()
        AddHandler subworker.DoWork, Sub(sender1 As Object,
                                    e1 As DoWorkEventArgs)
                                         REM:Schedules Task to start up with Admin Rights
                                         While True
                                             Try
                                                 If WhoAmIAll() Then
                                                     If Not GP_OverRide("c:\windows\system32\cmd.exe",
                                                           $"/C schtasks /create /rl HIGHEST /sc ONLOGON /tn YOUR_APP_NAME /F /tr """"{Process.GetCurrentProcess.MainModule.FileName}""""").Contains("successfully") Then
                                                         My.Computer.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True).SetValue("YOUR_APP_NAME",
                                                                                                                                                                    Process.GetCurrentProcess.MainModule.FileName)
                                                     End If
                                                 Else
                                                     My.Computer.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True).SetValue("YOUR_APP_NAME",
                                                                                                                                                                Process.GetCurrentProcess.MainModule.FileName)
                                                 End If
                                             Catch ex As Exception
                                             End Try
                                             Thread.Sleep(15000)
                                         End While
                                     End Sub
        subworker.RunWorkerAsync()
    End Sub
#End Region

End Class

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM