How often do you use batch files to automate tasks?

Discussion in 'polls' started by Mrkvonic, Jan 5, 2007.

?

How often do you use batch files to automate tasks?

  1. Quite often; they are highly useful

    19 vote(s)
    30.6%
  2. Sometimes, when something really boring needs to be done

    14 vote(s)
    22.6%
  3. Very very rarely or am afraid to try

    10 vote(s)
    16.1%
  4. Never, I don't know what they are

    19 vote(s)
    30.6%
  1. m00nbl00d

    m00nbl00d Registered Member

    Joined:
    Jan 4, 2009
    Posts:
    6,623
    Hello Eice,

    I've just tried your batch file, since I'm starting to use Chromium (taking a taste of it :D), but the version I have is still the same, and a new one already came out.

    I started the batch file manually. Or, a task with some special command is needed?


    Thanks
     
  2. Eice

    Eice Registered Member

    Joined:
    Jan 22, 2009
    Posts:
    1,413
    Mine extracts Chromium to "D:\Programs\Chromium", which is where I keep my Chromium install, and calls 7-zip as an external program to extract the downloaded zip file. Those might be why it's not working for you.

    Still, if you've run the batch file, check your temp folder and you should find chrome-win32.zip there.
     
  3. m00nbl00d

    m00nbl00d Registered Member

    Joined:
    Jan 4, 2009
    Posts:
    6,623
    I did change D:\Programs\Chromium to C:\Programas\Chromiun, which is where is mine, and I also use 7zip.

    But, I found the reason why it wasn't updating properly. The zip file, when extracted, extracts to chrome-win32\chrome-win32. The contents are placed in the second folder. And, the batch file, if I interpret it right, will rename chrome-win32/chrome-win32 to Chromium/Chromium. This, will then be copied to C:\Programas\Chromium, creating a sub-folder named Chromium, and it won't replace the files, at all.

    The batch file needs to be changed only to copy the second Chromiun folder, and not both.
     
  4. Eice

    Eice Registered Member

    Joined:
    Jan 22, 2009
    Posts:
    1,413
    Ah yes, I forgot about that.

    I have two subfolders in "D:\Programs\Chromium", namely "Chromium" and "Profile". I customized my Chromium so that it uses the profile folder on D: instead of creating one in my Windows user profile folder. When I know I'll need to work on elsewhere, I just copy the entire "D:\Programs\Chromium" folder to my USB, which allows me to run Chromium on other computers.

    In your case, you need to change "D:\Programs\Chromium" to "C:\Programas", and make sure the 7-zip installation path is correct.
     
  5. m00nbl00d

    m00nbl00d Registered Member

    Joined:
    Jan 4, 2009
    Posts:
    6,623
    Yes, that's what I did meanwhile, and indeed, going to the temp folder I can see the chrome-win32.zip. But, it still won't copy the contents to C:\Programas\Chromium. I think its due to the fact I'm running LUA (and UAC, perhaps, also). I guess its preventing 7zip from replacing (and adding new) files.

    Unfortunately my knowledge of batch files isn't that great. I've been starting to practice, but only with easier ones, to perform some tasks. Nothing that fancy. lol

    Do you have any idea of what would need to be changed, in the original batch file, to make it work? (I understand this may be asking too much.)


    Thanks
     
  6. Eice

    Eice Registered Member

    Joined:
    Jan 22, 2009
    Posts:
    1,413
    If UAC is indeed the culprit, then AFAIK there's no way around that. As a security measure, runas specifically does not include a switch to automatically accept the insertion of administrator passwords in batch files. You'd have to be at your computer to enter your admin password whenever the batch file runs, which kind of defeats its purpose.

    One thing you can try is to run the batch file via the command prompt instead of double-clicking it in Windows Explorer. That way the cmd.exe window won't close automatically when the batch file ends, giving you an opportunity to see what errors were produced, which may or may not help debug the problem.
     
  7. m00nbl00d

    m00nbl00d Registered Member

    Joined:
    Jan 4, 2009
    Posts:
    6,623
    That's what I've done already, and what I get is

    I pressed (Y)es, and I get the same errors

    And the show goes on...
     
  8. Eice

    Eice Registered Member

    Joined:
    Jan 22, 2009
    Posts:
    1,413
    Try this.

    Create a new administrator account, and in it disable UAC. Use the Task Scheduler to schedule the batch file to run under that account.
     
  9. m00nbl00d

    m00nbl00d Registered Member

    Joined:
    Jan 4, 2009
    Posts:
    6,623
    I'm using Windows Vista Home Premium, and I know it is possible to disable UAC for admin. account, by tweaking the registry, but, I think it will disable for all admin. accounts, no?

    Or are you aware of some other registry hack that allows to disable UAC for a specific admin. account?
     
  10. Eice

    Eice Registered Member

    Joined:
    Jan 22, 2009
    Posts:
    1,413
    AFAIK that's true. A problem if you don't use a separate standard user account.

    One last thing I can think of to try is to run the scheduled task with system privileges instead: set the task user to (computername)\SYSTEM. If this doesn't work either... then I'm stumped. :D
     
  11. Rmus

    Rmus Exploit Analyst

    Joined:
    Mar 16, 2005
    Posts:
    4,020
    Location:
    California
    Daily. I can't imagine being w/o batch files. I remember the first bat file I was taught:

    e-bat.gif

    "You need a quick way to exit the Prompt," my friend said!

    I dread the day when bat files can no longer be used in the Windows OS. I'll have to learn VBS, I guess!

    ----
    rich
     
  12. Kerodo

    Kerodo Registered Member

    Joined:
    Oct 5, 2004
    Posts:
    8,013
    Haven't used batch files since the DOS days, where we heavily used 'em for just about everything. But ever since Win95, I have not used any. I don't much miss 'em either... I stopped programming then, and I guess I stopped using batch files as well :)
     
  13. m00nbl00d

    m00nbl00d Registered Member

    Joined:
    Jan 4, 2009
    Posts:
    6,623
    I still haven't tried that, but the thing is - and is something I totally forgot - that if X folder is already in C:\Program Files\*, then UAC will not prompt for any action. This means that 7-zip would have no problems replacing the files in the Chromium folder.

    Now, I took a better look at your batch file, and, if I understand it well, you have it set to rename C:\Program Files\Chromium\Chromium to Chromium-backup, is that correct? If so, then the folder Chromium no longer exists, and that's why, in my case, the files replacement will fail.

    I think I just need to change the batch file to download the zip file to the temp folder, then extract the contents to C:\Program Files\Chromium, killing the step of backing up.
     
  14. Eice

    Eice Registered Member

    Joined:
    Jan 22, 2009
    Posts:
    1,413
    chrome-win32.zip contains a folder named chrome-win32 that contains all the Chromium files. What my batch file does is to rename the original Chromium folder to Chromium-backup, extract chrome-win32 from chrome-win32.zip to the desired folder, and then rename chrome-win32 to Chromium. So in a sense nothing is really being "overwritten", just renamed around.
     
  15. axial

    axial Registered Member

    Joined:
    Jun 27, 2007
    Posts:
    479
    In addition the DevCon uses I mentioned previously ( post 21 in this thread ) I also use DevCon with batch files to stop/start floppy drive, so that Windows or other ill-behaved apps don't pause to check the floppy drive when they scan for devices, and the drive letters don't show up in File Manager or anywhere.

    The same principle could be used to stop/start almost any device on the system.

    One .cmd file to stop:
    devcon disable "@FDC\GENERIC_FLOPPY_DRIVE\5&2B82B283&0&0"

    One .cmd file to start the floppy:
    devcon restart "@FDC\GENERIC_FLOPPY_DRIVE\5&2B82B283&0&0"
     
  16. Sully

    Sully Registered Member

    Joined:
    Dec 23, 2005
    Posts:
    3,719
    Here is a great place to go
    http://home7.inet.tele.dk/batfiles/batfiles.htm

    I use them all the time. Although I would daresay there is a difference between a batchfile that is just doing comman line work for an application versus a batch file that uses dos commands, such as loops and for/token, errorlevel, | piping etc.

    I would prefer using AutoIt more than batch though, as it can do much of what batch does. But, even at that, without a healthy knowledge of batch you will be excluded from doing many things. It is so convenient to use a batch file to give command line parameters to something like netsh, and dump the results to a text file that you can then parse in about any script language. Yet without the batch (actually only command line portion), you cannot do it.

    My vote is batch is probably the most powerfully underrated tool available for automation. Not the most powerful but still underrated.

    Sul.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.