Run a hidden cmd on click - windows

This is driving me crazy. I have a pretty application that does.. well, things. To start it up, some start.cmd needs to be executed. What start.cmd does is to set up some environment variables, check a few things and then start my main GUI program.
Now, everything works fine: when I click on my start.cmd everything gets launched properly. However, clicking on start.cmd causes an ugly, ugly cmd.exe to appear for an instant and then disappear. This is unacceptable!
I started looking around and I found this. It suggests to use some wscript invisible.vbsto run my start.cmd. This, however, works fine from the terminal, but I can't click on invisible.vbs directly to get what I need.
This is where I thought that I could use shortcut with the wscript invisible.vbs start.cmd command in it. However, you cannot make relative path shortcuts in Windows, which means that if I use a shortcut I will never be able to move my folder again, which is pretty bad if I need to install it around my users' computers.
So I really have no clue on how to get this apparently trivial thing done: how can I get a start.cmd batch file executed without anything showing and without having to launch anything from the terminal, and in a way that will allow me to move my folder around?

Check the hidder.bat . You can use it to wrap a .bat or .exe file into iexpress executable file that will be ran in hidden mode.To use you need:
hidder.bat example.bat hiddenExample.exe
this line will create a hiddenExample.exe which clicked will start your bat in hidden/background mode.You can also take a look at this question

Related

Configure launch command in Code::Blocks

I recently discovered Emscripten, and after downloading it, I decided to see if I could get it to work with Code::Blocks, so that I could easily test my applications to see how they performed when running as JavaScript.
I created a new compiler configuration, and set up all of the toolchain executables, except for the resource compiler (which doesn't seem to give me any problems), and the debugger. I wasn't really sure what to put in the debugger, because I remembered the debugger field as being a text-box. But when I looked, all that was there was a drop-down menu.
I managed to find a "Debugger" menu in the "Settings" menu, and when I opened it, there was a button called "Create config".
I created a new configuration, and pointed the executable path to "node.exe" (which runs .js files). I then went back to the compiler settings, and chose my new debugger in the drop-down.
I then tried to build and run a simple hello world application. But once it finished building, it gave me the message Execution of '[my file] ' in '[my project folder] 'failed. The actual build seemed to be successful, so I decided to manually run node.exe from the command line to see if I had configured the debugger incorrectly. And as I expected, it ran successfully.
While I was glad that I had successfully configured the compiler, I still was confused as to why the app didn't want to run. I also set Emscripten to create HTML files instead, to see if Code::Blocks would somehow recognize the appropriate program, and open it in the web browser instead. Of course that didn't work either.
What I am trying to figure out, is how I configure Code::Blocks' run command. Perhaps the debugger isn't even the right place to be looking. But I really need someone to help me figure out how I can configure this in Code::Blocks, as this is currently the only thing that is really giving me any trouble.
Thanks.
Possible but less ideal solution:
After some time, I was able to come up with a solution. However, I am sure that there are better alternatives.
To use this method:
Create a new build target called RunScript.
Set the compiler to No Compiler.
In the project properties, set the type to Console application.
Uncheck Auto-generate filename extension, and set the output filename to RunButton.bat.
Create a new file called RunButton.bat (or whatever you entered as the output filename).
Whatever you put in RunButton.bat will now be executed when you click the run button.
I also created a new virtual target that contained my RunScript target, and my main target, so that I don't have to switch targets whenever I want to test my application.
Problems with this method:
While this method does work, it is not ideal, as it requires you to have two extra targets (including the virtual target that I made for convenience). I would rather be able to just have everything contained in one target.
Slightly better solution:
A new solution that I decided to use, is to simply use the configure tools menu to create a tool that points to a batch file that runs my compiled programs.
To use this method:
Go to Tools>Configure Tools...>Add.
Fill in the name, and point the executable to the script that you want to run when this tool is used.
Fill in any needed parameters. You can use the built in ${TARGET_OUTPUT_FILE} macro to pass your output application as a parameter.
You can now use your tool by going to Tools>{My tool}, but you can set a hotkey by going to Settings>Editor...>Keyboard shortcuts.
Click the plus button by Tools, and click on your tool to set a shortcut for you tool.
Problems with this method:
While this method does eliminate the extra build targets, it doesn't let you run your script or run non-executable files by clicking the run button; which was the original intent. On top of this, you have to create a new tool anytime you want to add a new script.
I am hoping that someone else will be able to show me a better way of doing this, but for now this will work.
Might be a little late, but I was able to get the codeblocks run button to run any command by using a few post-build steps. The reason I need this is because my laptop has nvidia "optimus" and in order for my output program to see the discreet graphics card, I have to run it with the optirun prefix. So I added the following to the post-build steps in build options:
mv $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE)_bin
echo #!/bin/sh > $(TARGET_OUTPUT_FILE)
echo optirun $(TARGET_OUTPUT_FILE)_bin >> $(TARGET_OUTPUT_FILE)
chmod +x $(TARGET_OUTPUT_FILE)
It basically renames the output binary and creates a script replacing the original output binary name. When pressing the run button, the script is executed instead of the output.
On windows, you might have an issue running an exe extensioned file as a batch script so what if you generate the output file with a bat extension like in your first method, but with compilation and then rename it to exe in the post-build like this:
move $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).bat $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).exe
echo [WHATEVER YOU NEED TO RUN] > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).bat

How to comfortably monitor variables in a VBscript during development process? (e.g. in a continuously opened command window)

I need to write a huge VBscript to automatically run an application and I'm looking for a way to comfortably monitor what I'm actually doing, in other words, to display the values of some/all variables involved in my script.
I'm used to work with Matlab, where I have a comfortable workspace browser. When I run a Matlab script, all variables, their types and their values are accessible in that workspace and can be checked.
The VBscript I write with Notepad++ (it needs to be a free editor) and the only way I found to display variables was echoing them via wscript and cscript.
I set up the shortcuts.xml with the following line to run my script directly from Notepad++:
<Command name="Run with CScript" Ctrl="yes" Alt="no" Shift="yes" Key="116">cmd /K %windir%\system32\cscript.exe "$(FULL_CURRENT_PATH)"</Command>
In case I include commands in my script like
Wscript.Echo myVar
Wscript.Echo "Hello World!"
and run it with the newly introduced shortcut, a cmd window pops up and displays the value of myVar and "Hello World!".
But the next time I run the script a new window pops up. So my question is:
Is it possible get a continuously opened output window, displaying all echoed values everytime I run a script? I actually want to put the window on a second screen and keep the values from previous runs. So I can enter a line Wscript.Echo something, run, check, enter something else and so on, without fiddling around with a bunch of opened windows.
Alternatively, is there any open-source/free editor which offers an accessible workspace like the one in Matlab?
The open-source editor SciTE offers what I was looking for.
The default settings in vb.properties enable a similar behavior like in Notepad++
command.build.$(file.patterns.wscript)=cscript "$(FilePath)"
command.build.subsystem.$(file.patterns.wscript)=1
One can change it as follows to get the output into the integrated console.
command.go.$(file.patterns.wscript)=cscript.exe //nologo "$(FilePath)"
command.go.subsystem.$(file.patterns.wscript)=0
F5 runs the script and Shift+F5 cleans the output.
Another option is the NppExec Plugin for Notepad++ suggested by #Ansgar Wiechers, which adds a console. The script can be run with cscript.exe /nologo "$(FULL_CURRENT_PATH)" then.
Use a debugger. Start your script with the (meta)option //X. If you are lucky, you already have installed software (MS Office, Visual Studio (Express)) that provides a debugger for VBScript. If not do a bit of research to find an Express version suitable to your OS.
You can almost write native VBScript in the VBA editor, so if you have Excel or whatever you can use this to debug, then go through some steps to convert back to VBScript. That's what I usually do.

open console (terminal) window and execute command (rsync) on os x

I am from a windows background and trying to help a mac user friend to backup her pictures, docs, etc. onto an external drive. In windows, I would accomplish this by creating a simple batch file with an xcopy command and have a shortcut on the desktop that pointed to that .bat file when double clicked. However, in the mac world I am having significant trouble finding how to do this. I have searched repeatedly to find the mac equivalent, but all I find are sites saying things like "there are so many options on a mac - use one of them." However, none have ever given a specific solution nor pointed to a specific solution. Anyone here know of a specific step by step process to accomplish this? I simply want to be able to have her double click an icon on the desktop and have it copy her personal documents (not application settings or other overhead) to her external hard drive. Any help would be appreciated.
Create the batch file, which is usually called a shell script.
Enter all the commands that you want to run.
Set the executable bit, this is done with chmod +x path-to-the-file in Terminal.
Show info for the script and set Terminal to the application which should open it.
However, what I've done in similar situations and that I would recommend that you do is that I've created a shell script and instead of using Terminal I've initiated it from an AppleScript application. You can of course embed the entire shell script in the AppleScript as well. Basically it will look something like the following:
on run
do shell script "rsync -av ~/Pictures /Volume/Backup"
end run
Repeat the do shell ... line for each folder that you want to copy, or call the shell script itself. Then use AppleScript Editor which is included with Mac OS X and save it as an actual application.

Is there any way to run a VBScript file as a screen saver?

Can you execute a VBS file as a screen saver? I have managed to rename cmd.exe to *.scr and this works, but I need to be able to run a VBS file as the screen saver if this is possible.
No, this is not possible.
In Windows, screen savers (*.scr files) are a special type of executable (.exe) file. That is why renaming a program like cmd.exe to cmd.scr causes it to sort of "work" as a screen saver. In particular, screen savers respond to certain command line switches (or parameters), which is how the OS gets them to do things like show the configuration dialog or display a preview.
But you can't compile VBScript files into executables, so there's no way to make this trick work for them.
You might be able to migrate the VBScript code to a VB 6 application, which you could then compile into an executable and run as a screen saver, but I can't imagine that this would be worth the development time. If you're interested in such a thing (and can get your hands on an old copy of VB 6!), you can probably find several how-to guides online, like this one.
But I'm honestly having a hard time imagining why one would ever want to run a VBScript script as a screen saver, or what it would display on the screen. You don't have very much control over what gets displayed on the screen, and you can't call down to native Windows API functions from VBScript. You'd end up relying upon some external library, so you might as well just use that library in the first place.
You can simply write a batch file that starts your vb script:
CD "%SystemRoot%\System32"
Start /Wait Wscript.exe "c:\program files\myscript.vbs"
Exit
Then compile the batch to exe, rename the exe to scr.

My Ruby files don't run correctly

When i click on a .rb file to run it a CMD window pops up for a brief second and then closes again. This is probably a really nooby question thats easily fixed but i've looked everywhere for help. But like i said it pops up for a brief second and i THINK while its up its executing the code but when the codes done it closes so i don't know if i'm making mistakes in code or other important things like that.
Run the program through the command prompt (CMD), that way you can see the result, otherwise the window closes when the program exits.
Alternatively, you can prevent the program from exiting by putting some sort of blocking instruction at the end of the script, such that the program waits for user input before exiting.
Press Windows_Key+R and then type CMD. Browse to the location of the file and then type ruby your_ruby_file.rb. The program is running, but Windows automatically closes the window upon completion of the command.
To get Windows to run your *.rb files through Ruby when you click on them in the UI, you have to associate the .rb extension with the ruby.exe executable. Such an association is called a "Windows File Association." Here's a Microsoft Knowledge Base article that'll tell you how to create such a thing.
http://support.microsoft.com/kb/307859

Resources