[Win32utils-devel] Process.create with logon issue

Daniel Berger djberg96 at gmail.com
Tue Dec 11 09:29:52 EST 2007


Heesob Park wrote:
> Hi,
> 
> 2007/12/11, Daniel Berger <djberg96 at gmail.com <mailto:djberg96 at gmail.com>>:
> 
>     Heesob Park wrote:
> 
>     <snip>
> 
>     I modified what you provided slightly and committed to CVS. I had to
>     make an adjustment to wide_to_multi and multi_to_wide in the
>     Windows::Unicode module so that they return nil if the argument is nil
>     instead of segfaulting.
> 
>     After I made those changes I tried this:
> 
>     struct = Process.create(
>        :app_name         => 'notepad.exe',
>        :creation_flags   => Process::DETACHED_PROCESS,
>        :process_inherit  => false,
>        :thread_inherit   => true,
>        :cwd              => "C:\\",
>        :inherit          => true,
>        :environment      => "SYSTEMROOT=#{ENV['SYSTEMROOT']};PATH=C:\\",
>        :with_logon       => 'some_local_account',
>        :domain           => 'MYDOMAIN',
>        :password         => 'xxxx'
>     )
> 
>     p struct
> 
>  
> The creation flag is not correct.
> It must be combination of following constant:
> 
> CREATE_DEFAULT_ERROR_MODE
> 0x04000000
> 
> CREATE_NEW_CONSOLE
> 0x00000010
>  
> CREATE_NEW_PROCESS_GROUP
> 0x00000200
>  
> CREATE_SEPARATE_WOW_VDM
> 0x00000800
>  
> CREATE_SUSPENDED
> 0x00000004
>  
> CREATE_UNICODE_ENVIRONMENT
> 0x00000400
>  
> EXTENDED_STARTUPINFO_PRESENT
> 0x00080000
>  
> After modify the env to unicode and set create_flag to 
> CREATE_UNICODE_ENVIRONMENT like this
> 
>  
>       if hash['with_logon']
>          logon  = multi_to_wide(hash['with_logon'])
>          domain = multi_to_wide(hash['domain'])
>          app    = multi_to_wide(hash['app_name'])
>          cwd    = multi_to_wide(hash['cwd'])
>          passwd = multi_to_wide(hash['password'])
>          if hash['environment']
>            env = hash['environment'].split(File::PATH_SEPARATOR) << 0.chr
>            env = env.map{|x|multi_to_wide(x)}
>            env = [env.join("\0\0")].pack('p*').unpack('L').first
>          else
>            env = nil
>          end
>          hash['creation_flags'] |= CREATE_UNICODE_ENVIRONMENT  # 0x00000400
> 
>          bool = CreateProcessWithLogonW(
>             logon,                  # User
>             domain,                 # Domain
>             passwd,                 # Password
>             LOGON_WITH_PROFILE,     # Logon flags
>             nil,                    # App name
>             app,                    # Command line
>             hash['creation_flags'], # Creation flags
>             env,                    # Environment
>             cwd,                    # Working directory
>             startinfo,              # Startup Info
>             procinfo                # Process Info
>          )
>    else
> 
> And call like this
>  
> struct = Process.create(
>    :app_name         => 'notepad.exe',
>    :creation_flags   => CREATE_NEW_CONSOLE,  # 0x00000010
>    :process_inherit  => false,
>    :thread_inherit   => true,
>    :cwd              => "C:\\",
>    :inherit          => true,
>    :environment      => "SYSTEMROOT=#{ENV['SYSTEMROOT']};PATH=C:\\",
>    :with_logon       => 'some_local_account',
>    :domain           => 'MYDOMAIN',
>    :password         => 'xxxx'
> )
>  
> work fine for me.

Ok, I made the changes you suggested (in slightly different places, but 
you'll see the changes), but I still couldn't make it work. It could 
just be me, though.

Please check out the latest from CVS and see if it works for you.

Thanks,

Dan

Please checkout the lates


More information about the win32utils-devel mailing list