Sign in to follow this  
Followers 0
anthelie

FileCreateShortcut problems on Windows 7 64bit

8 posts in this topic

#1 ·  Posted (edited)

Hi,

I have a strange problem when my 32bit script is run on a 64bit machine.

Firstofall: the same code works fine for 32bit machines.

This is supposed to be one 32bit script running with administrative rights on several OSses which installs software and creates shortcuts.

$DestPath=@ProgramFilesDir & "myapp"
$ExeFile=$DestPath & "SomeProgram.exe"

$ShortcutTxt ="some Text"
$ShortcutPath=@ProgramsCommonDir & "My App"
$ShortcutParameter=""
$IconFile=$DestPath & "MYICON.ico"

; This seems to have no effect - though I get the MsgBox ...
If @OSArch="X64" Then
 Msgbox (0,0, @OSArch)
 $IconFile=$ProgramFilesX86 & "My AppMYICON.ico"
EndIf

If FileExists($ExeFile) Then
 DirCreate($ShortcutPath)
 $Ret=FileCreateShortcut ($ExeFile, 
 $ShortcutFullPath, 
 $DestPath, 
 $ShortcutParameter, $ShortcutTxt, 
 $IconFile, "", 0) 
EndIf

With this, I end up with an Icon pointing to the correct EXE-File in "C:Program Files (x86)myappMyApp.exe" - but the Icon's wrong.

When I try to change the icon manually I get the message "%ProgramFiles%myappMYICON.ico" not found. That's right - the icon is located in %ProgramFilesX86% which resolves to "C:Program Files (x86)"

Btw, it makes no difference if I use

$IconFile=$DestPath & "MYICON.ico"

or

$IconFile=$ProgramFilesX86 & "My AppMYICON.ico"

or

$IconFile=C:Program Files (x86) & "My AppMYICON.ico"

I always end up with the icon pointing to %ProgramFiles% :-(

Any ideas? Workarounds? Whatever ...

ciao

anthelie

Edited by anthelie

Share this post


Link to post
Share on other sites



For starters, you haven't actually filled in $ProgramFilesX86

Try something like (at the header):

If @OSArch = "X64" Then 
   $DestPath = "C:Program Files (X86)"
Else
   $DestPath = "C:Program Files"
EndIf

Are you telling me something I need to know or something I want to know?

Share this post


Link to post
Share on other sites

Hi,

sorry, I forgot to paste the part where I fill $ProgramFilesX86

I used

If @OSArch="X64" Then

$ProgramFilesX86 = EnvGet("ProgramFiles(x86)")

EndIf

Anyway, even if I put it in hardcoded like

$IconFile="C:Program Files (x86)My AppMYICON.ico"

I end up with %ProgramFiles%My AppMYICON.ico

Looks like something is putting in unneeded and faulty intelligence :-(

ciao

anthelie

Share this post


Link to post
Share on other sites

Okay, for some reason that's really confused me...

It looks a bit disjointed, try something like this:

If @OSArch = "X64" Then
$DestPath = "C:Program Files (X86)"
Else
$DestPath = "C:Program Files"
EndIf

$DestPath = $DestPath & "AutoIT3"
$ExeFile=$DestPath & "Au3Info_x64.exe"

$ShortcutTxt ="Just Some Text"
$ShortcutPath="c:tempMy App"
$ShortcutParameter=""
$IconFile=$ShortcutPath & "MYICON.ico" ;I didn't use this, just used the exe file instead...

If FileExists($ExeFile) Then
DirCreate($ShortcutPath)
$Ret=FileCreateShortcut($ExeFile, $ShortcutPath & "Test.lnk", $DestPath, $ShortcutParameter, $ShortcutTxt, $ExeFile, "", 0)
EndIf

Are you telling me something I need to know or something I want to know?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi,

there seems to be some weird replacement mechanism ....

C:UsersMEDesktopMyDirMyIcon.ico ==> results in %USERPROFILE%DesktopMyDirMyIcon.ico

C:TestTestMyIcon.ico ==> results in %SystemDrive%TestTestMyIcon.ico

I now created an environment variable

ThisIsStupid=C:TestTest

but still

C:TestTestMyIcon.ico ==> results in %SystemDrive%TestTestMyIcon.ico (instead of %ThisIsStupid%MyIcon.ico)

And even though

TEMP=C:TEMP

I get

C:TempMyIcon.ico ==> results in %SystemDrive%TempMyIcon.ico

Btw. it makes no difference if I use MyIcon.ico or MyApp.exe

ciao

anthelie

Edited by anthelie

Share this post


Link to post
Share on other sites

Hi Anthelie,

I'm not sure what you mean by "Results in", as %SystemDrive% is an environment variable which will be populated with the drive letter that the OS is installed on.

The environment variables are there to be read the other way to how you have indicated... For example:

%ThisIsStupid%=C:TestTest

would mean that

%ThisIsStupid%AnotherTest.exe

would equal

C:TempTempAnotherTest.exe

I'm confused to why you're trying to work things the other way around? You would only want to use an Environment Variable for something which would be unique on every machine or user but which you may not be able to efficiently code yourself... For example the variable for %AppData% is very useful, but it will always join the Roaming section of the profile ("C:Documents and Settings[uSER]Application Data" for WinXP and "C:Users[uSER]AppDataRoaming" for Win7).

I assume you already know to type "SET" into the command interpreter to get a full list of the environment variables?

So.... What exactly are you trying to do?

Mal


Are you telling me something I need to know or something I want to know?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi,

with my lasts test I just tried to figure out the mechanism why I end up with (wrong) environment variables instead of my correctly provided HARDCODED path. I also wouldn't mind correct environment variables - but the path to the icon file is just wrong :-(

All I need is a shortcut where the icon points to the correct path "C:Program Files (x86)MyAppMyIcon.ico"

Using FileCreateShortcut ("C:Program Files (x86)MyAppMyIcon.EXE".., "C:Program Files (x86)MyAppMyIcon.ico", ...) on a 64bit machine does create a shortcut

- with the exe pointing to "C:Program Files (x86)MyAppMyIcon.ico" (no environment variable automatism here)

- with the ICON pointing to "%ProgramFiles%MyAppMyIcon.ico" (WRONG environment variable automatism here as %ProgramFiles% is C:Program Files on 64bit systems)

ciao

anthelie

P.S. yes, I know how to set environment variables correctly :) I also know when to use them and when not :)

Edited by anthelie

Share this post


Link to post
Share on other sites

If I run your script, changing only the location of the file to be linked to, I don't get any environment variables in the shortcut. I'm getting C:Program Files(x86) when I run this script.

#AutoIt3Wrapper_UseX64=n
If @OSArch = "X64" Then
    $ProgramFilesX86 = EnvGet("ProgramFiles(x86)")
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ProgramFilesX86 = ' & $ProgramFilesX86 & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
EndIf
$DestPath = $ProgramFilesX86 & "Javajre7"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $DestPath = ' & $DestPath & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$ExeFile = $DestPath & "Welcome.html"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ExeFile = ' & $ExeFile & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$ShortcutTxt = "some Text"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ShortcutTxt = ' & $ShortcutTxt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$ShortcutPath = @DesktopDir & "My App"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ShortcutPath = ' & $ShortcutPath & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$ShortcutParameter = ""
$IconFile = $DestPath & "MYICON.ico"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $IconFile = ' & $IconFile & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$ShortcutFullPath = $ShortcutPath & "test.lnk"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ShortcutFullPath = ' & $ShortcutFullPath & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
; This seems to have no effect - though I get the MsgBox ...
If @OSArch = "X64" Then
    MsgBox(0, 0, @OSArch)
    $IconFile = $ProgramFilesX86 & "My AppMYICON.ico"
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $IconFile = ' & $IconFile & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
EndIf

If FileExists($ExeFile) Then
    DirCreate($ShortcutPath)
    $Ret = FileCreateShortcut($ExeFile, $ShortcutFullPath, $DestPath, $ShortcutParameter, $ShortcutTxt, $IconFile, "", 0)
EndIf

I added a bunch of ConsoleWrites to show the progress of the variables being created so you know if it's working as expected and where it's failing when it doesn't.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0