-
Dec 13th, 2007, 04:20 PM
#1
Thread Starter
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|