| View previous topic :: View next topic |
| Author |
Message |
darklight_tr
Joined: 29 May 2008 Posts: 11 Location: Madison, WI
|
Posted: Wed Jun 18, 2008 6:28 pm Post subject: SOLVED: FileCreateShortcut problems with %A_Programs% |
|
|
Hello,
I've run into a bit of a snag with FileCreateShortcut. When you use the %A_Programs% variable with that command in Windows Vista, the shortcut is created in C:\ProgramData, not C:\Users. C:\ProgramData should be used when using %A_ProgramsCommon%.
The command behaves properly under Windows XP. This issue is Windows Vista specific.
Here is a sample of my FileCreateShortcut code:
| Code: | | FileCreateShortcut, "%InstallFolder%\blah.exe", %A_Programs%\Blah\Blah.lnk, %InstallFolder%, , Blah %ScriptVer% |
%InstallFolder% and %ScriptVer% are declared elsewhere in the script.
I've tested on Windows XP Pro SP2 and Windows Vista Enterprise SP1.
Any ideas on what I may be doing wrong, or is this a legit bug?
Last edited by darklight_tr on Fri Jun 20, 2008 7:30 pm; edited 1 time in total |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Thu Jun 19, 2008 6:31 am Post subject: |
|
|
for me
| Code: |
msgbox, %A_Programs%
|
gives
| Code: |
---------------------------
test.ahk
---------------------------
C:\Users\engunneer\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
---------------------------
OK
---------------------------
|
edit: I think i see your point, which is that the variable reads one thing, but the item is actually created elsewhere. I will have to test later. anyone else care to try? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 731 Location: The Interwebs
|
Posted: Thu Jun 19, 2008 7:18 am Post subject: |
|
|
This is interesting...
| Code: | installfolder=C:
ScriptVer=4.2
FileCreateShortcut, ""%InstallFolder%\blah.exe"", %A_Programs%\Blah.lnk, %InstallFolder%, , Blah %ScriptVer%
|
works fine, places it in "C:\Users\****\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" (exactly where A_Programs says it should). However,
| Code: | installfolder=C:
ScriptVer=4.2
FileCreateShortcut, ""%InstallFolder%\blah.exe"", %A_Programs%\Blah\Blah.lnk, %InstallFolder%, , Blah %ScriptVer%
|
Does nothing, and gives me an ErrorLevel of 1—meaning there was a problem. |
|
| Back to top |
|
 |
darklight_tr
Joined: 29 May 2008 Posts: 11 Location: Madison, WI
|
Posted: Thu Jun 19, 2008 4:44 pm Post subject: |
|
|
| engunneer wrote: | for me
| Code: |
msgbox, %A_Programs%
|
gives
| Code: |
---------------------------
test.ahk
---------------------------
C:\Users\engunneer\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
---------------------------
OK
---------------------------
|
edit: I think i see your point, which is that the variable reads one thing, but the item is actually created elsewhere. I will have to test later. anyone else care to try? |
Exactly. When I tried MsgBox like you did it shows the correct path but when you try using FileCreateShortcut it doesn't seem to follow %A_Programs% correctly. Its almost as if it just uses %A_ProgramsCommon% instead.
| Krogdor wrote: | This is interesting...
| Code: | installfolder=C:
ScriptVer=4.2
FileCreateShortcut, ""%InstallFolder%\blah.exe"", %A_Programs%\Blah.lnk, %InstallFolder%, , Blah %ScriptVer%
|
works fine, places it in "C:\Users\****\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" (exactly where A_Programs says it should). However,
| Code: | installfolder=C:
ScriptVer=4.2
FileCreateShortcut, ""%InstallFolder%\blah.exe"", %A_Programs%\Blah\Blah.lnk, %InstallFolder%, , Blah %ScriptVer%
|
Does nothing, and gives me an ErrorLevel of 1—meaning there was a problem. |
I didn't include it in my example code, but I created the %A_Programs%\Blah folder just before the shortcut is created so I don't run into that error.
UPDATE: I was able to discover the source of the problem. FileCreateShortcut works fine with %A_Programs% BEFORE the script is complied, but once you compile the script it no longer works properly.
It looks like the issue has something to do with the compiling process.
BTW, I am using the latest AutoHotkey v1.0.47.06. |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Thu Jun 19, 2008 7:26 pm Post subject: |
|
|
compiling doesn't change the function of the code. It may affect permissions, however. try running the compiled script as admin.
Does the folder exist before FileCreateShorcut is used? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
darklight_tr
Joined: 29 May 2008 Posts: 11 Location: Madison, WI
|
Posted: Thu Jun 19, 2008 8:15 pm Post subject: |
|
|
I am an admin on both machines I am testing on.
The script creates the folder before FileCreateShortcut is used.
Here is the whole code snippet that runs:
| Code: | IfNotExist, %A_Programs%\TR Tools\[Script Name]
FileCreateDir, %A_Programs%\TR Tools\[Script Name]
FileCreateShortcut, "%InstallFolder%\[Script File]", %A_Programs%\TR Tools\[Script Name]\[Script File].lnk, %InstallFolder%, , [Script File Description] |
You need to fill in the [] areas with valid data, of course. FileCreateDir creates the directory in the proper location (C:\Users), but FileCreateShortcut puts the shortcut in C:\ProgramData and creates the necessary directory structure to support it. |
|
| Back to top |
|
 |
darklight_tr
Joined: 29 May 2008 Posts: 11 Location: Madison, WI
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2393
|
Posted: Sun Jun 22, 2008 4:16 am Post subject: |
|
|
| darklight_tr wrote: | | I am an admin on both machines I am testing on. | Vista doesn't care. You will still have to right-click and select to "Run as administrator" in many cases - even if your user has administrator rights. Administrator doesn't mean much to Vista anymore... Trusted Installer is now the real Administrator (although not a real user - a service) and Vista doesn't want us to have that title... |
|
| Back to top |
|
 |
darklight_tr
Joined: 29 May 2008 Posts: 11 Location: Madison, WI
|
Posted: Tue Jun 24, 2008 4:33 pm Post subject: |
|
|
| corrupt wrote: | | Vista doesn't care. You will still have to right-click and select to "Run as administrator" in many cases - even if your user has administrator rights. Administrator doesn't mean much to Vista anymore... Trusted Installer is now the real Administrator (although not a real user - a service) and Vista doesn't want us to have that title... |
While I can see your point, I have never had to use Run as administrator as long as the user I was logged in as was an admin.
Thanks for the info! |
|
| Back to top |
|
 |
DataLife
Joined: 27 Apr 2008 Posts: 13
|
Posted: Thu Jul 17, 2008 5:52 am Post subject: |
|
|
I also have this problem in Vista using A_Programs
I can create the folder in "C:\Users\****\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"
then attempt to create the shortcut in the folder I just created but it puts it in
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs"
in a folder with the same name as I just created in the c:\users location.
When I use filedelete to delete the shortcut it tries to delete it in the c:\users but that is not where it was created.
I seen that someone solved it with Compile_AHK, but I can not figure out what is going on with that. If I use Compile_AHK to compile my script will it create the shortcut in the correct location?
DataLife |
|
| Back to top |
|
 |
darklight_tr
Joined: 29 May 2008 Posts: 11 Location: Madison, WI
|
Posted: Wed Jul 23, 2008 2:31 pm Post subject: |
|
|
DataLife,
This problem didn't occur for me when using uncompiled scripts, only compiled ones.
The reason that I use Compile_AHK is that I need to force the Vista UAC Execution Level to a higher level (such as requireAdministrator) in order for the shortcut creation to work correctly with a compiled script. |
|
| Back to top |
|
 |
vezuv34
Joined: 15 Aug 2008 Posts: 1
|
|
| Back to top |
|
 |
|