none
CreateProcessWithLogon的参数问题 RRS feed

  • 问题

  •  

    在winxp下,用户名abc123,密码12345
    我想以这个用户来导入组册表:         c:\windows\regedit.exe   /s   c:\a2.reg
    不要后面参数(   /s   c:\a2.reg)   的时候,可以调用成功,带参数就不行!
    尝试更改   lpCommandLine   也不行.
    另外我想了解   StartInfo.dwFlags   =   0&   的意义,和值的设定


    代码网上复制的.
    下面是没带参数的情况,可以运行成功,环境winxp,vb6.0


        Private   Const   LOGON_WITH_PROFILE   =   &H1&
        Private   Const   LOGON_NETCREDENTIALS_ONLY   =   &H2&
        Private   Const   CREATE_DEFAULT_ERROR_MODE   =   &H4000000
        Private   Const   CREATE_NEW_CONSOLE   =   &H10&
        Private   Const   CREATE_NEW_PROCESS_GROUP   =   &H200&
        Private   Const   CREATE_SEPARATE_WOW_VDM   =   &H800&
        Private   Const   CREATE_SUSPENDED   =   &H4&
        Private   Const   CREATE_UNICODE_ENVIRONMENT   =   &H400&
        Private   Const   ABOVE_NORMAL_PRIORITY_CLASS   =   &H8000&
        Private   Const   BELOW_NORMAL_PRIORITY_CLASS   =   &H4000&
        Private   Const   HIGH_PRIORITY_CLASS   =   &H80&
        Private   Const   IDLE_PRIORITY_CLASS   =   &H40&
        Private   Const   NORMAL_PRIORITY_CLASS   =   &H20&
        Private   Const   REALTIME_PRIORITY_CLASS   =   &H100&
        Private   Type   PROCESS_INFORMATION
        hProcess       As   Long
        hThread       As   Long
        dwProcessId       As   Long
        dwThreadId       As   Long
        End   Type
       
        Private   Type   STARTUPINFO
        cb       As   Long
        lpReserved       As   Long
        lpDesktop       As   Long
        lpTitle       As   Long
        dwX       As   Long
        dwY       As   Long
        dwXSize       As   Long
        dwYSize       As   Long
        dwXCountChars       As   Long
        dwYCountChars       As   Long
        dwFillAttribute       As   Long
        dwFlags       As   Long
        wShowWindow       As   Integer
        cbReserved2       As   Integer
        lpReserved2       As   Byte
        hStdInput       As   Long
        hStdOutput       As   Long
        hStdError       As   Long
        End   Type
       
        Private   Declare   Function   CreateProcessWithLogon   Lib   "Advapi32"   Alias   "CreateProcessWithLogonW"   (ByVal   lpUsername   As   Long,   ByVal   lpDomain   As   Long,   ByVal   lpPassword   As   Long,   ByVal   dwLogonFlags   As   Long,   ByVal   lpApplicationName   As   Long,   ByVal   lpCommandLine   As   Long,   ByVal   dwCreationFlags   As   Long,   ByVal   lpEnvironment   As   Long,   ByVal   lpCurrentDirectory   As   Long,   lpStartupInfo   As   STARTUPINFO,   lpProcessInfo   As   PROCESS_INFORMATION)   As   Long
        Private   Declare   Function   CloseHandle   Lib   "kernel32"   (ByVal   hObject   As   Long)   As   Long
        Private   Sub   Form_Load()
        Dim   lpUsername           As   String,   lpDomain               As   String,   lpPassword               As   String,   lpApplicationName               As   String
        Dim   lpCommandLine           As   String,   lpCurrentDirectory               As   String
        Dim   StartInfo           As   STARTUPINFO,   ProcessInfo               As   PROCESS_INFORMATION
        lpUsername   =   "abc123"
        lpDomain   =   ""
        lpPassword   =   "12345"
        lpApplicationName   =   "c:\windows\regedit.exe"
        lpCommandLine   =   vbNullString               'use       the       same       as       lpApplicationName
        lpCurrentDirectory   =   vbNullString               'use       standard       directory
        StartInfo.cb   =   LenB(StartInfo)               'initialize       structure
        StartInfo.dwFlags   =   0&
        CreateProcessWithLogon   StrPtr(lpUsername),   StrPtr(lpDomain),   StrPtr(lpPassword),   LOGON_WITH_PROFILE,   StrPtr(lpApplicationName),   StrPtr(lpCommandLine),   CREATE_DEFAULT_ERROR_MODE   Or   CREATE_NEW_CONSOLE   Or   CREATE_NEW_PROCESS_GROUP,   ByVal   0&,   StrPtr(lpCurrentDirectory),   StartInfo,   ProcessInfo
        CloseHandle   ProcessInfo.hThread           'close       the       handle       to       the       main       thread,       since       we       don't       use       it
        CloseHandle   ProcessInfo.hProcess           'close       the       handle       to       the       process,       since       we       don't       use       it
        'note       that       closing       the       handles       of       the       main       thread       and       the       process       do       not       terminate       the       process
        'unload       this       application
        'Unload   Me
        End   Sub
    2008年3月1日 12:48

答案

全部回复