more help in batch files

Discussion in 'Software' started by red death68, Dec 18, 2010.

  1. red death68

    red death68 Command Sergeant Major

    ok so basicly i have a batch file set to open up a wordpad doc at a certain time everyday via a mix of batch and schedualed tasks the only problem is is that it has a habit of opening when im in full screen playing games and id like to make it wait until i exit the running program before executing what i want it to. is there a way to do this?

    basicly im asking "is there a way to tell a batch file not to run/or wait until programs closed if a certain program is running?"

    the base for the batch is simple for what i want it to it says

    start /MAX wordpad.exe "C:\Documents and Settings\Compaq_Owner\My Documents\MED REMINDER.rtf"
     
  2. PC-XT

    PC-XT Master Sergeant

    Some things you might try include setting the task's properties to not run until the computer is idle for a certain amount of time, or testing for each of the programs you don't want interrupted in the batch file, as the following links show:
    http://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script
    http://stackoverflow.com/questions/...e-how-can-i-tell-whether-a-process-is-running
    If they are running, you would need to delay the rest of the batch file, possibly by setting it as a once-only task using AT commands:
    http://support.microsoft.com/kb/313565 (This is for Win 2000, but AT /? works so you can see basic differences if there are any in your version.)
     
  3. PEBKAC

    PEBKAC Private First Class

    This is how I would check for a process in a batch file...

     
  4. red death68

    red death68 Command Sergeant Major

    i have it kind of running but certain running tasks its not recognizing heres what i have



    the things to check for are differnt game runing but it doesnt always work for some reason
     
  5. PC-XT

    PC-XT Master Sergeant

    I've had problems sometimes when the process name doesn't match mine correctly, but I usually get it working...

    In case you want to try it, here's another idea I used to do in DOS. I made a batch file for each program I wanted to mark for non-interruptibility (or whatever else I wanted to mark), like this:
    Code:
    @echo off
    echo Mark >> "c:\mystuff\mark.dat"
    [i]program_command[/i]
    del mark.dat /y
    
    using whatever file you want to exist to keep the interruption from happening. Then in your script, add this line near the beginning:
    if exist "c:\mystuff\mark.dat" exit

    This means making a batch file for each program that isn't successfully being detected. They can all use the same mark file, as long as you only run one at a time.

    You could use registry entries in the same way, instead.
     
  6. red death68

    red death68 Command Sergeant Major

    i found the problem apperently tasklist isnt supported by my xp because im using home so ima just put up with the distractions
     
  7. PC-XT

    PC-XT Master Sergeant

    Oh, I see. Well, the file lock thing I gave in the last post doesn't need the tasklist, since it keeps track of them itself. The only problem, besides the multiple files, is if the program crashes and doesn't delete the lock file, you need to run it again and exit properly, or just delete the file manually. This is what I used before the process list, and I still use it for other things. You would only need to make batch files to wrap programs you don't want interrupted. The others shouldn't need wrapping. Alternatively, you could just have one file, which I'll call dontint.bat:
    Code:
    @echo off
    echo Mark >> "c:\mystuff\mark.dat"
    start /wait %1 %2 %3 %4 %5
    del mark.dat /y
    and call it with the rest of the start parameters any time you don't want to be interrupted:
    c:\mystuff\dontint.bat "c:\program files\jagex\runescape\runescape.exe"
    I added the extra parameters up to 5 in case you want different ones for different programs.
     
  8. red death68

    red death68 Command Sergeant Major

    ok i may try that right now im trying to free up my system of a few gigs
     
  9. mjnc

    mjnc MajorGeek

    You can download Tasklist.exe here:
    Windows XP downloads
     
  10. red death68

    red death68 Command Sergeant Major

    is it supported by home though after i download it?
     
  11. GermanOne

    GermanOne Guest

    Yes it is.
    Place it in C:\Windows\system32 to use it from everywhere.
     
  12. red death68

    red death68 Command Sergeant Major

  13. spudman2

    spudman2 Private E-2

    I want to copy files from my hard drive to my usb drive. I want the file to include the date and time. I thought that my DOS command the ended with two commas would do it but apparently not.
    Windows XP operating system.
    the command I entered was copy c:\wizard.txt K:\wizard.txt,,
     
  14. PC-XT

    PC-XT Master Sergeant

    If you just want to update the timestamp while you copy, I sometimes use this method:
    type c:\wizard.txt > K:\wizard.txt
    It seems to often work for binary files, too.
     
  15. red death68

    red death68 Command Sergeant Major

    though you should have created another thread i do agree that your on the right track but i wouldnt specify the usb drive in such a way i would make it more of a variable path

    ill post a code soon unless what your trying is always on the drive path of k then youve already got your answer from pc-xt
     
  16. spudman2

    spudman2 Private E-2

    Is there a DOS version particular to this code? Thanks.
     
  17. spudman2

    spudman2 Private E-2

    The answer to my question turned out to be:

    copy c:\wizard.txt k:\wizard%date:~4,2%-%date:~7,2%-%date:~10%.txt

    yeilds :
    wizard01-19-2011.txt
     
  18. spudman2

    spudman2 Private E-2

    copy c:\wizard.txt k:\wizard%date:~4,2%-%date:~7,2%-%date:~10%.txt

    yeilds :
    wizard01-19-2011.txt
     
  19. mjnc

    mjnc MajorGeek

    To get the date formated as you have shown, with Windows XP CMD prompt:

    echo %date:~5,5%
    05-14

    echo %date:~0,5%
    2011-

    echo %date:~5,5%-%date:~0,4%
    05-14-2011

    Since the dash is part of the date string, it does not always need to be included
    in the formating mask.

    The first position on the left of the date string is indexed as position zero.
     
  20. red death68

    red death68 Command Sergeant Major

    ill look into thi9s for you i havnt had much free time but i may be able to get this working for you but i need some sleep first or else erronous coding can come about

    i just need to cofirm all you need to do is copy from hdd to flash drive with date and time as the title?

    if so i should be able too get that working quite soon it probably wont be automatic unless i do alot more work but all it will take is the drive letter input if i do it my one way

    i not there was a utility i was toying with forever ago that can detect the flash drive's port
     
  21. GermanOne

    GermanOne Guest

    As to the detection of a pen drive--

    There are methodes in pure batch to do this:
    - fsutil (available on XP, but restrained by UAC on Win7)
    - wmic (not available on XP Home)

    I would like to show you 2 different examples which are kinda exotic ;)
    You could use ActiveX objects indirectly. They are not supported for batch, but for the Windows Script Host.

    • VBScript - Redirection
      Batch can write a VBScript by echo-redirection, call it with cscript.exe and process the output in an FOR loop.

      Example1.bat
      Code:
      @echo off &setlocal
      
      (
        echo For Each objDrive In CreateObject^("Scripting.FileSystemObject"^).Drives
        echo   strSerialNumber = Right^("00000000" ^& Hex^(objDrive.SerialNumber^), 8^)
        echo   Wscript.Echo objDrive.DriveLetter ^& " " ^& objDrive.DriveType ^& " " _
        echo     ^& Left^(strSerialNumber, 4^) ^& "-" ^& Right^(strSerialNumber, 4^) _
        echo     ^& " " ^& objDrive.VolumeName
        echo Next
      )>"%temp%\drives.vbs"
      
      for /f "tokens=1-3*" %%a in ('cscript //nologo "%temp%\drives.vbs"') do (
        echo drive letter  : %%a
        echo drive type    : %%b
        echo serial number : %%c
        echo volume name   : %%d
        echo(
      )
      
      del "%temp%\drives.vbs"
      pause
      
    • JScript - Injection
      Both, batch and JScript use the same file. The first line is valid for both languages. You need it to mask the /* for batch which precedes a comment block in JScript. All code between /* and */ will not be parsed in JScript while the code below of goto :eof will not be parsed in batch. Because the extension .bat is not associated to wscript or cscript we have to tell cscript.exe what script engine has to be used ( option /e: ).

      Example2.bat
      Code:
      @set @x=0 /*
      @echo off &setlocal
      
      for /f "tokens=1-3*" %%a in ('cscript //nologo //e:JScript "%~f0"') do (
        echo drive letter  : %%a
        echo drive type    : %%b
        echo serial number : %%c
        echo volume name   : %%d
        echo(
      )
      pause
      goto :eof
      */
      
      var enumDrives = new Enumerator((new ActiveXObject("Scripting.FileSystemObject")).Drives);
      var strSerialNumber;
      for (; !enumDrives.atEnd(); enumDrives.moveNext()) {
        strSerialNumber = (enumDrives.item().SerialNumber + 4294967296).toString(16).toUpperCase().slice(-8, 9);
        WScript.Echo((enumDrives.item()).DriveLetter + ' ' + enumDrives.item().DriveType + ' ' +
          strSerialNumber.substr(0, 4) + '-' + strSerialNumber.substr(4, 4) + ' ' + enumDrives.item().VolumeName);
      }
      

    Both scripts display the same output, e.g.
    Code:
    drive letter  : C
    drive type    : 2
    serial number : 9EA9-0A30
    volume name   :
    
    drive letter  : D
    drive type    : 4
    serial number : 584E-1257
    volume name   :
    
    drive letter  : E
    drive type    : 1
    serial number : 0858-7C43
    volume name   : GERMANONE
    
    Drive types:
    0 = Unknown
    1 = Removable
    2 = Fixed
    3 = Network
    4 = CD-ROM
    5 = RAM Disk

    Well, it would be simple to use some IF statements to determine which drives are "removable" and (just to make sure you found the right pen drive) compare the serial number and/or the volume name.

    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