executing batch file from snapin

  • Is there anyway I can execute a batch from FOG snap argument.? I have batch file which copies 2 files from network drive to user’s local pc in FOG_PATH (c:\progra Files\FOG\tmp). The snapin works fine. I can verify that the fog snap creates test file in fog path. I have to manually double click this file in order for batch file to execute and copy 2 files. I am trying to avoid user double clicking and running this file. I tested the batch file and it works.
    How can I run this batch file without double clicking it? Can I type any snapin run argument which will run this batch files? I have FOG 1.3.0 RC-37 on Ubuntu 14.04.


  • Tom & JJ,

    Thank you for your help. I will make changes to batch script and add full path to networkdrive and modify my script as you both suggested. On last Friday before going home. I un-installed the FOG client on PC , re-installed it and my batch script was there. I waited for about 1/2 hours to see if this file gets deleted from C:\Program Files\FOG\temp folder but it was still there. I will follow your suggestions and let to you know.


  • Senior Developer

    TL;DR; Looking in the FOG installation tmp folder for where your script is running is not how your script is logically written. You should check the C:\Temp folder. (Maybe it’s not doing what you want because the C:\Temp folder doesn’t event exist?)

    I think this is what’s interesting to me.

    First, the messages of:
    @Olduser said in executing batch file from snapin:

    but when I go to C:\Program Files\FOG\tmp, it is empty. If I run script manually, it run without any problem. I see copy file in C:\Temp directory.

    You’re confusing yourself, as well as us, with the insistence of when i go to C:\Program Files\FOG\tmp

    As already stated numerous times, the C:\Program Files\FOG\tmp (or C:\Program Files (x86)\FOG\tmp) is the temporary holding point for the snapin being downloaded (then executed). Once the snapin is complete with installation the files used are cleaned up. This means the file will no longer exist.

    The Confusion, I believe, is you may be checking the wrong place to see if the snapin did, or didn’t, work properly. Items 1-2 are kind of hand-in-hand.

    1. Does the C:\Temp folder exist on the system? (Maybe before you try copying you should add mkdir %SYSTEMDRIVE%\Temp)
    2. Is 😄 the drive letter for your OS (I’d recommend changing the 😄 portion to %SYSTEMDRIVE%)
    3. When checking if the snapin did what you want make sure you’re looking in the place the script is trying to write to. (In your case it’s currently C:\Temp) It will not exist in the FOG\tmp folder except when it’s downloading and executing. That and your script is NOT writing anything to the FOG\tmp.
  • Moderator

    @JJ-Fullmer The only tweak I might suggest to your excellent code is that you could make the password for the share a batch variable like %1 and then pass that from answer from FOG so the password never exists in the batch script at all in case it was left behind for some reason after the snapin exited. It would be passed from FOG (assuming you can add switch variables inside the snapin setup). That part I don’t know because I don’t personally use snapins. Either way you could probably call the batch file with cmd.exe /c test.bat password and that should do it.

  • Testers

    @george1421 And thank you good sir.

  • Testers

    @george1421 Oh darn, I meant to also mention you in that comment saying that you were right and I was taking it a step further. So pretend I did that, and no I don’t know what an edit button is.

  • Moderator

    @JJ-Fullmer Well done!! I wish I could upvote your post more that just +1.

  • Testers

    I would suggest using the full path of the file in your batch script instead of changing the directory.
    And when I say full path, I mean the true full path, not the mounted S:\ drive.
    Even if S:\ is being mounted by active directory or is a mapped drive as part of your image, I would still suggest using the full network/unc path.
    I would also suggest mounting it with net use and a username and password. This will ensure the system account that the Fog Service uses has access to the files you want
    I would also add some logging and other error preventions.

    i.e. if S:\ was mapped to \FileServer\Share …

    @ECHO off
    echo. Create variables to make scripting easier
    set sharePath=\\FileServer\Share\Pat
    echo. Mount S drive path, replace username and password with share credentials. 
    echo. If share is public omit the /USER parameter and everything after it
    net use %sharePath% /USER:username password
    echo. make sure destination exists, create it if it doesn't
    if not exist C:\temp mkdir C:\temp
    echo. copy each file, add /Y to overwrite without any prompt
    echo. copying tdpunt...
    copy /Y %sharePath%\tdpunt.bat C:\temp\ > C:\temp\tdpunt-bat-Copy.log
    echo. copying tundpt.exe...
    copy /Y %sharePath%\tundpt.exe C:\temp\ > C:\temp\tundpt-exe-Copy.log
    echo. Done!

    Use that and then see if the .log files show up after deploying the snapin.

    Also, in the web gui snapin config, you should take out the /qn that does nothing.
    The snapin arguments section is for custom arguments that you have in your script. Your script doesn’t do anything with the /qn and it could cause issues. The /c parameter is passed to the cmd.exe command which tells cmd.exe to open a prompt, run the command, and then close.
    If you had a line in your script like this

    if "%1" == "/qn" (
        echo. hey look a parameter, lets do something since it's there!

    then the /qn would have a point.

    Hope that helps a bit.


  • Tom,

    I am also pasting fog log below:

     1/6/2017 11:32 AM Client-Info Client Version: 0.11.7
     1/6/2017 11:32 AM Client-Info Client OS:      Windows
     1/6/2017 11:32 AM Client-Info Server Version: 1.3.0-RC-37
     1/6/2017 11:32 AM Middleware::Response Success
     1/6/2017 11:32 AM SnapinClient Snapin Found:
     1/6/2017 11:32 AM SnapinClient     ID: 291
     1/6/2017 11:32 AM SnapinClient     Name: test
     1/6/2017 11:32 AM SnapinClient     Created: 2017-01-06 16:32:21
     1/6/2017 11:32 AM SnapinClient     Action: 
     1/6/2017 11:32 AM SnapinClient     Pack: False
     1/6/2017 11:32 AM SnapinClient     Hide: False
     1/6/2017 11:32 AM SnapinClient     Server: 
     1/6/2017 11:32 AM SnapinClient     TimeOut: 0
     1/6/2017 11:32 AM SnapinClient     RunWith: cmd.exe
     1/6/2017 11:32 AM SnapinClient     RunWithArgs: /c
     1/6/2017 11:32 AM SnapinClient     Args: 
     1/6/2017 11:32 AM SnapinClient     File: test.bat
     1/6/2017 11:32 AM Middleware::Communication Download:||00:00:00:00:00:00:00:E0&taskid=291
     1/6/2017 11:32 AM SnapinClient C:\Program Files\FOG\tmp\test.bat
     1/6/2017 11:32 AM Bus {
      "self": true,
      "channel": "Notification",
      "data": "{\r\n  \"title\": \"Installing test\",\r\n  \"message\": \"Please do not shutdown until this is completed\"\r\n}"
     1/6/2017 11:32 AM Bus Emmiting message on channel: Notification
     1/6/2017 11:32 AM SnapinClient Starting snapin...
     1/6/2017 11:32 AM SnapinClient Snapin finished
     1/6/2017 11:32 AM SnapinClient Return Code: 0
     1/6/2017 11:32 AM Bus {
      "self": true,
      "channel": "Notification",
      "data": "{\r\n  \"title\": \"test Installed\",\r\n  \"message\": \"Installation has finished and is now ready for use\"\r\n}"
     1/6/2017 11:32 AM Bus Emmiting message on channel: Notification
     1/6/2017 11:32 AM Middleware::Communication URL:||00:00:00:00:00:00:00:E0&newService&json
  • Moderator

    @Olduser If it was me, I would create some conditional tests.

    Does the S: drive exist
    Does the user account running this batch copy script have user rights to S:
    Does the path S:\PAT exist
    Does the file tdpunt.bat exist in the path S:\PAT
    Does the C:\Temp path exist, if not then create it
    Write the negative results of your tests to a log file in C:\Temp to help you figure out what went wrong.

  • Tom,

    Thank You very much for reply. I am also trying to figure out why snapin will install the batch script sometimes and other time nothing happens. I see a message that "Test installed " on taskbar but when I go to C:\Program Files\FOG\tmp, it is empty. If I run script manually, it run without any problem. I see copy file in C:\Temp directory.

    The batch script does this:0_1483714596462_fogforum.png


  • @Olduser As @Joe-Schmitt and others have said, C:\program Files\FOG\tmp is temporary.

    Files in that directory are not permanent. As soon as the snapin is complete, files in there are immediately deleted forever. Gone. Purged.

    Please post a copy of your script so we can help you more.

  • Senior Developer

    @Olduser Do you have the Batch file you originally uploaded? Please post that, or even just the source code directly. Telling us the same thing over and over isn’t helping much.

    We need to know what your script is trying to do, and why it’s not doing what you’re expecting it to do.

  • Wayne,

    I am selecting Batch Script Template when I created the snapin. I am still having problem. Sometime I see the file in fog path other time nothing there. There are no error in fog log.

    I will try to deply snap in to another machine,see if there is any issue with this Dell Optiplex 790.

    Thank you,
    Old user

  • @Olduser Joe is right. Can you post your batch file? What’s the end goal? Feel free to replace sensitive stuff in your batch file with made-up stuff that is otherwise valid in it’s syntax.

  • Wayne,
    Sorry I was away for for few days. Again thank you for the assistant. I created snap in exactly in the picture above. I also created a share folder and it is shared with Anonymous login with read only access.Whenever I deploy it, the client machine display “test installed, Installation has finished and now ready for use”. When I go to C:\program Files\FOG\tmp folder , there is nothing there. I have attached my snap in screen shot. I am using fog 1.3.0- RC37 on Ubuntu 14.04. I am not sure why sometime C:\program Files\FOG\tmp folder will display test file but another time it does not.

    0_1483547921529_snapin screenshot.png 0_1483547971113_Share folder.png

  • Following up on this, below is a screenshot of what I was talking about.
    Also there are some wiki resources below too.


    0_1483493378311_Snapin batch template.png

  • You can deploy a batch file via fog snapins. There’s a batch file template for it in the web interface even.