Process idle tasks

Discussion in 'Software' started by threecoins, Apr 2, 2011.

  1. threecoins

    threecoins Private E-2

    I'm making a batch file that will process idle tasks. I want the program to check for the existence of the process rundll32.exe, which runs when idle tasks are being processed, but closes if it doesn't need to be run. Then, I want the program to wait 15 minutes before it closes so they know when it is done. Here is what I have so far:

    At :2, I'm unsure what to put after the rundll32.exe, since I just found that script to check for it on Google. I know that eq is the correct paremeter, but I don't know what to put in the myapp.exe. In its current state, it just goes to 1, which shouldn't happen, because I know that rundll32 closes on my computer after about three seconds.

    I know that this wouldn't be useful to a lot of people, I just wanted it for personal use, so I can make a one click icon to run all the cleanup.
     
  2. threecoins

    threecoins Private E-2

    Edit:

    I've added a command to check for the existence of the Windows Resource Kit and used the sleep command instead of a vbs. I'm still trying to find a way to check for that process being open.
     
  3. GermanOne

    GermanOne Guest

    Try something like that
    Code:
    @echo off
    color 17
    title Process Idle Tasks by **** ********
    
    echo This will take about 15 minutes and should be run every three days.
    set /p "input=Would you like to process idle tasks? [y/n] "
    if /i "%input%" neq "y" goto NO
    
    :YES
    start "" "Rundll32.exe" "advapi32.dll,ProcessIdleTasks"
    echo This window will close if all idle tasks are processed.
    echo Please do not shut down your computer or run other programs
    
    :loop
    ping -n 10 localhost>nul
    tasklist /FI "IMAGENAME eq Rundll32.exe" /NH|findstr /ibc:"Rundll32.exe">NUL &&goto loop
    
    goto :eof
    
    :NO
    echo You declined to run this file.
    echo Make sure you run this at least once a week!
    echo This file will now terminate.
    pause
    
    BTW On Win7 you have to "Run As Administrator".

    Regards
    GermanOne
     
  4. threecoins

    threecoins Private E-2

    Thanks for the help. That is a little better structured than what I had written originally and it works fine. I'll be sure to credit you for the base file, even though I'm going to add to it some.
     
  5. threecoins

    threecoins Private E-2

    I noticed your note about Windows Seven. Not having experience with it, I wondered if this would work to check if a user is an administrator, since it has an option to right click and run as administrator, and I have no access to Windows Seven or Vista.

     
  6. GermanOne

    GermanOne Guest

    No, this code doesn't work anymore. I guess the reason why is that M$ changed the stream type of DEFRAGs output if an error occures. On XP it comes up as stdErr but on Win7 as stdOut.

    BTW If you work on Win7 and you belong to the local admin group it doesn't mean you always work with administrative rights. The User Account Control (UAC) settings are the reason for that.
    It needed some tests to tell you something more how a check could work.
    That's my code:
    Code:
    @echo off &setlocal
    
    echo %username%
    
    for /f "tokens=*" %%a in ('net localgroup 2^>nul^|findstr /ic:"admin"') do (
      set "check=%%a"
      net user %username%|findstr /c:"%%a">nul &&(
        echo You belong to the local admins.
      )||(
        echo You don't belong to the local admins.
      )
    )
    if not defined check echo You have no rights to run the NET command.
    
    fsutil fsinfo drives|findstr /c:":\\">nul &&(
      echo You work with administrative rights.
    )||(
      echo You don't work with administrative rights.
    )
    
    pause>nul
    
    I tested it with 3 different accounts on my PC.

    *** 1st account: Administrator
    The output:
    *** 2nd account: GermanOne
    The output:
    When I run as administrator:
    *** 3rd account: Guest
    The output:
    If I run as administrator a window comes up where I had to select one of the admin accounts and enter its password.
    Regards
    GermanOne
     
  7. mjnc

    mjnc MajorGeek

    Suggestion:

    set /p input=
    if %input%== y goto YES
    if %input%== n goto NO
    (what if they don't press y or n ?)
    goto ERR
    :
    :
    (at the end of the file)
    :ERR
    echo Sorry, invalid response
    (this isn't necessary, but you could add - END label provides an exit point from anywhere)
    :END

    Or put another label at the top before the prompt and loop back with goto after the error message.
     
  8. GermanOne

    GermanOne Guest

    Hi mjnc.

    It's always dangerous to work without quotes like:
    Code:
    if %input%==y ...
    If you hit Enter without inputting anything then %input% is not defined and results in an empty string. Something like
    if ==y ...
    will interrupt the batch processing.
    Better:
    Code:
    if /i "%input%"=="y" ...
    The /i option ignores upper and lower case. Because of the quotes an undefined variable results in the following line ...
    if ""=="y" ...
    ... which has the right syntax for the if command.

    An :END label is unnecessary. There is an imaginary label available. By ...
    Code:
    goto :eof
    ... it jumps to the end of file and quits the batch process. (No need to write this label to the end of your code!)

    Regards
    GermanOne
     
  9. mjnc

    mjnc MajorGeek

    Hi GermanOne.

    Yeah, I know about the quotes thing - I just copied the code as it was.

    I typically do something like:
    if not "%somevar%"=="thisthing" goto whereever

    Some years ago I saw a help doc (Microsoft??) that showed the following to check for an empty value.
    Example:
    if "%1x"=="x"

    I did not know about the :eof label.
    Is that something that was added in later versions of DOS or command.com??
    I've gone through two ms-dos books from about twenty years ago, by Microsoft Press,
    but don't recall ever seeing anything about an EOF implied label.
    I like that - THANKS.

    Is there a good up to date reference available for batch commands that will work with XP?
    If there is an inexpensive book available for such, I'd buy it just to have the reference.
     
  10. GermanOne

    GermanOne Guest

    Well, goto :eof can't be used on DOS or old Windows versions (where command.com is the only command line interpreter). Since Windows NT came with cmd.exe, the so called "Command Extensions" are available. Those are e.g. for /f, set /p, if /i or goto :eof.

    Have a look at the M$ command-line reference to get an overview of available commands on XP.

    BTW I know neither a German nor an English book about batch programming. If there is such a book, it's certainly very small :-D

    Regards
    GermanOne
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds