[Win32utils-devel] Fwd: win32/process problem

Heesob Park phasis at gmail.com
Sat Dec 8 21:44:06 EST 2007


2007/12/7, Daniel Berger <djberg96 at gmail.com>:
>
> Heesob Park wrote:
> > Hi,
> >
> > 2007/12/7, Berger, Daniel <Daniel.Berger at qwest.com
> > <mailto:Daniel.Berger at qwest.com>>:
> >
> >      > -----Original Message-----
> >      > From: win32utils-devel-bounces at rubyforge.org
> >     <mailto:win32utils-devel-bounces at rubyforge.org>
> >      > [mailto:win32utils-devel-bounces at rubyforge.org
> >     <mailto:win32utils-devel-bounces at rubyforge.org>] On Behalf Of
> >      > Daniel Berger
> >      > Sent: Thursday, December 06, 2007 5:18 AM
> >      > To: Development and ideas for win32utils projects
> >      > Subject: Re: [Win32utils-devel] Fwd: win32/process problem
> >      >
> >      > Heesob Park wrote:
> >      >
> >      > <snip>
> >      >
> >      > > Though it is doubtful whether this is the cause or not,
> >      > Insert flowing
> >      > > two lines before ProcessInfo.new (line #409 of
> >      > > process.rb) might be helpful.
> >      > >
> >      > >       CloseHandle(procinfo[8,4].unpack('L').first)
> >      > >       CloseHandle(procinfo[12,4].unpack('L').first)
> >      >
> >      > I'm somewhat afraid to do that, because I can't be sure other
> >      > people aren't using the process handle afterwards.
> >      >
> >      > At the very least I should document that, however. Hmm, let
> >      > me mull it over.
> >
> >     Ok, what if we add a "close_handles" option to Process.create? If
> set to
> >     true (the default), we'll close the handles automatically before
> >     returning from the method. Users could explicitly set it to false if
> >     they want to keep the handles open.
> >
> >     Seem reasonable?
> >
> >
> > Yes, it seems reasonable.
> >
> > 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')

Regards,
Park Heeosb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/win32utils-devel/attachments/20071209/42ad8bef/attachment.html 


More information about the win32utils-devel mailing list