[XP] "Silent" scripts

Discussion in 'Techie Discussion' started by Shovel, Jan 24, 2004.

  1. Shovel

    Shovel Can't get enough of FH

    Hello all:

    I have a script (.bat file) that I have scheduled to operate my webcam using a java prog I wrote and an FTP upload script I also wrote. However, whenever it runs it pops up a cmd.exe window until the script finishes.

    Can anyone tell me how to run a .bat file silently in the background - without any visual interruption.

    I tried making a shortcut to the script and running that as "Run minimised", but Scheduler refused to run that. I'm sure there must be a way to run a script without the cmd box? Surely?

    Thanks,

    Ben
     
  2. phlash

    phlash Fledgling Freddie

    Visual studio (amongst other proggys) runs compilers / scripts in 'detached' mode, that is with no window, but stdout/err connected to some appropriate pipe back to the controlling program. I don't think this is an option for shortcuts, but you could write a simple wrapper program that did this. How about doing the FTP from the same Java progam, then running that with javaw.exe?

    Phil.
     
  3. Shovel

    Shovel Can't get enough of FH

    One option that's come my way from the MS knowledge base is to have a script calling the script using the "start /min" command, which will pop the business end of the script on the taskbar, but minimised. That could be a temporary option.

    With regards to doing the FTP in java: Yes, I could. The reason for having it separated is due to wanting things to be lovely and moduler - so that theoretically the webcam capture program could be reused for capturing for some other purpose. But yes, in reality it's a very real option that I may implement. I just can't really believe that there's no way to silence a script.

    I guess maybe if it was a vbs script triggering the shell events it might do it... but I don't know if that would have the actual 2 stages silenced as well.

    I noticed actually that Samurize has a means of running command line actions as well, returning the result to Sam rather than to standard output. I'm increasingly of the feeling that somewhere in the deepest darkest depths of Windows is a blindingly simple button to do it...

    Thanks for the feedback :)
     
  4. babs

    babs Can't get enough of FH

    I'm not sure if it has any relevance, or even if it exists in XP, but I'm sure in one windows version there's a file called _default.pif (or something very similar). This characterizes the default properties/actions for a program that automatically spawns cmd to run it.

    I know I've changed it in the past succesfully to overcome things, but I think I'm going way off base now. I've had a few and am losing my train of thought.
     
  5. Shovel

    Shovel Can't get enough of FH

    _default.pif does indeed still exist in XP (C:\Windows\_default.pif). It's a binary file though, do you recall how it was you go about editing it?
     
  6. phlash

    phlash Fledgling Freddie

    It used to be PIFedit.exe, but that seems to have gone away - I get a very PIF-like set of properties for _default.pif, via the right-click context menu. I don't thing programs can be made to start hidden, but minimized - yup.

    Phil.
     
  7. Xavier

    Xavier Can't get enough of FH

    Why not just use the WindowsXP webcam powertoy? It can execute and run in the background silently, manage capture and upload without any user interaction.
     
  8. Shovel

    Shovel Can't get enough of FH

    Because my webcam isn't compatible with it.
     
  9. sibanac

    sibanac Fledgling Freddie

    shovel if you launch from sheduler it will run hidden in the background
     
  10. Shovel

    Shovel Can't get enough of FH

    Sadly not. It does launch from scheduler, and pops up a command prompt svchost.exe window. Unless I'm doing it wrong? ;)

    I have a batch file to launch the webcam java app and then to launch the perl upload script. Is there a different/better way to launch them in-order?
     
  11. sibanac

    sibanac Fledgling Freddie

    there is a away to do it drom sheduler, I had the same prob at work a while ago, sadly cant remember the exact details
    I'll check the settings when i get into work tomorow
     
  12. Shovel

    Shovel Can't get enough of FH

    Ah thankies :) That'd be great.
     
  13. sibanac

    sibanac Fledgling Freddie

    soz shovel i looked at it and didnt see any special settings.
    Must be posible tho since i got 4 cmd.exe's in taskmanager but none in my bar
     
  14. Clown

    Clown Part of the furniture

    I sort of want to do the same thing. I have a Windows BNC running, but it only runs in a command window. I wanna get it out of the bar or something. Can't I add it to services and make it work in the background?
     
  15. Shovel

    Shovel Can't get enough of FH

    There is a resource kit application that will install any .exe as a service, however, it doesn't work for everything. I tried it with my Dock (don't know why...) and it didn't launch as the Dock didn't send the right response or something.

    The exe is called "instsrv.exe", I think it's part of the Windows 2000 resource kit. If not, then I'll send it your way. I seem to have built up a rather large collection of command line apps... should really catalogue their sources better... ;)
     
  16. Clown

    Clown Part of the furniture

    You on IRC?
     
  17. Shovel

    Shovel Can't get enough of FH

    Follow Up:

    OK, managed to get some useful information from Microsoft, and from a random guy from Brazil who found us via Google.

    Options are:

    A command line scheduler called "at".
    Code:
    D:\bmpw>at /?
    The AT command schedules commands and programs to run on a computer at
    a specified time and date. The Schedule service must be running to use
    the AT command.
    
    AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
    AT [\\computername] time [/INTERACTIVE]
        [ /EVERY:date[,...] | /NEXT:date[,...]] "command"
    
    \\computername     Specifies a remote computer. Commands are scheduled on the
                       local computer if this parameter is omitted.
    id                 Is an identification number assigned to a scheduled
                       command.
    /delete            Cancels a scheduled command. If id is omitted, all the
                       scheduled commands on the computer are canceled.
    /yes               Used with cancel all jobs command when no further
                       confirmation is desired.
    time               Specifies the time when command is to run.
    /interactive       Allows the job to interact with the desktop of the user
                       who is logged on at the time the job runs.
    /every:date[,...]  Runs the command on each specified day(s) of the week or
                       month. If date is omitted, the current day of the month
                       is assumed.
    /next:date[,...]   Runs the specified command on the next occurrence of the
                       day (for example, next Thursday).  If date is omitted, the
                       current day of the month is assumed.
    "command"          Is the Windows NT command, or batch program to be run.
    Although I've not tested it, this will aparrently launch a program invisibly. However, setting advanced rules like "every 15 minutes" can't be done. For that you actually need to run a script on startup to generate AT events at the exact time. Fairly easy to script, and run at startup once a day (would appear, but once for the entire day could be acceptable.
    I also don't know if it's remembered if you reboot.

    Second up, which I got less help from MS on since they have a separate developer assistance helpline for VB scripting. However, from my new friend in Brazil, a VB script like this, should launch a process quietly.
    Code:
    CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
    I have no idea what it all means, except that "WScript.Arguments(0)" inserts what you want to run from the command line: e.g.
    Code:
    silent.vbs webcam.bat
    Not sure if the items then launched from webcam.bat would have to be launched using the same vbscript or not, have to try it. Also, have a feeling that specifying (0) for the WScript.Arguments will kill any extra parameters you give the eventual target program or script. Need to look up a bit on VB array handling to find out whether I can just have "WScript.Arguments" to spew out the entire command line.

    But there we have it - hopefully some food for thought and something which will help someone, some day.

    Regards,

    Shovel.
     
  18. MrBlack

    MrBlack Fledgling Freddie

    Try pycron (http://www.kalab.com/freeware/pycron/pycron.htm) a lightweight freeware python-based implementation of the ubiquitous unix cron.

    It installs as a windows service and you can set it to run anything using the crontab file. I use to fire some audit scripts at work. You have to allow the servie to interact with the desktop to allow some batch files to run correctly, but they're still run silently. (Youd don't see anything pop-up)

    the only other drawback it has is the typical cron hang-up of only running once a minute. (seconds are in the future feature list)

    MrB.
     
  19. phlash

    phlash Fledgling Freddie

  20. chelgrian

    chelgrian Regular Freddie

    The problem with doing this being that anything the program prints to standard error or standard out gets lost. Of couse for most Win32 programs running in the Windows rather than Console subsystems, which have no concept of being attached to input and output streams anyway it doesn't make much odds.
     
  21. Crusader

    Crusader Fledgling Freddie

Share This Page

  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.