Problem closing a bat file? Hide it instead-VBForums
Results 1 to 2 of 2

Thread: Problem closing a bat file? Hide it instead

  1. #1

    Thread Starter
    Addicted Member silentthread's Avatar
    Join Date
    Jun 2006
    Location
    Miami, Florida
    Posts
    143

    Problem closing a bat file? Hide it instead

    We have this Citrix published application that we needed to run a bat file, that in turn runs a vbs script, that updates the user profile.

    So like the bat file would not go away. So then I wrote a vb.net app that calls the bat file, waits a couple of seconds, closes the bat file and closes itself. It did not work. Why, something silly with the components of the .net framework over a published application. We received error messages....

    System.Security.Permissions.EnvironmentalPermission, mscorlib, and bunch of other silly messages like this.

    So, I took the law into my own hands, and resorted back to one of the best programming languages in the world. C++.

    Below is the source code for an app that can help you launch a hidden bat file.


    Code:
    #include <iostream>
    #include <conio.h>
    #include <windows.h>
    #include <fstream>
    #include <string>
    
    #define n '\n'
    
    using namespace std;
    
    int main()
    {
    
    ifstream myifstream;
    myifstream.open("BatFileConfig.txt");
    
    if(!myifstream)
    {
    cout << "There was a problem trying to open the BatFileConfig.txt" << n;
    getch();
    }
    
    string pathtofileSTR;
    int timerpauseSTR;
    
    myifstream >> pathtofileSTR >> timerpauseSTR;
    
    myifstream.close();
    
    SHELLEXECUTEINFO ShExecInfo;
    ShExecInfo.lpFile = pathtofileSTR.c_str();
    ShExecInfo.nShow = SW_HIDE;
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = NULL;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = NULL;
    ShExecInfo.lpParameters = NULL;
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.hInstApp = NULL;
    
    ShellExecuteEx(&ShExecInfo);
    
    Sleep(timerpauseSTR*1000);
    
    return 0;
    }
    Here is the txt configuration file (BatFileConfig.txt). The 3 is the number of seconds it will wait before it closes the bat file and then itself.

    Code:
    mybat.bat
    3
    Watch media as you download it! Excellent tool!
    FREE CUBA!
    MyBlog
    If you feel my post has helped, please rate it.

  2. #2
    Banned
    Join Date
    Mar 2009
    Posts
    17

    Re: Problem closing a bat file? Hide it instead

    it is very tough to understand. You should use comments in the source code so that it make easy to understand your source code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.