executing an exe using sandboxie with parameters - windows

I have an exe written in cpp, which I would like to execute in a sandbox called Sandboxie.
The exe file is requesting for input (using cin command in cpp), the only way I found passing parameters not within argv but for cin is with echo command.
the output of the exe file will go to txt file.
basically, if my program asks for one input, the run command looks like this :
start "D:\Program Files\Sandboxie\start.exe" /B (echo 3) | exetorun.exe > result.txt
The problem I found here is that it just doesn`t work,
so the solution I found is taking the part of parameters pass and exe name to run and inserting it into a batch file (.bat) and running it from the sandbox.
like that :
start "D:\Program Files\Sandboxie\start.exe" /B "runExec.bat"
and runExec.bat will have :
( echo 3 ) | exetorun.exe > output.txt
The problem now is that I have the basic version of Sandboxie which does not let you define a folder for example that no matter what when you try to run a file from there - it will run it from the sandbox... so basically all my points of sandbox is ruined.
Moreover, the idea of making a batch file for that is pretty stupid I think...
The only solution I find that will be the pretties is finding a way to just run the command of executing the wanted file and passing the wanted paramter to it within the first command instead of creating a batch file that will execute those commands.
Does someone know a way in any aspect (another sandbox, how to run the command not from a batch file) that can solve this ?
Thanks !

Related

start an exe with bat and it's own location

Okay this is my ToolChain setup:
I got a bat script that is calling a further bat script
The second bat script is calling an .exe which is performing autoit's on a software like starting, saving and closing.
In other words: bat > bat > exe (AutoIt) > exe (a Parser)
Okay here is the issue, the software (Parser) that will be started at least is some kind of weird, it won't find important files, if it's not being started from the same directory.
So as example if i put my autoit .exe or my .bat file into the directory of the software and start it - all is fine. But if i move my exe or my bat scripts outside of the directory and call it, it won't find files to start working.
For exactly this reason i made a second bat file and tried to set the path (set PATH=%PATH%;D:/filetype/dbcparser/) but that didn't have any effect on my case; if i call every bat or exe file not from the directory, it won't work correctly.
I hope someone found something like this before and could give me a hint for a workaround.
I was in the same situation, but using cd before start worked for me(whole file):
#echo off
cd "<start here>"
start "" call "<start here>your.bat"
also if you have PATH problems, try even this:
#echo off
cd "<start here>"
set PATH=<something>;%PATH%
start "" call "<start here>your.bat"

Launch .exe from MATLAB m.file, path issues

I want to Launch and .exe file from an m-file in MATLAB. The .exe does not Launch when i try. In restPath, the path of the .exe included. I am coding in a Windows Environment using the command line. My idea was to pass the command to run the .exe to the command line.
command = restPath;
[status,cmdout] = system(command,'-echo');
The error message is; Error file .cfg not found...
Do you have any suggestions?
Best regards
Edit: The .exe is now launched in 2 iterations. 1. cd to file, 2. Launch
addpath(restPath);
command = horzcat('cd ',restPath);
[status,cmdout] = dos(command,'-echo');
execute = 'abc.exe';
[statusExe,cmdoutExe] = system(execute,'-echo');
The main issue that I see here is that you are using two separate commands for the cd and the execution. Once the cd command executes, the command line context is thrown away and you start with a new one when you execute the system command (so the cd has no effect).
I would suggest either concatenating the two commands into one using the '&' notation like the following:
[status,cmdout] = dos([command ' & ' execute],'-echo');
or you could change your Matlab workspace first using a standard cd command in your mscript and then execute the system command.
currentPath = pwd;
cd(restPath);
execute = 'abc.exe';
[statusExe,cmdoutExe] = system(execute,'-echo');
cd(currentPath);
It is also possible that the exe you are calling is expecting an additional input to point to the .cfg file (although this may not be an issue if you have that in the same directory as the exe and it expects it to be there).

Scheduling automated scripts suite run from schedular

So I tried and tried but couldn't figure out this one for some reason.
how can I run a task from a desired directory instead of System32 directory where cmd.exe is.
so, when I schedule a task and try to run it ..
command prompt suppose to go to "c:\users\aaa\bbb\ccc" and then pass the argument.
Instead, It's starts at c:\Windows\System32 and fails.
Could anybody help me with this please?
I really appreciate it.
Thank you.
EDIT --
so, now I have a run.bat file with following content in it ...
C:\Users\aaa\bbb\ccc\dd (location to my testrunner.bat file)
testrunner.bat Scripts/all.suite website-address ie (command for the task I wanna perform)
net stop schedule (since window is poping up and going away way to fast, I added this to stop it (not working))
type run.bat
#echo off
cd C:\Users\aaa\bbb\ccc\dd
rem this will show all files in dir
rem is the file you're expecting listed?
dir
rem notice how you can make comments with a leading rem(ark)
#echo starting scripts\all.suite
rem you have to change this to have the full path using Windows X:\dir\dir conventions
c:\home\Scripts\all.suite website-address
#echo done running scripts\all.suite website-address
#echo shutting down
net stop schedule
So its still not clear exactly to me your goal. The reason I added the cd c:\... command is that will **C**hange **D**irectory to the path specified.
This is what you need so you can "run a task from a desired directory instead of System32".
Copy everything from the first #echo off to the last net stop and using notepad, paste it into a file, fix command names and paths website-urls, etc, then save that file to c:\temp\testrunner.bat.
Open a cmd.exe window and test that the script works. Just paste c:\temp\testrunner.bat on to cmd-line and hit enter. If that works, then made an entry in the scheduler to run c:\temp\testrunner.bat . I don't know the specifics of running a script for scheduler, so look for clues on the input screen. Is the an option to run 'now'?
If the .bat file doesn't work from the command-line, then you have to fix the file before you try running it in the scheduler. As your command Scripts/all.suite website-address is a little vague, you'll do better to post a new question asking for help to fix the .bat file and use a sample command that people will be able to use on their PCs at home.
IHTH.

Build output from Visual Studio 2010 external tools in output window

I run a batch file as an external tool (by adding it in Tools->External tools) in VS2010 (I've checked the "Use Output Window" option). This batch file performs compilation as in VS command prompt. The project that I'm working on has makefiles for various folders, so I use the mk command to build.
In the batch file, I set up the VS environment and then run the following commands:
cd $directoryWhichContainsFileToBuild
mk
cd main //This directory contains the executable that is to be built
mk
I see the output of the first mk in the Output window but after that it just hangs. I also tried to use an echo after the first mk but even that doesn't get printed in the output window (the ones before it can be seen).
Somewhere I read that there is an issue with VS 2010 output window where it hangs after showing some output, although I couldn't really be sure that that is what's the issue here.
Do I need to enable some other VS setting? Has anybody else encountered this issue?
Thanks.
Update: I unchecked the "Use Output Window" and "Close on exit" option, and I see an extra statement: "Press any key to continue". On doing that however, their is no further processing of the batch file.
Update2: Got it to work by prefixing mk with "call".
Thanks all who tried.
It is always good in batch files to specify executables with full path and file extension instead of just the file name. This avoids often lots of problems.
Here was just mk used instead of mk.bat. Therefore on every compile the command line processor cmd.exe searches for mk.* and then checks if any of the found files have an extension listed in environment variable PATHEXT. The order of file extensions separated by a semicolon in PATHEXT defines the order of execution in case of a directory contains multiple mk.* files.
If a command being specified in a batch file not being an internal command of cmd.exe without path, command line processor searches first for a file with given name in current working directory. This is often one more cause of error. What is the current working directory on execution of the batch file?
Next if no file to execute can be found in current working directory, the command line processor searches in all folders being listed in environment variable PATH separated by semicolons.
So specifying in batch files edited only rarely an external application or another batch file with full path, file name and file extension, in double quotes if necessary because of 1 or more spaces in path or file name, helps command line processor to more quickly execute that application or batch file and avoids problems because of executable not found (unknown command).
Sure, when typing commands in a command prompt window, nobody wants to enter the executables with full path, name and extension. But for batch files it is always good to be not lazy and type files to be executed with full path and extension.
TripeHound has given already the explanation why the observed behavior occurred here.
If a batch file is executed from another batch file without using command call, the command line processor continues batch execution in the other batch file and does never come back. In a C/C++ program this is like using goto with the difference that parameters can be passed to the batch file containing the further commands to be executed next.
But running from within a batch file another batch file with call results in continuation of execution below the line calling the other batch file once the other batch file reaches end, except command exit is used in the called batch file without parameter /B.
So the solution here is using:
cd /D "Directory\Which\Contains\File\To\Build"
call "Path\Containing\Batch\File\To\Build\mk.bat"
rem With mk.bat not changing current working directory change working
rem directory to the directory containing the executable to be built.
cd main
call "Path\Containing\Batch\File\To\Build\mk.bat"
BTW: exit exits command processor, exit /B exits just current batch file. I'll give you three guesses why the parameter is B and not a different letter. Yes, B is the first letter of batch.
Writing as a separate answer instead of an update in the question itself as many readers see the header and skim to the answer: got it to work by prefixing mk with "call". (#TripleHound has also posted the conceptual reason for it in the comment above.)

Run an input file using an exe file with cmd

I am using Windows 7
How can i run an input file (text file of commands) in an exe progam in CMD please.
Using other questions on the site, i have tried:
CMD /c ""C:/Program Files/Mplus/Mpluswin.exe" "C:/Users/jj/Desktop/mplus/test_mplus.inp""
which opens the input file in the program but does not run it
and this, which opens the program, but not the script
CMD /c "C:/Program Files/Mplus/Mpluswin.exe" < "C:/Users/jj/Desktop/mplus/test_mplus.inp"
Does this depend on the exe program?
Edit:
At present, the first command above launches the exe program and opens the text file within it (this is a file of program specific commands that will read in data, run calculations and output automatically). I can then run the commands in the exe program that has been opened (by selecting run in a menu) . But, I would like to pass the file to the exe program and it to be run automatically, ideally in the background. I am not sure of the correct terminology to use, so sorry if my description is unclear.
I've just noticed that you enclosed the entire term in an extra set of double quotes, and used linux forward slashes - try this batch file and also see if there is any error message on the console.
#echo off
cd /d "%userprofile%\Desktop\mplus"
"C:\Program Files\Mplus\Mpluswin.exe" "test_mplus.inp"
echo mplus was launched
pause

Resources