Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could be posible to create a short cut to an appl an put on destop?

Status
Not open for further replies.

hardwork99

Instructor
Feb 3, 2005
23
DO
Hi all,

Could be some way to create a short to automatically from an aplication select an put on the desktop?

Example: Put a Ms-Word or Excel, Icon on desktop or other software that i could select it from a form?
 

boyd.gif

 
Code:
* Using Windows Scripting Host create a shortcut (link to a file or URL)
* Example: 
* 1.) DO CreateShortCut WITH "Notepad.lnk", "notepad.exe"
* 2.) DO CreateShortCut WITH "Microsoft Web Site.URL", "[URL unfurl="true"]http://www.microsoft.com"[/URL]

LPARAMETERS tcShortCutName, tcTargetPath

IF PCOUNT() < 2
	MESSAGEBOX("Not enough parameters.")
	RETURN
ENDIF	

LOCAL lcxDirectory, loWshShell, loShortCut, llNormalShortCut

* Save current directory.
lcxDirectory = SET("Directory")

* Determine if this is a URL shortcut or a normal (lnk) shortcut.
llNormalShortCut = .F.
lcExt = UPPER(ALLTRIM(JUSTEXT(tcShortCutName)))
IF lcExt = "LNK"
	llNormalShortCut = .T.
ENDIF	

loWshShell = CreateObject( "WScript.Shell" )

* added desktop variable so you can see how to send the short-cuts to a different 
* folder, let's say a network folder that can be shared by several users.  This is handy 
* if you create weekly / monthly reports on the network and you want to give a group of 
* users access to them.
llDesktop = .T.
IF llDesktop
	SET DIRECTORY TO (loWshShell.SpecialFolders("Desktop"))
ELSE	
	SET DIRECTORY TO O:\office\shortcuts
ENDIF	


loShortCut = loWshShell.CreateShortcut( tcShortCutName )
loShortCut.TargetPath = tcTargetPath

* The following properties are only available for normal short cuts.
IF llNormalShortCut

	* Below are other properties and examples of setting them.
	* loShortCut.IconLocation = "notepad.exe, 0"
	loShortCut.Description = "Currently running script."
	
	* add hot key if you like.
	* loShortCut.Hotkey = "ALT+CTRL+F"
	loShortCut.Hotkey = ""
	
	loShortCut.WindowStyle = 7 && minimized
	
	loShortCut.WorkingDirectory = ADDBS(JUSTPATH(m.tcTargetPath))
	loShortCut.IconLocation = tcTargetPath

	
	* Display full path of the executable
	* ?loShortCut.Fullname
	
ENDIF	

loShortCut.Save

* move back to your starting directory
SET DIRECTORY TO (lcxDirectory)

Jim Osieczonek
Delta Business Group, LLC
 
from msn:
A .lnk file is a text file that contains the command line for the linked target, which can be enclosed in double quotation marks, along with the length of that command line. Optionally, you can also pass parameters into the linked target.

By default, an .lnk file uses the following format.

[number of ASCII characters after pound sign allocated to command line arguments]#[command line] [optional parameters]

For example, to start MyApp.exe and pass two optional parameters into the application, a sample MyApp.lnk file contains the following syntax.

40#\Windows\MyApp.exe parameter1 parameter2

therefore, aside from sir jim's suggestion, you could also use StrToFile() to achieve what you want.

hope this helps. peace! [peace]

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
my apoligies. it appears to me i was reading (and suggested) the wrong solution.

peace! [peace]

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top