[Win32utils-devel] Process.create with logon issue

Heesob Park phasis at gmail.com
Mon Dec 10 23:45:34 EST 2007


Hi,

2007/12/11, Daniel Berger <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.


> However, I couldn't make this work. I always get a "parameter is
> incorrect" error. I know I've got the right logon and password. The
> domain my local domain, which the Sys::Admin library confirms.
>
> Any ideas? You may want to take a look at multi_to_wide just to make
> sure I didn't break it, btw.
>
> Regards,
>
> Dan



Regards,

Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071211/e1a04f58/attachment-0001.html 


More information about the win32utils-devel mailing list