Win32_Process.Create -- not starting process

Discussion in 'Python' started by abcd, Feb 14, 2006.

  1. abcd

    abcd Guest

    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 remotely....or why its random?
    These are win xp machines with no firewalls running.
     
    abcd, Feb 14, 2006
    #1
    1. Advertising

  2. abcd

    EShames Guest

    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 remotely....or 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:
    <rnas.bat>
    :: 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

    ::mad: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
    </rnas.bat>
     
    EShames, Feb 17, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Golden
    Replies:
    1
    Views:
    747
  2. Tim Golden
    Replies:
    1
    Views:
    744
  3. Matt Trivisonno
    Replies:
    1
    Views:
    365
  4. Tim Golden
    Replies:
    1
    Views:
    361
  5. Junkone
    Replies:
    3
    Views:
    219
    Daniel Berger
    Mar 13, 2008
Loading...

Share This Page