[Win32utils-devel] Process.create with logon issue

Daniel Berger djberg96 at gmail.com
Mon Dec 10 22:41:43 EST 2007


Heesob Park wrote:

<snip>

>      > BTW, how about your thought about supporting Process.create as
>      > a different user with CreateProcessWithLoginW API ?
> 
>     I think it's a good idea. Let's add a "with_logon" option as well. If
>     set, it will call CreateProcessWithLoginW behind the scenes.
> 
>  
> Here is the snippet for CreateProcessWithLogonW
>  
>  if hash['user'].nil?
>        bool = CreateProcess(
>           nil,                    # App name
>           hash['app_name'],       # Command line
>           process_security,       # Process attributes
>           thread_security,        # Thread attributes
>           hash['inherit'],        # Inherit handles?
>           hash['creation_flags'], # Creation flags
>           env,                    # Environment
>           hash['cwd'],            # Working directory
>           startinfo,              # Startup Info
>           procinfo                # Process Info
>        )
>  else     
>        logon_flags = 0x1          # LOGON_WITH_PROFILE
>        bool = CreateProcessWithLogonW(
>           multi_to_wide(hash['user']),     # User name
>           multi_to_wide(hash['domain']),   # Domain name
>           multi_to_wide(hash['password']), # Password
>           logon_flags,               # Logon flags     
>           nil,                         # App name
>           multi_to_wide(hash['app_name']), # Command line
>           hash['creation_flags'],    # Creation flags
>           env,                       # Environment
>           multi_to_wide(hash['cwd']),      # Working directory
>           startinfo,                 # Startup Info
>           procinfo                   # Process Info
>        )
>       
>  end     
>  
> CreateProcessWithLogonW is defined as
> API.new('CreateProcessWithLogonW', 'PPPLPPLLPPP', 'B', 'advapi32')
> and called like this
> x = Process.create(:app_name => "notepad",:user=>'user',:password=>'pass')

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

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


More information about the win32utils-devel mailing list