I am using the code below to start ror server. Is there a easy way to quit that window without going through the route of finding the pid and using 'taskkill'? I mean after all i have the handle in 'shell' variable don't I?
shell = WIN32OLE.new('Shell.Application')
shell.ShellExecute("run_app_server.bat")
With the above code a window running ror server shows up. Now I also want to quit it from within the code.
Thanks
Well, you have a reference to an ole automation Shell object, but once you use ShellExecute to start a process in it's own window, that process belongs to Windows and I don't believe it's exposed in any way via the shell automation object - so there's no way to use an object reference to terminate it.
Rather than using Taskkill from a shell, though, you could also do the search & kill via automation like you're doing now - maybe adapt or "translate" this Perl script that does it.
Related
I have variable stand alone shell routines which I execute one after another automatically. Since every routine produces several X-windows figures I want to close all of them at the end without modifying every single routine. Is there a certain command?
Cheers!
Based on answers to this question. xdotool looks like what you need.
To kill an X11 window given it's title, you can use:
xdotool search "Your window title here" windowkill
Windows are owned by processes. One way to close windows is to kill their owner processes.
Another way is to start another X server, run your scripts with DISPLAY environment variable referring to the display of that X server, then terminate that X server with all windows.
So I've done some digging to try and find a way to run a script in the background on startup. The only solution I've found is to use:
Set WinScriptHost = Nothing
Is this a reasonable way to do it? Or could it cause some issues? I mean, from what I can tell, it just stops WinScriptHost from being used to refer to an object. But I feel like that could cause trouble in some scripts. So, should I avoid using this method and do something else?
Thanks!
CScript is for console windows, consoles programs by their definitions have a console. WScript is for GUI programs, unlike console programs, windows are optional (although almost all programs will create a hidden main window if not creating a visible window, as windows are how Windows communicates with a program).
Using WshShell.Run, which has a window style parameter, you can run cmd hidden eg cmd /c cscript script.vbs.
I am using nant, but this can apply to any thing, I just want to know if there is a way to set windows cmd or console2 or some kind of shell to give me a popup or make a noise when it is "finished" (i.e. when it is waiting and the screen says >C:\User\Random_FILE_PATH>_)
I'm using windows 7.
Valentine
sorry, to clarify, I am not running a script that I created, this is just when running anything in the console. I would like it to be that anytime my console is waiting for me it creates a pop up or a noise. This would ideally be some kind of setting
You may open a message box in the end of your batch file, using WSH with a simple VBScript or JScript. See Show a popup/message box from a Windows batch file for an example.
c:\> my_command & mshta.exe vbscript:Execute("msgbox ""finished"",0,""finished"":close")
this here uses conditional execution - when my_command is finished the mshta.exe will be executed with arguments in the brackets.As the parameter passing here is not so easy the string given to msgbox will not be displayed.
you can add a beep to your prompt:
set prompt=%prompt%^G
Don't type ^G. To get it, keep your alt-key pressed while entering 0 0 7 on your numeric keyboard.
When I have a Win32 non-console application (AFAIK, the console-ness of a Win32 app is linked into the exe), starting it from the console cmd.exe will return to the command prompt immediately, running the application "in the background" (o.c. it can have a GUI of sorts, or even open its own console window)
Is it possible in the non-console executable to detect that it was launched from cmd.exe and "attach" it to the launching cmd.exe?
And note that there are various questions/answers related to this, but it seems that this exact approach hasn't been investigated. (Maybe it's not possible like that.)
You can do this very easily. Simply pass ATTACH_PARENT_PROCESS to AttachConsole.
Whether or not the end result is sensible or practical is something I could not say. Both processes would read and write to the same console which could get pretty weird.
I want to have SlickEdit control another window.
I have an idea of how this could be done using some window’s apis but I am not sure how to implement this in SlickEdit. I am assuming Slick-C (SlickEdit's macro language) would be used. I have done some limited coding in Slick-C but I am not sure if window apis can be run.
Here is what I want done using windows API.
BringWindowToTop (This will bring the other window to the top)
SetForegroundWindow
Simulate pressing the F7 in the other window by using SendKey.
SendKey is a method in WScript.Shell .
It sounds pretty straight forward, all I need to know is how to do it in SlickEdit.
Update:
I pretty much used the concept jussij outlined but in a language I am familar with called PL/B. I already had most of these APIs working for another process, so it was pretty easy to create this new program and had SlickEdit shell out to run the program.
Here is what was needed inside of SlickEdit:
_command BenShellSAV1P198() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL|VSARG2_READ_ONLY)
{
save_all();
shell("T:\\Sunbelt\\CODE\\plbwin.exe -h -i PlbBenTDSm.INI SAV1P198.PLC","N");
}
Then I bound that macro to a hot key and it all works just fine.
SendKey is a method in WScript.Shell.
I am pretty sure everthing you describe can be done at the WScript level.
So you could write a script that does all the work and once you have it working, just add it as a tool to SlickEdit by running the script using the cscript.exe executable.