Autohotkey - run command - autohotkey

I've encountered a problem I am having troubles to formulate, therefore I can't google it properly.
I have a script:
WheelLeft::
Run, "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE", "C:\Program Files\Microsoft Office\root\Office16"
Return
+XButton1::
Send, !{Right}
Return
WheelRight::
Run, "C:\Users\pavel\AppData\Local\GPMDP_3\app-4.4.0\Google Play Music Desktop Player.exe"
Return
which works fine, but the RUN commands do not start from everywhere. For instance, it does not start when I am using Chrome, but works fine from FileExplorer.
Could anybody please point me to a resource about this kind of problem?
Thanks in advance

Assuming AutoHotkey is up to date, I'd suspect it's simply Chrome hijacking your forward/back commands or fighting with AHK over it.
Before delving in further, try a tilde, which will pass through the command instead of consuming it after AHK acts on it.
~WheelLeft::
Run, Notepad.exe
Return
~WheelRight::
Run, Notepad.exe
Return

Related

Powershell hangs on Launch

When I run powershell ISE, I can execute commands/scripts without issue. When I launch either the 32 or 64 bit command line, the window takes about 30 seconds to load and then it is frozen. It will not accept inputs of any kind (keyboard or copy/paste). I have tried doing a system check, no errors. I even tried updating to powershell 4.0, the install was successful but the command line still locks on launch. Can anyone advise how to fix this? I am using windows server 2008 R2.
Update
It appears that the powershell is in fact accepting input, except at a glacial speed. I left the window open while I was writing this post initially, and then grabbed a coffee. Upon my return I found that what I have tried to copy/paste and type was now in the powershell command line. I have now attempted to execute $PSVersionTable.PSVersion, and going on 3 minutes now I still have no response. My guess is it will come back at some point but this is obviously not acceptable. Any ideas on how to debug/fix this?
Update2
As far as I can tell all the locations listed in $PROFILE | Select * don't exist. I also tried launching: powershell.exe -noprofile, but this did not help
After reading this post I decided to try that tool and see if I had a similar problem and discovered that there were literally hundreds of writes per second happening when powershell command line was running and they were all to the FusionLog. Disabling the Fusion logging fixed the issue completely (this was enabled a while ago to debug a different issue with an app and I must have forgotten to disable it). Everything else on the machine seemed to hum along just fine with FusionLogging in the background but powershell was horribly crippled. Hope this helps someone some day.

Unable to start program outside Windows folder

I'm trying to control an external program that I call inside PowerShell and if this program takes more than 10s, for example, I want to terminate it. How can I accomplish that?
I have searched, but what I found was the following code. I can use this code to call calc.exe for example, and terminate it after a specific amount of time, but I can't call another program that is not from system32 or Windows folder. Why?
$ps = New-Object diagnostics.processstartinfo
$ps.FileName='c:\folder\program.exe'
$p = [System.Diagnostics.Process]::Start($ps)
$p.WaitForExit(10000)
$p.Kill()
A very likely problem is that the program you are trying to run is an x86 application and you are trying to run it from powershell x64. This will not work and as far as I remember powershell will not even tell you why.
Instead you need to run the x86 version. https://technet.microsoft.com/en-us/library/hh847733.aspx

Cmd.exe no popup

I have to run cmd / c from a program, run the start command xx.exe, and I capture the result (there xx.exe?). until everything is right, however, remains open the console with the error popup. how can I close the console with the error?
Usually win32 applications will close the command prompt after execution. If this isn't the case with what you're trying to run, you could:
Run it from Windows "Run" option (Windows button+R) than your program name and path in prompt.
Run it from a batch file, like so:
runMe.bat:
START "" "C:\windows\notepad.exe"
EXIT`
Than just run runMe.bat from wherever. Notice the 'exit' command that closes the command prompt after execution.
Read more about batch files, the start command, and this issue here, and there.
Good luck!

Word 2010 /m switch from batch file

I'm trying to execute a Word macro from a batch file. The documentation here indicates that this is accomplished using the /mMacroname switch.
However, when I do this, I receive an "Invalid switch - /mMacroname" error. It seems I'm doing something wrong, but I can't for the life of me figure out what it is.
The name of the macro is FormatStrikethrough. It opens/closes/etc. the file on its own. I am invoking it like so:
start "C:\Program Files (x86)\Microsoft Office\Office14\winword.exe" /mFormatStrikethrough
Dropping the start from the command will make it work.
I believe this is because your parameters were being passed to start rather than the winword executable. As for how to use start to launch a program with switches,
This answer seems to tell you how to do that.

Powershell Script doesn't work when starting it by double-clicking

I got some strange behaviour when executing a powershell script.
When I run my script using the ISE it works just fine.
When I open Powershell.exe and run my script it works just fine.
When I open cmd, and start my script using powershell.exe -noexit
./myscript.ps1, myscript works just fine.
When I double-click myscript however, powershell opens for some milliseconds, I see that it shows some error (red font) and the powershell window closes. I'm unable to track down the error causing this problem since the powershell windows closes to fast.
I even tried one single big try-catch block around my hole script, catching any [Exception] and writing it down to a log file. However: the log file is not generated (catch is not called).
How can I track that issue? What could possibly be causing the trouble?
Please note that my execution-policy is set to unrestricted.
Before trying the suggestion invoke this to see your current settings (if you want restore them later):
cmd /c FType Microsoft.PowerShellScript.1
Then invoke this (note that you will change how your scripts are invoked "from explorer" by this):
cmd /c #"
FType Microsoft.PowerShellScript.1=$PSHOME\powershell.exe -NoExit . "'%1'" %*
"#
Then double-click the script, it should not exit, -NoExit does the trick. See your error messages and solve the problems.
But now all your scripts invoked "from explorer" keep their console opened. You may then
remove -NoExit from the above command and run it again or restore your
original settings.
Some details and one good way to invoke scripts in PS v2 is here.
Unfortunately it is broken in PS v3 - submitted issue.
by default, for security reason when you double clic on a .ps1 file the action is : Edit file, not Run file .
to execute your script : right-click on it and choose run with powershell
I also wasn’t able to run a script by double clicking it although running it manually worked without a problem. I have found out that the problem was in the path. When I ran a script from a path that contained spaces, such as:
C:\Users\john doe\Documents\Sample.ps1
The scipt failed to run. Moving the script to:
C:\Scripts\Sample.ps1
Which has no spaces, solved the problem.
This is most likely an issue with your local Execution Policy.
By default, Powershell is configured to NOT run scripts that are unsigned (even local ones). If you've not signed your scripts, then changing your default double-click 'action' in Windows will have no effect - Powershell will open, read the execution policy, check the script's signature, and finding none, will abort with an error.
In Powershell:
Help about_execution_policies
gives you all the gory details, as well as ways to allow unsigned scripts to run (within reason - you'd probably not want to run remote ones, only ones you've saved onto the system).
EDIT: I see at the tail end of your question that you've set Execution Policy to 'unrestricted' which SHOULD allow the script to run. However, this might be useful info for others running into execution policy issues.
If you would catch the error you will most likely see this
The file cannot be loaded. The file is not
digitally signed. The script will not execute on the system. Please
see "Get-Help about_signing" for more details.
Because you are able to run it from the shell you started yourself, and not with the right mouse button click "Run With PowerShell", I bet you have x64 system. Manually you are starting the one version of PowerShell where execution policy is configured, while with the right click the other version of the PowerShell is started.
Try to start both version x64 and x86 version and check for security policies in each
Get-ExecutionPolicy
I was in exactly the same situation as described in the question : my script worked everywhere except when double-clicking.* When I double-clicked a powershell windows would open but then it will close after a second or so. My execution-policy is also set to unrestricted.
I tried the selected answer concerning FType Microsoft.PowerShellScript.1 but it didn't change anything.
The only solution I found was a work around: create a bat file which start the powershell.
Create a file, copy this and modify the path : powershell.exe -File "C:\Users\user\script\myscript.ps1"
Save it as a .bat
Double-click the bat
I also used .ahk to start my powershell with a shorcut and it didn't work when pointing directly to the powershell. I had to point to the .bat