Saturday, January 29, 2011

Run a batch file silently, executed at remote desktop login

In our office we are using Linux thin client machines, they work very well except the lack of IE, which is a pain because the corporations we deal with are too stupid to update their web apps (no flame wars please).

To solve this problem we have machine in our computer room which users remote desktop into to access internet explorer, this is achieved by running a batch script which opens IE and when it closes logs them off, this setup works well for us.

Even though I have @echo off and the cmd window isn't displaying anything, I would really like that batch file to be executed silently, so the cmd window doesn't appear at all.

Is this possible?

The Ubuntu terminal server client has an option to launch a file / app at login, is there a command I can use to run this batch silently.

I have tried these:

C:\my_batch.bat /NOCONSOLE
C:\my_batch.bat /NOWINDOW
C:\my_batch.bat /B
C:\my_batch.bat /Q

...with no success, perhaps it's the way I am doing it?

Cheers :-)

Edit

The remote desktop platform is a Windows XP machine, nothing entirely special but not a Windows Server setup.

  • If you don't mind the batch file executing whenever any user logs on (i.e. via terminal services or locally), then:

    1. Save your .cmd file to a location where all users have read only access. (e.g. %WINDIR%)
    2. Launch gpedit.msc from a command prompt
    3. Navigate to User > Security > Scripts > Logon
    4. Add a new script, and point it to wherever you saved your .cmd file

    The script should run silently without showing a command prompt window.

    If you don't want it to run when a user logs on locally, it is probably possible to detect this in your batch file and silently abort the script.

    Bryan : Disclaimer: The path in step 3 is from memory, as I don't have a windows PC in front of me to check.
    From Bryan
  • Perhaps try

    start /b my_batch.bat
    

    the /b parameter is used to

    Start application without creating a new window. The
    application has ^C handling ignored. Unless the application
    enables ^C processing, ^Break is the only way to interrupt
    the application
    
    From smoak
  • Instead of using a batch file, why don't you create a Group Policy that forces the user shell to be Internet Explorer. This should achieve the behavior you want without any scripts at all.

    user configuration -> administrative templates-> system -> custom user interface

    Another alternative would be create a vbscript and use that via thw windows scripting host instead of a batch file. Scripts launched with wscript will not spawn a new window. What is your batch file doing? It should be easy enough to simply convert it WSH.

    From Zoredache
  • You can't run a batch script hidden if run it like this. But it's possible with a little VBS.

    Just execute the VBS file and it will run the Script hidden

    Dim oShell
    Set oShell = WScript.CreateObject ("WScript.Shell")
    oShell.run "cmd /C C:\my_batch.bat",0,false
    Set oShell = Nothing
    

    See this msdn article: http://msdn.microsoft.com/en-us/library/d5fk67ky%28VS.85%29.aspx

    From grub
  • The remote desktop application is in fact using said batch file as an alternate shell, and I don't think parameters can be passed using this method.

    Therefore I will have to live with my console window.

    From ILMV

0 comments:

Post a Comment