Jump to content

Help with shortcut creation.


Recommended Posts

I'm trying to create a shortcut using FileCreateShortcut. Here is the line of code I am using to do so:

FileCreateShortcut("%JAVA_HOME%" & "\bin\javaws.exe", $SHORTCUT_PATH & "\TEAMLEADER", $SHORTCUT_PATH, $GALC_URL)

It creates the shortcut just fine, but it keeps adding "C:" to the start of the target. How can I get it to not do that? %JAVA_HOME% is a System Environment Variable. If I edit the created shortcut and delete the "C:" it works just fine.

Any help would be greatly appreciated.

Link to comment
Share on other sites

  • Moderators

What about something like this?

$home = EnvGet("JAVA_HOME")
FileCreateShortcut($home & "\bin\javaws.exe", $SHORTCUT_PATH & "\TEAMLEADER", $SHORTCUT_PATH, $GALC_URL)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Try this.

Opt("ExpandEnvStrings", 1)

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

Link to comment
Share on other sites

 

Try this.

Opt("ExpandEnvStrings", 1)

That didn't seem to help any.

 

When the Environment strings are expanded it would get the Environment path, so if you have a new JAVA version, the variable would obviously get changed !!

 

The idea of this script is to create a shortcut that never has to be changed.

 

Although, I might as well just create an executable AutoIt file and run the java app from there if I can't get it to get rid of the C:

Link to comment
Share on other sites

I see the problem you're talking about.

 

The shortcut created has a target of 

C:%JAVA_HOME%binjavaws.exe http://test.com

Rather than just

%JAVA_HOME%binjavaws.exe http://test.com

EDIT: I notice that it only prepends the "C:" to the shortcut if the environment variable doesn't exist. If I use %systemroot% in place of %java_home% it doesn't add the drive letter. If I use %systemroo% (misspelling systemroot) it does add the drive letter. Looks like a bug to me.

Edited by BrewManNH

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

Link to comment
Share on other sites

Well, I know the variable exists, because my script creates it.

Here's all the code:

$JAVA_HOME = EnvGet("JAVA_HOME")
If $JAVA_HOME = "" Then 
   If @OSVersion = "WIN_7" Then
      If FileExists("C:\Program Files (x86)\Java\jre1.6.0_03") Then
         $JAVA_HOME = "C:\Program Files (x86)\Java\jre1.6.0_03"
      EndIf
   ElseIf FileExists("C:\Program Files (x86)\Java\jre1.5.0_12") Then
         $JAVA_HOME = "C:\Program Files (x86)\Java\jre1.5.0_12"
   EndIf
ElseIf @OSVersion = "WIN_XP" Then
   If FileExists("C:\Program Files\Java\jre1.6.0_03") Then
      $JAVA_HOME = "C:\Program Files\Java\jre1.6.0_03"
   EndIf
   ElseIf FileExists("C:\Program Files\Java\jre1.5.0_12") Then
      $JAVA_HOME = "C:\Program Files\Java\jre1.5.0_12"
   EndIf
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "JAVA_HOME", "REG_SZ", $JAVA_HOME)


$GALC_URL = "http://galchminline1naprod.hmin.am.honda.com/BaseWebStart/TEAMLEADER.host"
$SHORTCUT_PATH = ""
If @OSVersion = "WIN_7" Then
   $SHORTCUT_PATH = "C:\Users\Default\Desktop"
Else
   $SHORTCUT_PATH = "C:\Documents and Settings\Default User\Desktop"
EndIf
FileCreateShortcut("%JAVA_HOME%" & "\bin\javaws.exe", $SHORTCUT_PATH & "\TEAMLEADER", $SHORTCUT_PATH, $GALC_URL)
Link to comment
Share on other sites

 

Well, I know the variable exists, because my script creates it.

 

Use EnvSet first to create the environment variable and it will create the shorcut correctly:

EnvSet("JAVA_HOME", "C:\Program Files (x86)\Java\jre1.6.0_03")
FileCreateShortcut("%JAVA_HOME%" & "\bin\javaws.exe", $SHORTCUT_PATH & "\TEAMLEADER", $SHORTCUT_PATH, $GALC_URL)

Edit: I forget to mention that you should take a look to "Remarks" in the help file for EnvSet function.

Cheers,

sahsanu

Edited by sahsanu
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...