Page 1 of 2 12>
Topic Options
#178735 - 2007-08-06 07:55 PM Loop : Desktop Shortcut Check
vt_techie2006 Offline
Lurker

Registered: 2006-09-20
Posts: 3
Hello All !

I think the best route to what I'm trying to accomplish is via the following methodology, though I am open to alternative methods :

Purpose of Script : Check to see if there is an 'Outlook' shortcut on the Desktop. If there is, do nothing. If there is not, copy the shortcut to the desktop.

As per the 'purpose,' I'm looking to write a 'while-loop' to determine whether or not a user has the Outlook shorcut on their desktop.

For each shortcut, I'd check the name of the shortcut to see if it contains the word 'Outlook' as desktops are not all uniform.

If one shortcut CONTAINED the name 'Outlook,' I would do nothing.

If however at the end of the loop, there was no Outlook shortcut, I'd create one.

Any help in this regard would be greatly appreciated !

I just downloaded the doc, but didn't want to recreate the wheel if it already exists.

Thanks for any insight,

V.

Top
#178736 - 2007-08-06 08:22 PM Re: Loop : Desktop Shortcut Check [Re: vt_techie2006]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
This is kind of dangerous because you could have a file with outlook somewhere in the name on the desktop but this does not have to be a shortcut to outlook. It could be anything.

Anyway if you want a script that does this you could have a look at these UDF's.

wshShortcut() - v1.3 - Create File & Web Shortcuts
DirPlus() - a recursive dir tool
KiXtart FAQ & How to's » How to use UDFs
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185004 - 2008-02-01 10:08 AM Re: Loop : Desktop Shortcut Check [Re: Mart]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
hey guys,

i was looking for a script that does the same thing you want it to, but then with word, poweroint and exel.

i was thinking about checking the target of the shortcut in order to see if it really is a shortcut to an office program

there any script like this yet?

thx in advance!

Top
#185009 - 2008-02-01 10:54 AM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Hi and welcome to the board.

you could get the shortcut names with the DirList() UDf or the DirPlus() UDF, check the name of each shortcut and check the target with the GetShortcutTarget() UDF if Word, Excel or PowerPoint is in the name.

UDF Library » DirList() - Returns an array with a list of files in a given directory
UDF Library » DirPlus() - a recursive dir tool
UDF Library » GetShortcutTarget() - Get the target of a specific shortcut.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185025 - 2008-02-01 04:18 PM Re: Loop : Desktop Shortcut Check [Re: Mart]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
yeah i could check the names.. but what happends if a user renamed the shortcut to something else then "word"....

i want to make a script for each office application:

the script has to list all .lnk files on the desktop. perform a check on that list, if a file in the list contains a shortcut to "c:\program files\office12\msword.exe" do nothing
if not then it has to copy over a new shortcut and then die

i only want shortcuts to word, powerpoint and exel so 3 scripts should do the job.

also i still have the problem of having a network with office 2003 and office 2007... but i kinda solved that using a batch script wich checks for the existence of office12 in program files (wich means 2007 is present)


if im unclear pls notice me ;\)

Top
#185027 - 2008-02-01 04:51 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Well then you can just get all .lnk files with the DirList() or DirPlus() UDF and use the GetShortcutProperties() or the GetShortcutAttr() UDF to get the path it points to.

UDF Library » GetShortcutProperties() - Get Properties / Attributes of Shortcut files
UDF Library » GetShortcutAttr() - Get the attributes of a shortcut
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185030 - 2008-02-01 05:03 PM Re: Loop : Desktop Shortcut Check [Re: Mart]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
so basicly what i need to do:

- use dirlist to create a list of .lnk files and put them in an array

- use shortcuttarget to retrieve the targets of each .lnk in the array

- use some script to check the array for word, powerpoint and exel. if not present copy over new shortcuts

so the thing im still missing is a script to check an array for values

Top
#185031 - 2008-02-01 05:38 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
You only need a single script to do the whole thing.

Copy the UDF's mentioned by Mart and paste them into your favorite script editor.

One you have them...
 Code:
$List = DirList("c:\documents and settings\username\desktop")
For each $lnk in $list
  $Path = GetShortCutProperties($lnk,"Path")
  If Instr($path,"word.exe") or Instr{$path,"excel.exe") or Instr($path,"powerpoint.exe")
  ;do nothing
  Else
  ;copy file
  EndIf
Next


Note this is not tested / working code, just enough to get you the idea of where to go....
_________________________
Today is the tomorrow you worried about yesterday.

Top
#185040 - 2008-02-02 09:21 PM Re: Loop : Desktop Shortcut Check [Re: Gargoyle]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
ok, will try this wednessday.. will post the results here.. thx for your replies so far!
Top
#185080 - 2008-02-05 02:53 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
thx, i changed the script to:

$List = DirList("C:\Documents and Settings\Thijs\Bureaublad")
For each $lnk in $list
$Path = GetShortCutProperties($lnk,"Path")
If Instr($path,"notes.exe")
del c:\test\test1
Else
del c:\test\test2
EndIf
Next

so when test1 is delled, the script finds a link containing lotus.exe

But i cant get this to work.. i got a shortcut on my desktop wich holds:
C:\Lotus\Notes\notes.exe

so i let the script look for notes.exe.. it doesnt seem to find it

what am i doing wrong?

Top
#185081 - 2008-02-05 03:34 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Testa and test2 are folders right? If they are you need to use RD and not Del. Del looks for a file called test1 or test2 in the folder c:\test\ and deletes it if it is there.

Edited by Mart (2008-02-05 03:35 PM)
Edit Reason: typo
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185082 - 2008-02-05 03:38 PM Re: Loop : Desktop Shortcut Check [Re: Mart]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
test1 and test2 are files with no extension..

the script does del test2..

but there is a word shortcut on the desktop wich it cant seem to find so it wont del test1

Top
#185084 - 2008-02-05 04:14 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Not really sure how any of this is working...

You're using DirList with no optional arguments; specifying a full path, but getting back file names; and exepect to find a "file" that you found in "path" without looking in "path\file"??? You're also returning a list of ALL files, not just shortcuts.

The way you're defining DirList("path"), you're getting an array of FILE NAMES - ie: "Word", "Excel", and so on. When you call the GetShortcutProperties UDF, you pass this name, but not the path, so the UDF has no clue where to look. You have two choices to make this work - add the path to the GetShortcutProperties UDF, or specify the optional arg in DirList to return full paths.

Here's a working example, with comments and debugging messages:
 Code:
Dim $List	; array of LNK files
Dim $Lnk	; array enumerator
Dim $Path	; target path

; Get list of LNK files (shortcuts), returning full paths
$List = DirList('%USERPROFILE%\Desktop\*.lnk', 2)

; Enumerate the array
For Each $Lnk in $List
  'Processing ' $Lnk ?
  $Path = GetShortCutProperties($Lnk, 'Path')
  'Path: ' $Path ?
  If Instr($Path, 'IExplore.exe')
    'Found Explorer!' ?
  Else
    'Explorer was not found' ?
  EndIf
Next

Try this script WITHOUT the "2" argument in DirList and you'll see why GetShortcutProperties won't work reliably. Also, using "%USERPROFILE%" is recommended over hard coding the documents path, although you might need to change the "desktop" reference.

I searched for Explorer, since that is a link I had on my desktop. I'd suggest you start there and then modify your code.

Also - from a command prompt, run "DIR %USERPROFILE%\Desktop" and see what file names are returned - you might be surprised. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185086 - 2008-02-05 04:24 PM Re: Loop : Desktop Shortcut Check [Re: Glenn Barnas]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
this did the trick for me.. the only thing left now is to create the shortcut if it doesnt exists...

but im sure there's an udf for it ;\) thx for your help!

Top
#185087 - 2008-02-05 04:31 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
hmm..

so now it runs through every .lnk checking if it holds a string true/false

how should i configure it?

true -> do nothing
false -> copy shortcut ;it will still copy if the first shortcut doesnt hold the string, but the last one does for example.. how can i secure this?

perhaps put the results of the strings in an array? and test the array for strings later on in the script..




Edited by henkie32 (2008-02-05 04:33 PM)

Top
#185089 - 2008-02-05 04:47 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
 Originally Posted By: henkie32

perhaps put the results of the strings in an array? and test the array for strings later on in the script..


Exactly!
_________________________



Top
#185091 - 2008-02-05 05:02 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Sounds overly complicated, actually.

What are you trying to do, exactly? Verify that shortcuts for Word, Excel, etc actually exist?

If so, your If/Endif won't do the job.

Create a FLAG variable for each shortcut (I'll use Word & Excel in the example):
$fWord = 1 $fExcel = 1

Replace the whole If/EndIf with a Select statement:
 Code:
Select
 Case InStr($Path, 'Word.exe')        ; found - don't need to install
  $fWord = 0
 Case InStr($Path, 'Excel.exe')
  $fExcel = 0
EndSelect

; Should Word shortcut be defined
If $fWord
  ; copy/create the Word shortcut
EndIf

Place this after the Next statement, when everything else is done:
 Code:
; Should Excel shortcut be defined
If $fExcel
  ; copy/create the Excel shortcut
EndIf


Glenn


Edited by Glenn Barnas (2008-02-05 07:56 PM)
Edit Reason: typo in example
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185092 - 2008-02-05 05:19 PM Re: Loop : Desktop Shortcut Check [Re: Glenn Barnas]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
jup i want to verify if a user has the shortcuts to powerpoint, exel and word on his desktop.. if not copy them over
Top
#185093 - 2008-02-05 05:41 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
OK - then the mods above as an update to my prior example will do just that. YOU will have to add the code to either copy a standard shortcut or create one, depending on how standard your install locations are. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185095 - 2008-02-05 05:54 PM Re: Loop : Desktop Shortcut Check [Re: Glenn Barnas]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Glenn,

Shouldn't this be
Case instr($Path, 'Word.exe')

or are you doing something else?

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.051 seconds in which 0.015 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org