AutoHotkey Community

It is currently May 27th, 2012, 1:14 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: June 18th, 2008, 6:28 pm 
Offline

Joined: May 29th, 2008, 5:02 pm
Posts: 21
Location: Madison, WI
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 June 20th, 2008, 7:30 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2008, 6:31 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
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?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2008, 7:18 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2008, 4:44 pm 
Offline

Joined: May 29th, 2008, 5:02 pm
Posts: 21
Location: Madison, WI
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2008, 7:26 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
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?

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2008, 8:15 pm 
Offline

Joined: May 29th, 2008, 5:02 pm
Posts: 21
Location: Madison, WI
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2008, 7:30 pm 
Offline

Joined: May 29th, 2008, 5:02 pm
Posts: 21
Location: Madison, WI
The problem has been solved. I had to use Compile_AHK to set a Vista UAC level when compiling the script.

http://www.autohotkey.com/forum/viewtopic.php?t=22975&highlight=compileahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2008, 4:16 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2008, 4:33 pm 
Offline

Joined: May 29th, 2008, 5:02 pm
Posts: 21
Location: Madison, WI
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 5:52 am 
Offline

Joined: April 27th, 2008, 5:28 pm
Posts: 489
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2008, 2:31 pm 
Offline

Joined: May 29th, 2008, 5:02 pm
Posts: 21
Location: Madison, WI
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2008, 3:25 pm 
Offline

Joined: August 15th, 2008, 3:24 pm
Posts: 1
Thanks for this information

_________________
http://www.maildunyasi.com


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group