Windows 10中的模拟-Win Forms应用程序

时间:2018-10-17 09:15:48

标签: windows vb.net winforms windows-7 windows-10

我受命修改旧版获胜表格应用程序

应用程序使用模拟功能通过“ Advapi32”库和别名为“ CreateProcessWithLogonW”的用户来提升用户的权限

然后,被调用的应用程序被授予从system32内的后台打印程序文件夹中删除文件的权限,该应用程序无论如何都无法访问其他文件夹或文件。

这在Windows 7 OS上有效,但是,当用户从Windows 10 OS运行应用程序时,它将拒绝访问。我已经按照以前的开发人员的建议通过设置禁用了UAC,但这产生了相同的结果。

下面是代码段:

    Public Sub RunProgram()
        Try
            Dim siStartup As STARTUPINFO
            Dim piProcess As PROCESS_INFORMATION
            Dim intReturn As Integer

            siStartup.cb = Marshal.SizeOf(siStartup)
            siStartup.dwFlags = 0

            intReturn = CreateProcessWithLogon(username, domain, password, LOGON_WITH_PROFILE, application,
                                               CmdLine, NORMAL_PRIORITY_CLASS Or CREATE_DEFAULT_ERROR_MODE Or
                                               CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, IntPtr.Zero,
                                               IntPtr.Zero, siStartup, piProcess)

            If intReturn = 0 Then
                Throw New System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error())
            End If
            CloseHandle(piProcess.hProcess)
            CloseHandle(piProcess.hThread)
        Catch ex As Exception
            MsgBox(ex.Message & " - " & ex.StackTrace)
        End Try
    End Sub

    Private Declare Unicode Function CreateProcessWithLogon Lib "Advapi32" Alias "CreateProcessWithLogonW" _
        (ByVal lpUsername As String,
         ByVal lpDomain As String,
         ByVal lpPassword As String,
         ByVal dwLogonFlags As Integer,
         ByVal lpApplicationName As String,
         ByVal lpCommandLine As String,
         ByVal dwCreationFlags As Integer,
         ByVal lpEnvironment As System.IntPtr,
         ByVal lpCurrentDirectory As System.IntPtr,
         ByRef lpStartupInfo As STARTUPINFO,
         ByRef lpProcessInfo As PROCESS_INFORMATION) As Integer

    Private Const LOGON_NETCREDENTIALS_ONLY As Integer = &H2
    Private Const NORMAL_PRIORITY_CLASS As Integer = &H20
    Private Const CREATE_DEFAULT_ERROR_MODE As Integer = &H4000000
    Private Const CREATE_NEW_CONSOLE As Integer = &H10
    Private Const CREATE_NEW_PROCESS_GROUP As Integer = &H200
    Private Const LOGON_WITH_PROFILE As Integer = &H1

这是应用程序问题吗?还是Windows 10配置问题?

0 个答案:

没有答案