Group
Have tried my level best to create a service , using the
createprocessasuser function from the win32::Adminmisc module.All
background checkups , including setting up of desired privileges for the
the account running the service , had been performed.These included (
acting as part of os , replacing primary level token privilege etc ).
The program would work if win32::process::create , function is used ,
everything else remaining the same.A breif of what I am attempting is
listed below.

The goal is to write a service and capture the stdout and stdin issued
by java rmi servers , running on a win32 machine and store them in
files.

The trouble I had faced with the createprocessasuser function , is that
java somehow failed to understand classpath settings.I had even set up
hkey_user default environment settings , using regedt32.The classpath
was even tried both as a system and user environment
variable.Irrespective of what I do the program would startup ODBC
connections and then die down , stating that It could not find the base
class defined for each of the programs.

Could anybody throw light on what is going wrong.The error messages
issued , and the subroutines used are being listed below fo start
with.Is there any way of telling createprocessasuser that this is the
environment it is supposed to use.

starts the executable and stores its std error and out logs in separate
files
#servername used only for logfile naming purposes and has nothing to do
with process creation
#this one generates stdout and stderr as diskfiles but the program would
collapse after startup

sub start_process
{
my($logfilestdout,$logfilestderr,$servername,$executable,
$exact_command) = @_;
my($proc,$exitstatus);
my($inherit_file_handle)=1;
my($pid);
my($working_directory)="$GCS_WORKING_DIR";
my($xstdouthandle,$xstdinhandle,$xstderrhandle);
my($logresponse);

#ALL ENVIRONMENT VARS SEEMS TO BE FINE AT THIS POINT
listvars();
$logresponse=LogAsUser("$SERVICEUSER","$SERVICEPASSWD");
write_log("\nLogging in as $SERVICEUSER WITH $SERVICEPASSWD Connection
Successful? $logresponse\n");

Win32::AdminMisc::GetLogonName();

if ( $servername eq 'ARMI' )
{
$pid = Win32::AdminMisc::CreateProcessAsUser(
                                 $exact_command,
                                 $working_directory,
                                 "Flags"  => DETACHED_PROCESS,
                                 "Show"   => SW_MINIMIZE,
                                 "XSize"  => 640,
                                 "YSize"  => 400,
                                 "X"      => 200,
                                 "Y"      => 175,
                                "XBuffer"=> 80,
                                "YBuffer"=> 175,
                                "Title"  => "\u$SERVICEUSER\'s
$exact_command",
                                "Fill"   => BACKGROUND_BLUE    |
                                            FOREGROUND_RED     |
                                            FOREGROUND_BLUE    |
                                            FOREGROUND_GREEN   |
                                            FOREGROUND_INTENSITY
                                );
                               
    $STATUS=$pid ;

    if ( $pid == 0 )
    {
      write_log("\n$servername creation failure " .
Win32::FormatMessage(Win32::GetLastError()));
      write_log("\nExact command used $exact_command\n");
    }                                      
}
else
{
    open(LOGSTDOUT,">>$logfilestdout") or die $! ;
    open(LOGSTDERR,">>$logfilestderr") or die $! ;

    write_log("\nRunning command\n$exact_command ".timenow()."\n");
    
    $xstdouthandle=Win32API::File::GetOsFHandle(LOGSTDOUT);
    $xstderrhandle=Win32API::File::GetOsFHandle(LOGSTDERR);
    $xstdinhandle=Win32::AdminMisc::GetStdHandle(STD_INPUT_HANDLE);
    $xstdoutscreen=Win32::AdminMisc::GetStdHandle(STD_OUTPUT_HANDLE);

    $pid = Win32::AdminMisc::CreateProcessAsUser(
                                     $exact_command,
                                     $working_directory,
                                     "Flags"  => CREATE_NEW_CONSOLE,
                                     "XSize"  => 640,
                                     "YSize"  => 400,
                                     "X"      => 200,
                                     "Y"      => 175,
                                     "XBuffer"=>  80,
                                     "YBuffer"=> 175,
                                     "Priority" =>
NORMAL_PRIORITY_CLASS,
                                     "Show"   => SW_MINIMIZE,
                                     "Title"  => "Owner $SERVICEUSER
Server $servername",
                                     "Directory" =>
"$working_directory",
                                     "Inherit"   =>  1 , 
                                     "StdOutput" => $xstdoutscreen,
                                     "StdError"  => $xstderrhandle,
                                     "StdInput"  => $xstdinhandle,
                                     "Fill"   => BACKGROUND_BLUE    |
                                                 FOREGROUND_RED     |
                                                 FOREGROUND_BLUE    |
                                                 FOREGROUND_GREEN |
                                                 FOREGROUND_INTENSITY );
    $STATUS=$pid ;
    if ( $pid == 0 )
    {
      write_log("\n$servername creation failure " .
Win32::FormatMessage(Win32::GetLastError()));
    }
}
Win32::AdminMisc::LogoffAsUser;
return $pid;
}


#starts the executable and stores its std error and out logs in separate
files
#servername used only for logfile naming purposes and has nothing to do
with process creation
#this function does not redirect file , geenrates console window for all
the processes
#WHATEVER I DO I COULD NOT REDIRECT STDOUT TO FILES USING THIS APPROACH
#but the program started up
sub xstart_process
{
my($logfilestdout,$logfilestderr,$servername,$executable,
$exact_command) = @_;
my($proc,$exitstatus);
my($inherit_file_handle)=1;
my($pid);
my($line);
my($flag)=CREATE_NEW_CONSOLE;
my($processid);
my($working_directory)="$GCS_WORKING_DIR";
my($xstdouthandle,$xstdinhandle,$xstderrhandle,$xstdoutscreen);

    open(LOGSTDOUT,">>$logfilestdout") or die $! ;
    open(LOGSTDERR,">>$logfilestderr") or die $! ;

    write_log("\nRunning command\n$exact_command ".timenow()."\n");
    
    $xstdouthandle=Win32API::File::GetOsFHandle(LOGSTDOUT);
    $xstderrhandle=Win32API::File::GetOsFHandle(LOGSTDERR);
    write_log("Pushing $xstdouthandle and $xstderrhandle into stack for
server $servername\n");
    push(@WIN32HANDLES,$xstdouthandle);
    push(@WIN32HANDLES,$xstderrhandle);

    $xstdinhandle=Win32::AdminMisc::GetStdHandle(STD_INPUT_HANDLE);

    $xstdoutscreen=Win32::AdminMisc::GetStdHandle(STD_OUTPUT_HANDLE);
    $xstderrscreen=Win32::AdminMisc::GetStdHandle(STD_ERROR_HANDLE);

    #redirect stdout and stderr the tricky way
    open STDOUT ,">&=".$xstdouthandle;
    open STDERR ,">&=".$xstderrhandle;

    #unbuffer stderr and stdout
    select ((select(STDERR),$| =1)[0]);
    select ((select(STDOUT),$| =1)[0]);
$line="\nRunning $exact_command time is :".timenow()."  \n";
write_log("$line");
$pid=Win32::Process::Create($proc
                           ,$executable
                           ,$exact_command
                           ,$inherit_file_handle
                           ,$flag
                           ,$working_directory
                           );

   #reassign stdinput and output as the original
 #redirect stdout and stderr the tricky way
    open STDOUT ,">&=".$xstdoutscreen;
    open STDERR ,">&=".$xstderrscreen;

$STATUS=$pid ;

if ( $pid )
{
  $processid = $proc->GetProcessID();
  $line ="Process id created for $servername pid $processid\n";
  write_log("$line");
}
else
{
$line="$servername creation failure " .
Win32::FormatMessage(Win32::GetLastError());
write_log("$line");
}

$rmidefinitions{$servername}{PROCESSOBJ}=$proc;
return $processid;
}

#####################SAMPLE
OUTPUT#####################################################

setting MAX_POOLED_CONNECTIONS to be 8

         Creating DBConnection 0 for
jdbc:oracle:thin:@CFS-GCSINT01.CFSISP:1521:GCSINT01 ...  Created
DBConnection 0
         Creating DBConnection 1 for
jdbc:oracle:thin:@CFS-GCSINT01.CFSISP:1521:GCSINT01 ...  Created
DBConnection 1
         Creating DBConnection 2 for
jdbc:oracle:thin:@CFS-GCSINT01.CFSISP:1521:GCSINT01 ...  Created
DBConnection 2
         Creating DBConnection 3 for
jdbc:oracle:thin:@CFS-GCSINT01.CFSISP:1521:GCSINT01 ...  Created
DBConnection 3
         Creating DBConnection 4 for
jdbc:oracle:thin:@CFS-GCSINT01.CFSISP:1521:GCSINT01 ...  Created
DBConnection 4
         Creating DBConnection 5 for
jdbc:oracle:thin:@CFS-GCSINT01.CFSISP:1521:GCSINT01 ...  Created
DBConnection 5
         Creating DBConnection 6 for
jdbc:oracle:thin:@CFS-GCSINT01.CFSISP:1521:GCSINT01 ...  Created
DBConnection 6
         Creating DBConnection 7 for
jdbc:oracle:thin:@CFS-GCSINT01.CFSISP:1521:GCSINT01 ...  Created
DBConnection 7
DBConnectionPool Size: 8
Database Connection Pool initialised successfully!
Adapter Thread Pool initialised successfully!
Trouble: java.rmi.ServerException: Server RemoteException; nested
exception is: 
        java.rmi.UnmarshalException: error unmarshalling arguments;
nested exception is: 
        java.lang.ClassNotFoundException:
com.compaq.cfs.gcsp.mqseries.MQRMIImpl_Stub
         Destroying DBConnection 0 ...  [DONE]
         Destroying DBConnection 1 ...  [DONE]
         Destroying DBConnection 2 ...  [DONE]
         Destroying DBConnection 3 ...  [DONE]
         Destroying DBConnection 4 ...  [DONE]
         Destroying DBConnection 5 ...  [DONE]
         Destroying DBConnection 6 ...  [DONE]
         Destroying DBConnection 7 ...  [DONE]



The actual listing being too long , I have restricted the code only to
these two functions which are under test.
Any clue , would be highly appreciated.


Thanks
c.kannan
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to