Suppress .CMD windows [RESOLVED] mControl cmd line
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
Suppress .CMD windows [RESOLVED] mControl cmd line
Ok this is a long shot but does anyone know of an easy way to suppress hide commands (.cmd) when they are run?
I looked at this in the past and don't remember finding any easy way to do it.
I have several .cmd files on my HTPC C:\ drive that run commands to my home automation controller (mcontrol) to turn lamps on and off in the living room. I then mapped custom buttons with keyboard shortcuts on my Harmony remote control to run these lighting command files via Autohotkey.
Anyways the black command windows pops up over what ever application is running and then disappears once the command has been executed, ideally I don't want to see them pop up at all.
Cheers.
UPDATE:
I documented my setup on a blog post.
http://windowsmediacenter.blogspot.com/ ... ol_30.html
Basically its describes how to use wGet to send SOAP commands to the mControl Web Service to control devices and run macros - from your Amulet voice remote or Logitech Harmony remote control!
I looked at this in the past and don't remember finding any easy way to do it.
I have several .cmd files on my HTPC C:\ drive that run commands to my home automation controller (mcontrol) to turn lamps on and off in the living room. I then mapped custom buttons with keyboard shortcuts on my Harmony remote control to run these lighting command files via Autohotkey.
Anyways the black command windows pops up over what ever application is running and then disappears once the command has been executed, ideally I don't want to see them pop up at all.
Cheers.
UPDATE:
I documented my setup on a blog post.
http://windowsmediacenter.blogspot.com/ ... ol_30.html
Basically its describes how to use wGet to send SOAP commands to the mControl Web Service to control devices and run macros - from your Amulet voice remote or Logitech Harmony remote control!
Last edited by cw-kid on Tue Aug 30, 2011 12:34 pm, edited 6 times in total.
-
- Posts: 2623
- Joined: Wed Jun 08, 2011 3:15 am
- Location:
- HTPC Specs:
Create a VBS script with the following code (just create a new text document, paste this code in it, then rename it to whatever you want to call it and change the extension from TXT to VBS):
Instead of running the CMD file, run this with the CMD file as an argument. For example, let's say you save the VBS file as INVISIBLE.VBS and have a CMD file called DOSOMETHING.CMD. Instead of running DOSOMETHING.CMD, you run:
Code: Select all
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
Code: Select all
C:\INVISIBLE.VBS C:\DOSOMETHING.CMD
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
Richard
thanks for the reply, I will definitely try this later when I have some more time.
Will let you know if I get stuck
Cheers.
thanks for the reply, I will definitely try this later when I have some more time.
Will let you know if I get stuck
Cheers.
-
- Posts: 111
- Joined: Sun Aug 07, 2011 2:14 pm
- Location:
- HTPC Specs:
try this.
Create a shortcut to the command (right click -->create shortcut)
in the shortcut properties select "run minimized" (right click --> properties --> RUN Minimized)
Now whatever runs the cmd have it run the shortcut
Create a shortcut to the command (right click -->create shortcut)
in the shortcut properties select "run minimized" (right click --> properties --> RUN Minimized)
Now whatever runs the cmd have it run the shortcut
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
Hellowinterescape wrote:try this.
Create a shortcut to the command (right click -->create shortcut)
in the shortcut properties select "run minimized" (right click --> properties --> RUN Minimized)
Now whatever runs the cmd have it run the shortcut
thanks for your suggestion, I have used this method before when wanting to run commands from the Windows Startup folder. So I place the shortcut to the cmd file in to the startup folder instead. It does work well in this situation.
However I am not sure I would be able to call shortcuts to run cmd files in an Autohotkey script?
Basically I have four .cmd files. The command files contain wget commands to send soap requests to the mControl home automation http server. There is also four xml files one associated to each of the .cmd files, these xml files contain the actual requested action to be sent to the mControl server for example turn On device ID 3 (turn on left lamp) You don't need to know any of this but just so you can see what I am trying to do.
So on my Harmony remote control I taught it four new keyboard commands for example Ctrl+Alt+A Ctrl+Alt+B Ctrl+Alt+C and Ctrl+Alt+D I then have an autohotkey script running on the HTPC that contains the following:
^!A::
IfWinExist Untitled - Left Lamp On
WinActivate
else
Run C:\Lights\Lounge-On-Left.cmd
return
^!B::
IfWinExist Untitled - Left Lamp Off
WinActivate
else
Run C:\Lights\Lounge-Off-Left.cmd
return
^!C::
IfWinExist Untitled - Right Lamp On
WinActivate
else
Run C:\Lights\Lounge-On-Right.cmd
return
^!D::
IfWinExist Untitled - Right Lamp Off
WinActivate
else
Run C:\Lights\Lounge-Off-Right.cmd
return
This works if I press my new custom button on the harmony remote control to turn on left lamp it sends Ctrl+Alt+A via IR autohotkey then picks this up and then runs the command C:\Lights\Lounge-On-Left.cmd the command window then pops up on the TV screen (which is the problem) and the left lamp turns on.
I did briefly try Richards suggestion but it didn't seem to do anything, I need to spend more time and have another go with the vbs files.
Last edited by cw-kid on Mon Aug 29, 2011 6:38 pm, edited 2 times in total.
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
Richard
Your suggestion is working but not with autohotkey.
I created a VBS file called Run-CMD.vbs and saved it in C:\Lights in the vbs file is just the code line:
If I use the Run dialog box from the Windows Start Menu and enter:
C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd
The right lamp turns off and no command window ever pops up or can be seen, so this is looking good!
It also works from a command prompt if I manually type in: C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd
However when I try to run the same line from within the autohotkey script I get a Windows Script Host error:
This is what I have in the autohotkey script to run the vbs file etc...
^!D::
IfWinExist Untitled - Right Lamp Off
WinActivate
else
Run C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd
return
Run-CMD.vbs is in the C:\Lights folder also the Lounge-Off-Right.cmd file is also present in the C:\Lights folder, so I am not sure why the error is about not being able to find the file.
Your suggestion is working but not with autohotkey.
I created a VBS file called Run-CMD.vbs and saved it in C:\Lights in the vbs file is just the code line:
Code: Select all
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd
The right lamp turns off and no command window ever pops up or can be seen, so this is looking good!
It also works from a command prompt if I manually type in: C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd
However when I try to run the same line from within the autohotkey script I get a Windows Script Host error:
This is what I have in the autohotkey script to run the vbs file etc...
^!D::
IfWinExist Untitled - Right Lamp Off
WinActivate
else
Run C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd
return
Run-CMD.vbs is in the C:\Lights folder also the Lounge-Off-Right.cmd file is also present in the C:\Lights folder, so I am not sure why the error is about not being able to find the file.
-
- Posts: 2623
- Joined: Wed Jun 08, 2011 3:15 am
- Location:
- HTPC Specs:
That error box means there's no argument included....AutoHotKey isn't passing the louge-off-right.cmd argument. Looking in the AutoHotKey help, I found out that it doesn't accept spaces in the command without quotes. Put quotes around the command in AutoHotKey:
Code: Select all
Run "C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd"
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
I've got it working now with Autohotkey!
No popup command windows anymore!
I had to changed the autohotkey script to the below, I had to add the part that is in bold: C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Right.cmd
^!A::
IfWinExist Untitled - Left Lamp On
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On-Left.cmd
return
^!B::
IfWinExist Untitled - Left Lamp Off
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Left.cmd
return
^!C::
IfWinExist Untitled - Right Lamp On
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On-Right.cmd
return
^!D::
IfWinExist Untitled - Right Lamp Off
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Right.cmd
return
No popup command windows anymore!
I had to changed the autohotkey script to the below, I had to add the part that is in bold: C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Right.cmd
^!A::
IfWinExist Untitled - Left Lamp On
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On-Left.cmd
return
^!B::
IfWinExist Untitled - Left Lamp Off
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Left.cmd
return
^!C::
IfWinExist Untitled - Right Lamp On
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-On-Right.cmd
return
^!D::
IfWinExist Untitled - Right Lamp Off
WinActivate
else
Run C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Right.cmd
return
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
I tried it previously with quotes around as you suggested but got a different error with Autohotkey.richard1980 wrote:That error box means there's no argument included....AutoHotKey isn't passing the louge-off-right.cmd argument. Looking in the AutoHotKey help, I found out that it doesn't accept spaces in the command without quotes. Put quotes around the command in AutoHotKey:
Code: Select all
Run "C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd"
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
Richard
thanks for the tip, very happy now I can turn my lamps on and off with my harmony remote and I no longer see the popup commands..
Thanks again..
thanks for the tip, very happy now I can turn my lamps on and off with my harmony remote and I no longer see the popup commands..
Thanks again..
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
Also using the custom commands feature of the Amulet voice remote control I can call my .cmd files to turn the Z-WAVE lamps on and off by talking in to the Amulet remote which is even cooler! LIGHTS ON...
-
- Posts: 2623
- Joined: Wed Jun 08, 2011 3:15 am
- Location:
- HTPC Specs:
So having the quotes solved the problem?cw-kid wrote:Richard
thanks for the tip, very happy now I can turn my lamps on and off with my harmony remote and I no longer see the popup commands..
Thanks again..
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
No adding quotes gives me a different error in Autohotkeyrichard1980 wrote:So having the quotes solved the problem?cw-kid wrote:Richard
thanks for the tip, very happy now I can turn my lamps on and off with my harmony remote and I no longer see the popup commands..
Thanks again..
Adding an additional C:\Lights\ in front of the .cmd file name resolved the problem
C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Right.cmd
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
To complete this thread I thought I'd post some examples of my mControl .cmd and .xml files. Running these .cmd files which in-turn invokes the associated .xml file
I can send command line requests from my HTPC to the mControl HTTP Server on the WHS to run macros or just control devices individually.
I had to install wGet on my HTPC and also had to add the path of C:\Program Files (x86)\GnuWin32\bin in to the Windows Environment Variables PATH.
Run Marco Example:
Lounge-On.cmd
Lounge-On.xml
Macro ID 8 is the marco to turn my lounge lights on - to find out which macros have what macroID? I just opened the mControl webpage in IE from my WHS box http://whs01/mcontrol/ and then viewed the source code in IE and found the macroID's that way.
From Source Code
SystemMacros[8] = new myMacro(
8,
'Lounge On',
'MacroAllOn.gif',
2,
0,
'READY',
true,
true
Control Individual Device Example:
To determine the Z-Wave deviceID's of different Z-Wave modules I just looked in the mControl Z-Wave Adapter Utility on the WHS.
Lounge-On-Left.cmd
Lounge-On-Left.xml
This is a great way to make mControl on the WHS run macros or control devices from the command line from your HTPC.
This has enabled me to get my regular IR Harmony remote control to turn Z-Wave lights on and off and run macros by using learnt keyboard commands from my MCE IR Keyboard, such as Ctrl+Alt+A and then using Autohotkey on the HTPC to intercept the keyboard command and then run a mControl .cmd file.
Also my Amulet voice remote has become allot more useful now I can speak custom voice commands to have mControl do stuff.
I can send command line requests from my HTPC to the mControl HTTP Server on the WHS to run macros or just control devices individually.
I had to install wGet on my HTPC and also had to add the path of C:\Program Files (x86)\GnuWin32\bin in to the Windows Environment Variables PATH.
Run Marco Example:
Lounge-On.cmd
Code: Select all
wget -Onul --post-file=C:\Lights\Lounge-On.xml --header="Content-Type: text/xml; charset=utf-8" --header="SOAPAction: http://embeddedautomation.com/webservices/mControl/RunMacro" http://whs01/mcontrol/mServer.asmx
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<RunMacro xmlns="http://embeddedautomation.com/webservices/mControl">
<macroId>8</macroId>
</RunMacro>
</soap12:Body>
</soap12:Envelope>
From Source Code
SystemMacros[8] = new myMacro(
8,
'Lounge On',
'MacroAllOn.gif',
2,
0,
'READY',
true,
true
Control Individual Device Example:
To determine the Z-Wave deviceID's of different Z-Wave modules I just looked in the mControl Z-Wave Adapter Utility on the WHS.
Lounge-On-Left.cmd
Code: Select all
wget -Onul --post-file="C:\Lights\Lounge-On-Left.xml" --header="Content-Type: text/xml; charset=utf-8" --header="SOAPAction: http://embeddedautomation.com/webservices/mControl/SendCommand" http://whs01/mcontrol/mServer.asmx
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SendCommand xmlns="http://embeddedautomation.com/webservices/mControl">
<devId>3</devId>
<command>on</command>
</SendCommand>
</soap12:Body>
</soap12:Envelope>
This has enabled me to get my regular IR Harmony remote control to turn Z-Wave lights on and off and run macros by using learnt keyboard commands from my MCE IR Keyboard, such as Ctrl+Alt+A and then using Autohotkey on the HTPC to intercept the keyboard command and then run a mControl .cmd file.
Also my Amulet voice remote has become allot more useful now I can speak custom voice commands to have mControl do stuff.
Last edited by cw-kid on Mon Aug 29, 2011 4:25 pm, edited 1 time in total.
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
Richard
This is the error I got from Autohotkey when just adding quotes around it:
^!D::
IfWinExist Untitled - Right Lamp Off
WinActivate
else
Run "C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd"
return
This is the error I got from Autohotkey when just adding quotes around it:
^!D::
IfWinExist Untitled - Right Lamp Off
WinActivate
else
Run "C:\Lights\Run-CMD.vbs Lounge-Off-Right.cmd"
return
-
- Posts: 2623
- Joined: Wed Jun 08, 2011 3:15 am
- Location:
- HTPC Specs:
Ahh, yeah, I don't know why I didn't catch that in your AHK code. And looking back at the AHK help again, I see where the quote requirement is only required when AHK is running CMD with arguments:cw-kid wrote:No adding quotes gives me a different error in Autohotkeyrichard1980 wrote:So having the quotes solved the problem?cw-kid wrote:Richard
thanks for the tip, very happy now I can turn my lamps on and off with my harmony remote and I no longer see the popup commands..
Thanks again..
Adding an additional C:\Lights\ in front of the .cmd file name resolved the problem
C:\Lights\Run-CMD.vbs C:\Lights\Lounge-Off-Right.cmd
Code: Select all
When running a program via Comspec (cmd.exe) -- perhaps because you need to redirect the program's input or output -- if the path or name of the executable contains spaces, the entire string should be enclosed in an outer pair of quotes. In the following example, the outer quotes are shown in red and all the inner quotes are shown in black:
Run %comspec% /c ""C:\My Utility.exe" "param 1" "second param" >"C:\My File.txt""
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
I wanted to be able to do this for a long time being able to not see the .cmd windows popup, I remember doing quite a bit of research on it previously but never found a working solution. Your idea was very simple but works wonderfully. I am not a programmer myself so unless I can find step by step instructions I am usually totally lost.
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
I documented my setup on a blog post.
http://windowsmediacenter.blogspot.com/ ... ol_30.html
Basically its describes how to use wGet to send SOAP commands to the mControl Web Service to control devices and run macros - from your Amulet voice remote or Logitech Harmony remote control!
http://windowsmediacenter.blogspot.com/ ... ol_30.html
Basically its describes how to use wGet to send SOAP commands to the mControl Web Service to control devices and run macros - from your Amulet voice remote or Logitech Harmony remote control!
Last edited by cw-kid on Tue Aug 30, 2011 12:32 pm, edited 1 time in total.
- holidayboy
- Posts: 2852
- Joined: Sun Jun 05, 2011 1:44 pm
- Location: Northants, UK
- HTPC Specs:
Great project Stuart!
Nice write-up too
Nice write-up too
Rob.
TGB.tv - the one stop shop for the more discerning Media Center user.
TGB.tv - the one stop shop for the more discerning Media Center user.
- cw-kid
- Posts: 707
- Joined: Mon Jun 20, 2011 5:53 pm
- Location: United Kingdom
- HTPC Specs:
Been having a nightmare posting the source code examples on The Digital Lifestyle website they are all messed up. Anyways I've got a new link to my other blog and everything reads correctly on there.
http://windowsmediacenter.blogspot.com/ ... ol_30.html
http://windowsmediacenter.blogspot.com/ ... ol_30.html