Running a script in the system account

2006-03-18 Thread Jim Hill
Hi all

My mta, Mailtraq http://www.mailtraq.com/, contains a custom
active-x control which can be accessed only when it is running as
an application, not as a service. If Mailtraq is started as a
service, its normal mode, the active-x control can't be instanced
in perl or javascript ...

| test.js
| var mailtraq = new ActiveXObject(Mailtraq.Control);
| WScript.Echo(mailtraq.Config.UserCount);

| c:\scripts cscript test.js
| Microsoft (R) Windows Script Host Version 5.6
| Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
|
| c:\scripts\test.js(2, 1) Microsoft JScript runtime error: Automation server 
can't create object

We, the Mailtraq developer and I, are assuming that this is a
permissions problems but we can't get to the bottom of it. If
anyone has encountered similar problems, we'd appreciate some
pointers in the right direction. 

Scripts, both perl and javascript, can access the control if they
are run from a cmd prompt with system account privileges. The
only way I know to achieve that is to exploit a bug in the win2k
scheduler. At the time specified ...

| c:\scripts at 1:25 /interactive cmd
| Added a new job with job ID = 1

... a cmd window pops up with system account privileges ...

| Microsoft Windows 2000 [Version 5.00.2195]
| (C) Copyright 1985-2000 Microsoft Corp.
| 
| C:\WINNT\system32

... and then scripts, both perl and javascript ...

| # test-ole.pl
| use Win32::OLE;
| use strict;
| use warnings;
| 
| my $mtq = Win32::OLE - new('Mailtraq.Control');
| die Error: , Win32::OLE - LastError(), \n unless $mtq;
| 
| my $count = $mtq - Config - UserCount;
| print $count\n;

... can instance the control without problems ...

| C:\WINNT\system32 perl test-ole.pl
| 42

If the core problem can't be fixed, is there a better, safer way
of gaining system account status within a perl script?
-- 

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Running a script in the system account

2006-03-18 Thread mark pryor


--- Jim Hill [EMAIL PROTECTED] wrote:

 Hi all
 
 My mta, Mailtraq http://www.mailtraq.com/,
 contains a custom
 active-x control which can be accessed only when it
 is running as
 an application, not as a service. If Mailtraq is
 started as a
 service, its normal mode, the active-x control can't
 be instanced
 in perl or javascript ...
 
 | test.js
 | var mailtraq = new
 ActiveXObject(Mailtraq.Control);
 | WScript.Echo(mailtraq.Config.UserCount);
 
 | c:\scripts cscript test.js
 | Microsoft (R) Windows Script Host Version 5.6
 | Copyright (C) Microsoft Corporation 1996-2001. All
 rights reserved.
 |
 | c:\scripts\test.js(2, 1) Microsoft JScript runtime
 error: Automation server can't create object
 
 We, the Mailtraq developer and I, are assuming that
 this is a
 permissions problems but we can't get to the bottom
 of it. If
 anyone has encountered similar problems, we'd
 appreciate some
 pointers in the right direction. 
 

Jim,

You can use the WinXP schtasks utility to run a script
in the SYSTEM account.

run NewJob.pl as administrator and it will create a
scheduled task that runs under the System account,
then it will run the task and show you some ENV vars
that will prove to you that it works as expected.

regards,
tlviewer

 begin NewJob.pl -
#!/usr/bin/perl -w
#
# Author:  [EMAIL PROTECTED]
# script:   NewJob.pl 
# Description: method to run a perl script in the
SYSTEM account with the WinXP schtasks utility
# keywords: schtasks backtick winxp
# Date:   03/18/06
#   

use Cwd; 

#
#   /* part I -- get the task script from DATA and
write it to file */
#

$/ = '';
my @in = DATA;

print len=, length(join(\n,@in)), \n; 

my $in = join(\n,@in); 

my $task = RemotePerl;

open OUT, $task\.pl;

print OUT $in;
close OUT;

#
# /* part II -- run the utility (schtasks) using
backticks and create our _Scheduled Task_ */
#
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true
#

my $wd = getcwd;
print dir= $wd/$task\.pl, \n;
#exit(0);

# use the native (WinXP) utility to create Scheduled
Tasks via commandline
my $mk =NEW;
schtasks /create /tn RemotePerl /ru SYSTEM /tr perl
$wd/$task\.pl /sc once /st 09:00:00
NEW

print `$mk`; 

#
# /* part III -- use backticks to run our job */
#

$mk =RUN;
schtasks /run /tn $task
RUN

print `$mk`;

sleep 2;

`notepad $wd/$task\.txt`

__END__  

use File::stat;

# pretty print time
sub PPTime {
my @localtime = localtime shift;
return sprintf(%04d-%02d-%02d--%02d:%02d:%02d,
$localtime[5]+1900,
$localtime[4]+1,
$localtime[3],
$localtime[2],
$localtime[1],
$localtime[0]); 
}   

my $setup_path = c:\\WinNT\\setupapi.log; 
my $st = stat($setup_path); 


my $tstfile =  $0;
$tstfile =~ s/pl\s*$/txt/i;

open OUT, $tstfile  or exit(13); 
print OUT Today=, PPTime( time),  \n; 

print OUT User=, Win32::LoginName(),  \n; 

print OUT mod time=, PPTime($st-mtime), \n;
#print OUT Name=, Win32::NodeName(), \n;

foreach my $var (sort keys %ENV) {
  my $val = $ENV{$var};
  $val =~ s|\n|\\n|g;
  $val =~ s||\\|g;
  print OUT qq{${var} = ${val}\n};
} 
close OUT; 
exit(11);
__END__ 
 end script --   


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Running a script in the system account

2006-03-18 Thread Jim Hill
mark pryor in
[EMAIL PROTECTED]:
 --- Jim Hill [EMAIL PROTECTED] wrote:
 
  [...] is there a better, safer way
  of gaining system account status within a perl script?

Thanks for the response, Mark.

 You can use the WinXP schtasks utility to run a script
 in the SYSTEM account.

I can't, I'm afraid. I'm running win2k with no plans to change.

 run NewJob.pl as administrator and it will create a
 scheduled task that runs under the System account

Instead of running all day with a cmd shell with system account
privileges, I think it would be safer if only the scripts which
need such privileges are able to obtain them at runtime for
themselves. 

Unfortunately, I have no idea how to go about that.
-- 

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs