For Function with Pipe Problem.

Discussion in 'Microsoft Windows 2000 CMD Promt' started by BaKaR, Mar 24, 2004.

  1. BaKaR

    BaKaR Guest

    Hi!
    I have a problem with a *.cmd batch script.
    If i run it "on click" it is working, but if i run it with "schtasks.exe" and "system" user (in background) its not running one of
    the two for functions:


    @echo off

    for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
    echo %date% %time% Info.PID: %%i >> file.log

    for /f "tokens=4" %%k in ('kernrate -p %%i -s 2 ^| findstr /C:"User Time"') do (
    echo %date% %time% Info.CPU: %%k >> file.log

    if %%k GTR 40.0% (
    echo %date% %time% "CPU OverUse Positive ( %%k )" >> file.log
    call taskkill /pid %%i /F
    )
    echo Out_1 >> file.log
    )
    echo Out_2 >> file.log
    )
    echo %date% %time% "Finished!" >> file.log

    So, the problem is happening in for function where i use kernrate and findstr. If i run the batch "on click", everything is working
    well, but if im using schtasks.exe with system user that part of the batch is skipped (also, i cant see echo Out_1) ?! or something,
    cauze i cant see its run, every echo i set in front, or after is initiated (again, except Out_1).

    Any ideas ?

    Thank You,


    *. Remove: "DnotSpamMe" When R_ing.
     
    BaKaR, Mar 24, 2004
    #1
    1. Advertisements

  2. BaKaR

    Marty List Guest

    "BaKaR" <> wrote in message
    news:c3rsov$3ea$4u.hr...
    > Hi!
    > I have a problem with a *.cmd batch script.
    > If i run it "on click" it is working, but if i run it with "schtasks.exe"

    and "system" user (in background) its not running one of
    > the two for functions:
    >
    >
    > @echo off
    >
    > for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
    > echo %date% %time% Info.PID: %%i >> file.log
    >
    > for /f "tokens=4" %%k in ('kernrate -p %%i -s 2 ^| findstr /C:"User

    Time"') do (
    > echo %date% %time% Info.CPU: %%k >> file.log
    >
    > if %%k GTR 40.0% (
    > echo %date% %time% "CPU OverUse Positive ( %%k )" >> file.log
    > call taskkill /pid %%i /F
    > )
    > echo Out_1 >> file.log
    > )
    > echo Out_2 >> file.log
    > )
    > echo %date% %time% "Finished!" >> file.log
    >
    > So, the problem is happening in for function where i use kernrate and

    findstr. If i run the batch "on click", everything is working
    > well, but if im using schtasks.exe with system user that part of the batch

    is skipped (also, i cant see echo Out_1) ?! or something,
    > cauze i cant see its run, every echo i set in front, or after is initiated

    (again, except Out_1).
    >
    > Any ideas ?
    >
    > Thank You,
    >
    >
    > *. Remove: "DnotSpamMe" When R_ing.
    >
    >



    Which OS are you using?

    Where is tasklist.exe located? Is this folder in the PATH of the SYSTEM
    account?

    Where is kernrate.exe located? Is this folder in the PATH of the SYSTEM
    account?

    While you're troubleshooting, comment out that @Echo Off. That makes it
    look nicer but it's hiding a lot of good troubleshooting info from you.

    The >> redirection is only redirecting standard output to your file.log.
    You're not seeing any error output, add " 2>>errors.log" or " 2>>file.log"
    like this:
    for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
    echo %date% %time% Info.PID: %%i >>file.log 2>>file.log
     
    Marty List, Mar 24, 2004
    #2
    1. Advertisements

  3. BaKaR

    BaKaR Guest

    Hi!

    OS: WinXP Pro.

    Tasklist.exe: C:\windows\system32\
    Kernrate.exe: C.\program files\MS Resource Kit\Tools\kernrate.exe

    Both are in the "Environment Variables">"System Variables"

    Im using echo and 2>>, just i gave you part of "almost" finished problem.

    Well, im using schtasks.exe (WinXP/Win2K3 at.exe) command which is working very well.

    schtasks /create /sc minute /mo 5 /tn "test" /tr c:\scripts\test.cmd /ru System

    So, it will put the task in the background process and execute it every 5 minutes with NTAuthority\System privilages/permissions.


    If i run the script, i tested, with my account (local Admin) it works fine, still, if ran with that schtasks and system account,
    aint working ...



    --


    -------;.Wo0o0oS!h:..
    !#!Int3RGAlaCTic Fu!x!#!:..
    =!:MESING a.k.a. BaKaR a.k.a BR4iNL355:..
    -------;.Ca0Tic EXp:..
    *. Remove: "DnotSpamMe" When R_ing.
    "Marty List" <> wrote in message news:c3s215$2aeiod$-berlin.de...
    >
    > "BaKaR" <> wrote in message
    > news:c3rsov$3ea$4u.hr...
    > > Hi!
    > > I have a problem with a *.cmd batch script.
    > > If i run it "on click" it is working, but if i run it with "schtasks.exe"

    > and "system" user (in background) its not running one of
    > > the two for functions:
    > >
    > >
    > > @echo off
    > >
    > > for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
    > > echo %date% %time% Info.PID: %%i >> file.log
    > >
    > > for /f "tokens=4" %%k in ('kernrate -p %%i -s 2 ^| findstr /C:"User

    > Time"') do (
    > > echo %date% %time% Info.CPU: %%k >> file.log
    > >
    > > if %%k GTR 40.0% (
    > > echo %date% %time% "CPU OverUse Positive ( %%k )" >> file.log
    > > call taskkill /pid %%i /F
    > > )
    > > echo Out_1 >> file.log
    > > )
    > > echo Out_2 >> file.log
    > > )
    > > echo %date% %time% "Finished!" >> file.log
    > >
    > > So, the problem is happening in for function where i use kernrate and

    > findstr. If i run the batch "on click", everything is working
    > > well, but if im using schtasks.exe with system user that part of the batch

    > is skipped (also, i cant see echo Out_1) ?! or something,
    > > cauze i cant see its run, every echo i set in front, or after is initiated

    > (again, except Out_1).
    > >
    > > Any ideas ?
    > >
    > > Thank You,
    > >
    > >
    > > *. Remove: "DnotSpamMe" When R_ing.
    > >
    > >

    >
    >
    > Which OS are you using?
    >
    > Where is tasklist.exe located? Is this folder in the PATH of the SYSTEM
    > account?
    >
    > Where is kernrate.exe located? Is this folder in the PATH of the SYSTEM
    > account?
    >
    > While you're troubleshooting, comment out that @Echo Off. That makes it
    > look nicer but it's hiding a lot of good troubleshooting info from you.
    >
    > The >> redirection is only redirecting standard output to your file.log.
    > You're not seeing any error output, add " 2>>errors.log" or " 2>>file.log"
    > like this:
    > for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
    > echo %date% %time% Info.PID: %%i >>file.log 2>>file.log
    >
    >
    >
    >
     
    BaKaR, Mar 24, 2004
    #3
  4. If I try to run kernrate from the system account I get:
    RtlAdjustPrivilege(SE_PROFILE_PRIVILEGE) failed: c0000061

    Try running it under anadmin account.

    "BaKaR" <> wrote in message
    news:c3rsov$3ea$4u.hr...
    > Hi!
    > I have a problem with a *.cmd batch script.
    > If i run it "on click" it is working, but if i run it with "schtasks.exe"
    > and "system" user (in background) its not running one of
    > the two for functions:
    >
    >
    > @echo off
    >
    > for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
    > echo %date% %time% Info.PID: %%i >> file.log
    >
    > for /f "tokens=4" %%k in ('kernrate -p %%i -s 2 ^| findstr /C:"User
    > Time"') do (
    > echo %date% %time% Info.CPU: %%k >> file.log
    >
    > if %%k GTR 40.0% (
    > echo %date% %time% "CPU OverUse Positive ( %%k )" >> file.log
    > call taskkill /pid %%i /F
    > )
    > echo Out_1 >> file.log
    > )
    > echo Out_2 >> file.log
    > )
    > echo %date% %time% "Finished!" >> file.log
    >
    > So, the problem is happening in for function where i use kernrate and
    > findstr. If i run the batch "on click", everything is working
    > well, but if im using schtasks.exe with system user that part of the batch
    > is skipped (also, i cant see echo Out_1) ?! or something,
    > cauze i cant see its run, every echo i set in front, or after is initiated
    > (again, except Out_1).
    >
    > Any ideas ?
    >
    > Thank You,
    >
    >
    > *. Remove: "DnotSpamMe" When R_ing.
    >
    >
     
    Paul R. Sadowski, Mar 24, 2004
    #4
  5. BaKaR

    Marty List Guest

    "BaKaR" <> wrote in message
    news:c3s549$mq4$4u.hr...
    > Hi!
    >
    > OS: WinXP Pro.
    >
    > Tasklist.exe: C:\windows\system32\
    > Kernrate.exe: C.\program files\MS Resource Kit\Tools\kernrate.exe
    >
    > Both are in the "Environment Variables">"System Variables"
    >
    > Im using echo and 2>>, just i gave you part of "almost" finished problem.
    >
    > Well, im using schtasks.exe (WinXP/Win2K3 at.exe) command which is working

    very well.
    >
    > schtasks /create /sc minute /mo 5 /tn "test" /tr c:\scripts\test.cmd /ru

    System
    >
    > So, it will put the task in the background process and execute it every 5

    minutes with NTAuthority\System privilages/permissions.
    >
    >
    > If i run the script, i tested, with my account (local Admin) it works

    fine, still, if ran with that schtasks and system account,
    > aint working ...
    >
    >



    Are you sure you're looking at the correct file.log? If the current
    directory is different for the scheduled task, then a new copy of file.log
    will be created elsewhere. Try specifying the full path to your output
    file.

    I think you should post the exact contents of your script, not something
    "almost" the same.
     
    Marty List, Mar 24, 2004
    #5
  6. BaKaR

    BaKaR Guest

    True, Got same error msg.
    Also, got same msg when i tryed running kernrate with another user on the system.

    Well, the problem is, System user is giving me "background" option from schtasks.exe which i cant get like a normal user..

    --


    *. Remove: "DnotSpamMe" When R_ing.



    "Paul R. Sadowski" <> wrote in message news:...
    > If I try to run kernrate from the system account I get:
    > RtlAdjustPrivilege(SE_PROFILE_PRIVILEGE) failed: c0000061
    >
    > Try running it under anadmin account.
    >
    > "BaKaR" <> wrote in message
    > news:c3rsov$3ea$4u.hr...
    > > Hi!
    > > I have a problem with a *.cmd batch script.
    > > If i run it "on click" it is working, but if i run it with "schtasks.exe"
    > > and "system" user (in background) its not running one of
    > > the two for functions:
    > >
    > >
    > > @echo off
    > >
    > > for /f "tokens=2" %%i in ('tasklist ^| findstr /i aplication') do (
    > > echo %date% %time% Info.PID: %%i >> file.log
    > >
    > > for /f "tokens=4" %%k in ('kernrate -p %%i -s 2 ^| findstr /C:"User
    > > Time"') do (
    > > echo %date% %time% Info.CPU: %%k >> file.log
    > >
    > > if %%k GTR 40.0% (
    > > echo %date% %time% "CPU OverUse Positive ( %%k )" >> file.log
    > > call taskkill /pid %%i /F
    > > )
    > > echo Out_1 >> file.log
    > > )
    > > echo Out_2 >> file.log
    > > )
    > > echo %date% %time% "Finished!" >> file.log
    > >
    > > So, the problem is happening in for function where i use kernrate and
    > > findstr. If i run the batch "on click", everything is working
    > > well, but if im using schtasks.exe with system user that part of the batch
    > > is skipped (also, i cant see echo Out_1) ?! or something,
    > > cauze i cant see its run, every echo i set in front, or after is initiated
    > > (again, except Out_1).
    > >
    > > Any ideas ?
    > >
    > > Thank You,
    > >
    > >
    > > *. Remove: "DnotSpamMe" When R_ing.
    > >
    > >

    >
    >
    >
     
    BaKaR, Mar 24, 2004
    #6
  7. BaKaR

    BaKaR Guest

    Ya, that was the right *.log file.
    Almost as in not so much error cheking + cleared all comments and some start, call lines in the end.

    + ill use Local computer Admin user - it will be enough.


    Thank You All!

    --

    *. Remove: "DnotSpamMe" When R_ing.



    "Marty List" <> wrote in message news:c3s6oh$2b68n2$-berlin.de...
    >
    > "BaKaR" <> wrote in message
    > news:c3s549$mq4$4u.hr...
    > > Hi!
    > >
    > > OS: WinXP Pro.
    > >
    > > Tasklist.exe: C:\windows\system32\
    > > Kernrate.exe: C.\program files\MS Resource Kit\Tools\kernrate.exe
    > >
    > > Both are in the "Environment Variables">"System Variables"
    > >
    > > Im using echo and 2>>, just i gave you part of "almost" finished problem.
    > >
    > > Well, im using schtasks.exe (WinXP/Win2K3 at.exe) command which is working

    > very well.
    > >
    > > schtasks /create /sc minute /mo 5 /tn "test" /tr c:\scripts\test.cmd /ru

    > System
    > >
    > > So, it will put the task in the background process and execute it every 5

    > minutes with NTAuthority\System privilages/permissions.
    > >
    > >
    > > If i run the script, i tested, with my account (local Admin) it works

    > fine, still, if ran with that schtasks and system account,
    > > aint working ...
    > >
    > >

    >
    >
    > Are you sure you're looking at the correct file.log? If the current
    > directory is different for the scheduled task, then a new copy of file.log
    > will be created elsewhere. Try specifying the full path to your output
    > file.
    >
    > I think you should post the exact contents of your script, not something
    > "almost" the same.
    >
    >
    >
    >
     
    BaKaR, Mar 24, 2004
    #7
  8. "BaKaR" <> wrote in message
    news:c3s6t7$qjo$4u.hr...
    >
    > Well, the problem is, System user is giving me "background" option from
    > schtasks.exe which i cant get like a normal user..


    If that's an issue then here's a simple way to run a batch file in a hidden
    window using WSH.

    Set WshShell = WScript.CreateObject("WScript.Shell")
    cmd = "c:\bin\scripts\ftpputiefavs.cmd"
    Return = WshShell.Run(cmd, 0, True)
    set WshShell = Nothing

    Just change the string that cmd points to to whatever your batch file is.
    Then run this script using wscript.exe as a scheduled job.
     
    Paul R. Sadowski, Mar 24, 2004
    #8
  9. BaKaR

    BaKaR Guest

    Thanks!

    --

    *. Remove: "DnotSpamMe" When R_ing.


    "Paul R. Sadowski" <> wrote in message news:...
    > "BaKaR" <> wrote in message
    > news:c3s6t7$qjo$4u.hr...
    > >
    > > Well, the problem is, System user is giving me "background" option from
    > > schtasks.exe which i cant get like a normal user..

    >
    > If that's an issue then here's a simple way to run a batch file in a hidden
    > window using WSH.
    >
    > Set WshShell = WScript.CreateObject("WScript.Shell")
    > cmd = "c:\bin\scripts\ftpputiefavs.cmd"
    > Return = WshShell.Run(cmd, 0, True)
    > set WshShell = Nothing
    >
    > Just change the string that cmd points to to whatever your batch file is.
    > Then run this script using wscript.exe as a scheduled job.
     
    BaKaR, Mar 24, 2004
    #9
  10. BaKaR

    BaKaR Guest

    Well, one more thing ..
    Ill use schtasks as "local computer\Administrator" so the tasks run in background.
    When i execute an *.exe file from the script ran in the schtasks .. background i get its process in task manager but the task is
    invisible in the tray bar.
    Any ideas how to run an exe aplication to foreground ?
    Think thats mapped to logged user ...
    But if i run schtasks as me i cannot hide the schtasks initiating, even with WSH script you provided.
    Every time it runs it pops svchost window (wsh script).

    The thing is, i have a *.cmd (which i provided) that needs to run every 3 minutes to check some things.
    In the end of that *.cmd there is If chk. If its positive then is starts an exe "start aplication.exe" and after that one "cscript
    script.vbs".

    If i run schtasks and *.cmd with local Admin right its working every 3 minutes in the background so i cant see it == thats ok.
    But, when it comes to that IF and its postive running exe is in background, including that *.vbs in the end.

    So, everything is kewl up to IF chk. There i need a mechanizm to run *.exe and *.vbs after to foreground/desktop.

    Any ideas ?

    --

    *. Remove: "DnotSpamMe" When R_ing.


    "Paul R. Sadowski" <> wrote in message news:...
    > "BaKaR" <> wrote in message
    > news:c3s6t7$qjo$4u.hr...
    > >
    > > Well, the problem is, System user is giving me "background" option from
    > > schtasks.exe which i cant get like a normal user..

    >
    > If that's an issue then here's a simple way to run a batch file in a hidden
    > window using WSH.
    >
    > Set WshShell = WScript.CreateObject("WScript.Shell")
    > cmd = "c:\bin\scripts\ftpputiefavs.cmd"
    > Return = WshShell.Run(cmd, 0, True)
    > set WshShell = Nothing
    >
    > Just change the string that cmd points to to whatever your batch file is.
    > Then run this script using wscript.exe as a scheduled job.
    >
    >
    >
     
    BaKaR, Mar 25, 2004
    #10
  11. The only thing I can think of is to use BeyondExec with the i switch (allow
    to interact with the desktop) to launch some of the applications.

    Look at http://www.beyondlogic.org/consulting/remoteprocess/BeyondExec.htm
    for details and see if you can use it to get that visible window.

    "BaKaR" <> wrote in message
    news:c3v0tv$unv$4u.hr...
    > Well, one more thing ..
    > Ill use schtasks as "local computer\Administrator" so the tasks run in
    > background.
    > When i execute an *.exe file from the script ran in the schtasks ..
    > background i get its process in task manager but the task is
    > invisible in the tray bar.
    > Any ideas how to run an exe aplication to foreground ?
    > Think thats mapped to logged user ...
    > But if i run schtasks as me i cannot hide the schtasks initiating, even
    > with WSH script you provided.
    > Every time it runs it pops svchost window (wsh script).
    >
    > The thing is, i have a *.cmd (which i provided) that needs to run every 3
    > minutes to check some things.
    > In the end of that *.cmd there is If chk. If its positive then is starts
    > an exe "start aplication.exe" and after that one "cscript
    > script.vbs".
    >
    > If i run schtasks and *.cmd with local Admin right its working every 3
    > minutes in the background so i cant see it == thats ok.
    > But, when it comes to that IF and its postive running exe is in
    > background, including that *.vbs in the end.
    >
    > So, everything is kewl up to IF chk. There i need a mechanizm to run *.exe
    > and *.vbs after to foreground/desktop.
    >
    > Any ideas ?
    >
    > --
    >
    > *. Remove: "DnotSpamMe" When R_ing.
    >
    >
    > "Paul R. Sadowski" <> wrote in message
    > news:...
    >> "BaKaR" <> wrote in message
    >> news:c3s6t7$qjo$4u.hr...
    >> >
    >> > Well, the problem is, System user is giving me "background" option from
    >> > schtasks.exe which i cant get like a normal user..

    >>
    >> If that's an issue then here's a simple way to run a batch file in a
    >> hidden
    >> window using WSH.
    >>
    >> Set WshShell = WScript.CreateObject("WScript.Shell")
    >> cmd = "c:\bin\scripts\ftpputiefavs.cmd"
    >> Return = WshShell.Run(cmd, 0, True)
    >> set WshShell = Nothing
    >>
    >> Just change the string that cmd points to to whatever your batch file is.
    >> Then run this script using wscript.exe as a scheduled job.
    >>
    >>
    >>

    >
    >
     
    Paul R. Sadowski, Mar 25, 2004
    #11
    1. Advertisements

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Kadir Doruk

    xcopy problem

    Kadir Doruk, Jul 3, 2003, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    7
    Views:
    2,760
    Kadir Doruk
    Jul 14, 2003
  2. Keith Langmead

    problem using dumpel to remotely backup an AD's event log

    Keith Langmead, Jul 15, 2003, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    0
    Views:
    1,167
    Keith Langmead
    Jul 15, 2003
  3. Roger Johnson

    pipe file input into command line command

    Roger Johnson, Aug 1, 2003, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    0
    Views:
    1,046
    Roger Johnson
    Aug 1, 2003
  4. Aliyah

    Pipe the output

    Aliyah, Mar 4, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    3
    Views:
    610
    Aliyah
    Mar 5, 2004
  5. Dave

    DSMOD User -pwd function

    Dave, Jul 23, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    3
    Views:
    1,895
    Jerold Schulman
    Jul 23, 2004
  6. Claus Koch

    Pipe Output into Environment Variable?

    Claus Koch, Aug 11, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    1
    Views:
    14,452
    Matthias Tacke
    Aug 11, 2004
  7. ajmister

    dateadd Function

    ajmister, Aug 23, 2004, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    1
    Views:
    410
    Phil Robyn
    Aug 23, 2004
  8. Wensi Peng

    oExec.StdOut after pipe Findstr

    Wensi Peng, Jan 7, 2005, in forum: Microsoft Windows 2000 CMD Promt
    Replies:
    1
    Views:
    771
    Matthias Tacke
    Jan 7, 2005
Loading...