Re: Win32_Process.Create -- not starting process

2006-02-17 Thread EShames
On 2/14/2006 11:25 AM, abcd wrote:
> I am using Python to create a process on another computer.  Both
> computers are on the same domain with admin privileges.
> 
> On computer B I have a batch script which starts a python script.  From
> computer A I am doing the following:
> 
> import wmi
> w = wmi.WMI("1.2.3.4")
> p = w.new("Win32_Process")
> pid, retVal = p.Create(CommandLine="C:\\a_script.bat")
> print pid, retVal
> 
> The output I get is, 1218 0  0 = "Successful Completion"
> .however the python script that is called from the batch script
> never seems to run or at least only for a split second.  Sometimes I
> see python.exe appear in the task manager on computer B for a split
> second then it goes away.  So I went to computer B and double clicked
> on the batch script, and sure enough a command opened up and the python
> script was running...and stayed running...no problem.   I should
> mention, that sometimes it will execute the batch script and the Python
> script will run and stay running.  That has only happened after trying
> to do "p.Create(CommandLine)" more than once, but not every time I
> try.
> 
> Any ideas why its not working for me remotelyor why its random?
> These are win xp machines with no firewalls running.
> 

Troubleshooting context issues seems the right track. Consider:

  -Start a_script.bat using %windir%\system32\runas.exe ([/noprofile | 
/profile] [/env] [/netonly] Play with parameters to set and explore 
context issues.

  -Use the (well respected) psexec.exe from Sysinternals to confirm 
remote execution using another means.

  -Also from Sysinternals get and use ProcessExplorer, FileMon, TDIMon 
and TCPMon

Other (possibly insulting to mention, please forgive) win batch 
troubleshooting steps:
  -REM out "@echo off" if any.

  -Place a strategic "pause" in the batch to hold the command window open.

  -Direct output from commands in the bat to a file "set > 
c:\temp\bat_out1.txt" then look at the creator, owner, etc.


Prophylactic measures & things that effect the user context behavior:
  -Check "launch folder windows in a seperate process" in 
Explorer/Tools/Folder Options/View or you will not be able to run 
explorer.exe as an alternate user.
  -Uncheck "use simple file sharing" in same as above.


FWIW Getting runas to to fire cmd.exe, then a .bat can be tricky, I use 
this to wrap runas, maybe it will help:

:: Wrapper for runas.exe
:: If called with a parameter use it as target, otherwise start cmd.exe
:: !Note: /savecred is is convenient, but not very secure!
:: LAST EDIT EBS 2006-02-10

::@echo off

:: !Change _USER to domain and user to run as!
set _USER=domain\user

if %1! == ! (
 %SYSTEMROOT%/system32/runas.exe /savecred /noprofile /user:%_USER% 
"cmd.exe cd /D c:\\\_utils\"
 goto END
) else (
 %SYSTEMROOT%/system32/runas.exe /savecred /user:%_USER% "%~f1"
)

:END
::DIAGNOSTIC
  pause
exit

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Print a PDF transparently

2006-02-17 Thread EShames
On 2/17/2006 9:02 AM, Daniel Crespo wrote:
> Hi to all,
> 
> I want to print a PDF right from my python app transparently. With 
> "transparently" I mean that no matter what program handles the print 
> petition, the user shouldn't be noticed about it.
> 
> For example, when I want to print a PDF, Adobe Acrobat fires and keep
>  opened. This is what I don't want to happen (and I thing there are a
>  lot of people who want this too). So I just want to send the PDF to
> the right handler and print it. That's all.
> 
> I've seen some things like Adobe's Postscript driver that can read a 
> PDF, or Ghostscript, but I still don't know how to use it.
> 
> Any help for printing a PDF transparently?
> 
> Thank you
> 
> Daniel
>

You may find that RedMonEE is a useful piece to your puzzle. I find it 
to be stable and quite invaluable.

http://www.is-foehr.de/
> RedMon - Redirection Port Monitor EE
> 
> Transparent PostScript printing from Windows NT, W2K and XP. Overview
> 
> 
> The RedMon EE port monitor redirects a special printer port to a
> program. RedMon EE is commonly used with Ghostscript and a
> non-PostScript printer to emulate a PostScript printer.
> 
> RedMon EE can be used with any program that accepts data on standard
> input.
> 
> Using RedMon EE you create a redirected printer port. If you connect
> a Windows printer driver to the redirected printer port, all data
> sent to the redirected port will be forwarded by RedMon to the
> standard input of a program. The output of this program can be sent
> to different printer port, or the program can generate whatever
> output it desires.
> 
> A PostScript Windows printer redirected to a RedMon port can shared
> on a network. When this printer is configured to use Ghostscript and
> a non-PostScript printer, it appears as a PostScript printer to other
> network clients.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Activating Batch Files from Python

2006-04-20 Thread EShames
On 4/18/2006 11:39 PM, Jeff Groves wrote:
> I'm writing a launcher that should do the following:
> 
> 1. Activate a .bat file to set environmental variables.
> 2. Start 3 programs, using said environmental variables as arguments.
> 
> However, I can't get the environmental variables to stick because all
> of Pythons' system start/open functions split off into their own little
> subshells, therefore the .bat file doesn't affect the main shell.
> 
> How can I use the .bat file to set environmental vars from Python?
> 

Resource Kit has SETX, but better is SETENV by Vincent Fatica
  http://barnyard.syr.edu/~vefatica/

C:\_Utils>setenv /?
  SETENV syntax:

   To set or change the value of a variable:

  User environment:   setenv -u name value(also /u)
  Machine environment:setenv -m name value(also /m)
  Default user environment:   setenv -d name value(also /d)
  Volatile environment:   setenv -v name value(also /v)

   To display a variable: setenv -u|-m|-d|-v name

   To delete a variable:  setenv -u|-m|-d|-v name -delete   (also 
/delete)

   To display an environment: setenv -u|-m|-d|-v

   Use double-quotes around values containing spaces.

   If a variable name or value is to CONTAIN a double-quote,
   escape that double-quote as \"

   Return codes: 0 = success1 = variable not found
 2 = access denied  3 = other error
 4 = SETENV has shown this syntax message

   Requested output goes to STDOUT; help and error messages to STDERR.
-- 
http://mail.python.org/mailman/listinfo/python-list