displeaser has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I'm having what is probably quite a silly question and havnt had much luck in finding a solution that works so I thought someone here might know where to look. Basically my problem is that when starting a process from a win32 perl service I cannot see the window of the process I created.

Using the perl dev kit I have created a service which as part of its operation is ment to open up an internet explorer window. This all works fine, except the Internet explorer window (when called from the service) dosnt appear! You can see that it was sucessfully started and can see it in the task manager but it's like the window is hidden. I've tried to look at system, exec and spawn commands, Win32::Process, Win32::SetChildShowWindow and AdminMisc::CreateProcessAsUser to display my Internet explorer window but to no avail - I havnt much experience with process's in perl so it could well be just my lack of understanding.

This is currently the line I use within the service to call Internet explorer:

my $prog="C://Program Files//Internet Explorer//iexplore.exe"; my site="http://www.website.html"; Win32::Process::Create($ProcessObj,"$prog"," site",0,NORMAL_PRIORITY_C +LASS,".");

I know it's probably something I'm been very blind too so apologies in advance.
I'm using perl v5.8.0, win 2000 pro+sp4 and version 5.3.0 of the dev kit (will be upgrading soon if I can get managment to pay :-)

Cheers and thanks for any help,
J

Replies are listed 'Best First'.
Re: Starting a process from a win32 perl service
by BrowserUk (Patriarch) on Feb 09, 2005 at 11:03 UTC

    Just a guess, but you may find that you have to check the "Allow service to interact with desktop" checkbox on the "Log On" tab of the service's "Properties" dialog--via Start->Settings->Control Panel->Adminastrative Tools->Services.

    Alternatively, if the service doesn't need to retain links with IE after it is started, you may be able to set a combination of flags in the dwCreationFlags parameter (see Process creation flags) that will allow the window to become visible. In particular, CREATE_NEW_PROCESS_GROUP may have the desired effect.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
      Hi,
      cheers for the reply.

      I'm running the service under a particular user account and not the system account so you don't get the option.

      Hmm, I'll try give that a go (fingers crossed). Thanks for that.

      j
        Hi again,
        I've been able to get it to work under the system account & allow interactive desktop. Though I don't see why it won't work when setup under a specific user account (my prefered way of doing it). I even tried playing with the service "type" (setting it to 256) in the registry trying to force it to be interactive but that didnt work either. Possably an NT quirk (or security feature ;-)
        Ah well, it's working now anyways.

        Thanks for the suggestions and help.

        J
Re: Starting a process from a win32 perl service
by m-rau (Scribe) on Feb 09, 2005 at 10:38 UTC
    First, it must be $site, not site. Next. You must use backslaches with $prog,. Finally, if the program call itself includes the executable without the path, it works.
    #!/usr/bin/perl use Win32::Process; my $prog="C:\\Programme\\Internet Explorer\\iexplore.exe"; my $site="http://www.gmx.de"; Win32::Process::Create($ProcessObj,$prog,'iexplore "' . $site . '"', 0 +, NORMAL_PRIORITY_CLASS, ".");
    Check the Task Manager to see, if the iexplorer did start! See the Win32::Process pod, too:
    sub ErrorReport{ print Win32::FormatMessage( Win32::GetLastError() ); } Win32::Process::Create($ProcessObj, "D:\\winnt35\\system32\\notepad.exe", "notepad temp.txt", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); $ProcessObj->Suspend(); $ProcessObj->Resume(); $ProcessObj->Wait(INFINITE);
      Hi,
      thanks for getting back to me.

      my problem is that I can sucessfully create the iexplore process, it is visable from the task manager, I just cant visably see it, which I would like to.

      When taking the code to call Internet explorer and put it into a basic command line script (as opposed to a service) it works fine.

      I think the problem lies in and around the fact that as the service has not got an active/displayed window, I think this is "inherited" to process's created from it, hence my Internet explorer window is running but just has no window visable...argh.
      I think all I need is some way to tell the process that it's window should be visable. I tried using Win32::SetChildShowWindow to display the window but didnt get anywhere (i can post code if needed)
      jd
        Code would be helpful.
Re: Starting a process from a win32 perl service
by olivierp (Hermit) on Feb 09, 2005 at 10:40 UTC
    Is your Service "Allowed to Interact with the Desktop" ?
    HTH
    --
    Olivier
      Hi Oliver,
      Thanks for getting back to me.

      I've setup the service to run under a particular users account so don't have the option for setting "interact with the desktop". The user is a member of the administrators group and there is nothing relevant appearing in the event logs.

      thanks,
      J