Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Script Opens But doesn't work when launched by windows on startup


  • Please log in to reply
10 replies to this topic
skeddles
  • Members
  • 5 posts
  • Last active: Oct 22 2014 11:20 AM
  • Joined: 19 Oct 2014

So I finished my program, works 100%. Basically all it does it play sounds. It's simple.

 

Last thing I did was add it to the startup on windows. Did it through the registry.

 

It works. My program opens on startup. I know that it partially works, when I select things from the tray, the options change like they're supposed to.

 

Only thing is, it doesn't play sound. At all. Not the sound I tell it to play on start up, or the sound I tell it to play  when I hit keys.

 

If I relaunch the program, which replaces the old one, it works perfectly.

 

Any ideas? Is there some kind of permission issue with things lanched via the registry? Did it get launched too early and couldn't hook into the sound card?

 

 



Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

Are your speaker muted, or are some applications muted perhaps?

 

The following script works when I place it in MyDocuments and 2x click it

I can also copy the file (in windows explorer) and paste a shortcut into startup folder.

This shortcut in startup works when I log in

I have WIN7 64 bit

 

Please try it with your system

 

Spoiler

 

For more help, we need more information.

Please provide us details of your system, with Windows version  and a very simplified version of your script.



skeddles
  • Members
  • 5 posts
  • Last active: Oct 22 2014 11:20 AM
  • Joined: 19 Oct 2014

Thanks for the reply

 

Tried your script, and it works for me as well. But if you change SoundBeep, 750, 500 to SoundPlay, other.wav, it doesn't work again.

 

Here's my shortened version of my script, has the same problem:

RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, testscript, "%A_ScriptDir%\script.ahk"

#Persistent
#SingleInstance force

SoundPlay, other.wav

~a::SoundPlay, other.wav

So as you see, it should play a sound upon opening, and then again every time you hit the a key. If it starts with startup, it plays no sound, even with the hotkey. If you double click the script, it replaced the one that opened, and suddenly works.



GEV
  • Members
  • 1364 posts
  • Last active:
  • Joined: 23 Oct 2013

Try to run the script as administrator.

 

For more info read this.



skeddles
  • Members
  • 5 posts
  • Last active: Oct 22 2014 11:20 AM
  • Joined: 19 Oct 2014

Is there a special way to run startup programs as administrator? I tried checking off run as adminstrator under the properties menu of the file, but that just makes it not open at all on startup.



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
If your script is compilde this may work (source)
 
if not A_IsAdmin
{
    Run *RunAs "%A_ScriptFullPath%"
    ExitApp
}
also have you tried just putting a simple sleep "a bit of time" before the start of your sound?

to let most of windows start up before trying to play sounds...
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

skeddles
  • Members
  • 5 posts
  • Last active: Oct 22 2014 11:20 AM
  • Joined: 19 Oct 2014

If your script is compilde this may work (source)
 

if not A_IsAdmin
{
    Run *RunAs "%A_ScriptFullPath%"
    ExitApp
}
also have you tried just putting a simple sleep "a bit of time" before the start of your sound?

to let most of windows start up before trying to play sounds...

 

 

Yes it's a compiled script, both the full program, and the one I'm testing with.

 

I tried that admin code, and it didn't seem to change anything.

 

I tried the sleep thing, but my program doesn't work even if I take out the startup sound and just wait for a while before touching a hotkey. So no matter how long I wait, the program that gets launched on startup still wont play sound.



T_Lube
  • Members
  • 640 posts
  • Last active: Sep 09 2016 02:19 AM
  • Joined: 16 Oct 2014

One interesting thing that I have heard over the years is that you must be using a link and not the actual exe in the startup dir for it to startup correctly every time. Not sure if this is true but I don't have any issues with getting something to run for me on Startup and that is what I always do, and I am running as a non-admin on a server at work, just for data relative to the "RunAs" thing above.



Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

SoundPlay

 

Filename

     The name of the file to be played, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified.

 

 

 

I suggest adding this to your script to test the WorkingDir

 

f1::

msgbox %WorkingDir%

return



ErrorOnLine1
  • Members
  • 230 posts
  • Last active: Oct 05 2015 02:46 PM
  • Joined: 25 Dec 2012
Could it be as simple as changing this ... 
SoundPlay, other.wav 
 
to this?
SoundPlay, other.wav, wait
 
Here's an interesting concept that might work for you. It loads a wav file into memory and plays it in a loop from memory. Written by Skan. I just don't have the ambition to add another SHORTCUT to my StartUp Folder, joining the other 3 SHORTCUTS already there, then rebooting my computer to test it.
Spoiler


skeddles
  • Members
  • 5 posts
  • Last active: Oct 22 2014 11:20 AM
  • Joined: 19 Oct 2014

I suggest adding this to your script to test the WorkingDir

 

f1::

msgbox %WorkingDir%

return

 

Okay okay, now we're getting somewhere.
 

When launching the script normally, I get:

---------------------------
script.exe
---------------------------
C:\Users\Sam\Desktop
---------------------------
OK   
---------------------------

But when launched via startup, I instead get:

---------------------------
script.exe
---------------------------
C:\WINDOWS\system32
---------------------------
OK   
---------------------------

EDIT: So I added %A_ScriptDir% before my paths, and that seems to have fixed the problem in the test script. Will try with my full script and report back.

 

EDIT2: So it looks like that worked. Thanks everyone for commenting, you seem like a helpful / knowledgeable community.