Page 2 of 2 <12
Topic Options
#185096 - 2008-02-05 07:52 PM Re: Loop : Desktop Shortcut Check [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Yeah - was supposed to be. We had a network glitch here this morning. I didn't notice it missing and copied/pasted the error. I'll update the example - thanks!

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

Top
#185103 - 2008-02-06 07:33 AM Re: Loop : Desktop Shortcut Check [Re: Allen]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
thx for your replies so far...

it still doesnt work the way i would like it to...

im using this code:
 Code:
Dim $List	; array of LNK files
Dim $Lnk	; array enumerator
Dim $Path	; target path

$List = DirList('C:\Documents and Settings\Thijs\Bureaublad\*.lnk', 2)

For Each $Lnk in $List
  'Processing ' $Lnk ?
  $Path = GetShortCutProperties($Lnk, 'Path')
  'Path: ' $Path ?

$fExcel = 1
Select
 Case InStr($Path, 'xlicons')        ; found - don't need to install
  $fExcel = 0
EndSelect
Next

; Should shortcut be defined
If $fExcel
  del c:\test\test1.txt
EndIf


The Script has some weird thingies

When i use 'word' in the instr it works fine having a [censored] of crap on my desktop.
when i use 'xlico' or 'ppt' in the intr it worke fine when exel is the only office shortcut on my desktop.. but when i place other office shortcuts on the desktop.. it sets the flag to 0. so i guess it cant find it?


what am i doing wrong?


Edited by henkie32 (2008-02-06 08:24 AM)

Top
#185107 - 2008-02-06 09:33 AM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I'm not sure that your explanation follows the logic of your script, but there is one thing very definately wrong.

You are setting the value of $fExcel to 1 inside your FOR/NEXT loop, which means that if it is set to 0 in your case statement and then you have another iteration of the loop it will be set back to 1 again.

Initialise the variable outside your loop and it will work better:
Dim $List       ; array of LNK files
Dim $Lnk ; array enumerator
Dim $Path ; target path
Dim $fExcel $fExcel=1


$List = DirList('C:\Documents and Settings\Thijs\Bureaublad\*.lnk', 2)


For Each $Lnk in $List
'Processing ' $Lnk ?
$Path = GetShortCutProperties($Lnk, 'Path')
'Path: ' $Path ?


Select
Case InStr($Path, 'xlicons') ; found - don't need to install
$fExcel = 0
EndSelect
Next


; Should shortcut be defined
If $fExcel
del c:\test\test1.txt
EndIf


Top
#185108 - 2008-02-06 10:17 AM Re: Loop : Desktop Shortcut Check [Re: Richard H.]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
that did the trick... i now created two scripts

one for office 2003
one for office 2007

the script checks if powerpoint, excel and word are present on users desktop by checking shortcut targets.

if they dont exists shortcuts are created.. (not copied)

shall i post the complete script here?

Edit:

when testing i found out one last problem: what if the shortcut is present in "all users"?
can i use an "or" to also check in all users?



thx for your help!!


Edited by henkie32 (2008-02-06 10:20 AM)

Top
#185109 - 2008-02-06 12:05 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
There are a couple of ways of doing it.

The most efficient way is to iterate through all of the the user's and all-user's icons and collect all the paths together in a single string.

Once you have created the string you can then check if your substring is present.

Top
#185110 - 2008-02-06 12:36 PM Re: Loop : Desktop Shortcut Check [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Here is the code to do it, don't forget to include the GetShortCutProperties udf.

Break ON
$=SetOption("Explicit","ON")


Dim $sTargets


$sTargets=udfGetTargets(%ALLUSERSPROFILE%+"\Desktop")+@CRLF+udfGetTargets(%USERPROFILE%+"\Desktop")


If Not InStr($sTargets,"xlicons")
"No XLICONS present - will install..."+@CRLF
EndIf


Function udfGetTargets($sPath)
Dim $asDirEntries
Dim $sLink


$sLink=Dir($sPath+"\*.lnk")
While $sLink
$udfGetTargets=$udfGetTargets+@CRLF+GetShortCutProperties($sPath+"\"+$sLink,'Path')
$sLink=Dir()
Loop
$udfGetTargets=SubStr($udfGetTargets,3)
EndFunction


Top
#185130 - 2008-02-07 12:06 PM Re: Loop : Desktop Shortcut Check [Re: Richard H.]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
thx for your reply Richard, i got it to work with the script above
Top
#185172 - 2008-02-08 03:21 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
henkie32 Offline
Fresh Scripter

Registered: 2008-02-01
Posts: 17
Script works like a charm.. only thing is it doesnt list shortcuts that are in "all users"

so when i have word and exel for example in all users and not on the current desktop.. the script will place two new shortcuts so my current desktop then has double word and exel shortcuts.

so what iam trying to do now is listing two directorys with dirlist and put them in one array..

what would be the best way to do this?

1) use one dirlist command to list two directories if possible so the output would be in one array directly
2) use two dirlist commands and concat the output in one array

i tried option one but i didnt came further. now trying option two but i cant find some material on concatinating arrays on the forum perhaps someone can point me in the right direction?

cheers.
example.
 Code:
$sublist1 = DirList('C:\Documents and Settings\%username%\Bureaublad\*.lnk', 2)  
$sublist2 = DirList('C:\Documents and Settings\All Users\Bureaublad*.lnk', 2)

$List = $sublist1.$sublist2


Edited by henkie32 (2008-02-08 03:43 PM)

Top
#185176 - 2008-02-08 04:38 PM Re: Loop : Desktop Shortcut Check [Re: henkie32]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 Quote:
Script works like a charm.. only thing is it doesnt list shortcuts that are in "all users"


Yes it does! Check that the environment variables are OK for your locale.

Here it is modified to display the links it finds:
 Code:
Break ON
$=SetOption("Explicit","ON")
 
Dim $sTargets
 
$sTargets=udfGetTargets(%ALLUSERSPROFILE%+"\Desktop")+@CRLF+udfGetTargets(%USERPROFILE%+"\Desktop")
 
If Not InStr($sTargets,"xlicons")
        "No XLICONS present - will install..."+@CRLF
EndIf
 
Function udfGetTargets($sPath)
	Dim $asDirEntries
	Dim $sLink

	$sLink=Dir($sPath+"\*.lnk")
	While $sLink
		"Getting path from: "+$sPath+"\"+$sLink+@CRLF
		$udfGetTargets=$udfGetTargets+@CRLF+GetShortCutProperties($sPath+"\"+$sLink,'Path')
		$sLink=Dir()
	Loop
	$udfGetTargets=SubStr($udfGetTargets,3)
EndFunction


When I run this on my machine I get:
 Quote:
Getting path from: C:\Documents and Settings\All Users\Desktop\Cisco Network Assistant.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\Cygwin.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\DYMO Label.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\Extend360.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\gVim 7.0.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\gVim Easy 7.0.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\gVim Read only 7.0.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\Harsco AD.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\IBM iSeries Access for Windows.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\iSeries Navigator.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\LockoutStatus.exe.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\Oracle Live.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\PuTTY.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\SnagIt 8.lnk
Getting path from: C:\Documents and Settings\All Users\Desktop\Vodafone Mobile Connect.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\Catherine.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\CBP.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\COM 7.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\Dameware.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\Grab & Burn.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\hsc-oracle-apps-asep.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\HyperTerm.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\Mercury.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\MMC.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\MSVFL1.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\Pitbull.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\PSFTP.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\PUTTY.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\RunAs Explorer.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\Shortcut to Local Area Connection.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\Shortcut to Offline Files.LNK
Getting path from: C:\Documents and Settings\rhowarth\Desktop\WHSE01.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\Windows Media Player.lnk
Getting path from: C:\Documents and Settings\rhowarth\Desktop\ZenMap.lnk
No XLICONS present - will install...


You can see the "All Users" links at the top of the list.

Top
#185177 - 2008-02-08 04:44 PM Re: Loop : Desktop Shortcut Check [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ahhh... hang on... I think I may see what the problem is.

The sample that I have given you looks only in "Desktop" for All Users and the logged in user.

If you want to enumerate all the directories, change the udfGetTargets() UDF to use DirList() instead of Dir() and pass the parent directory rather than the Desktop directory.

Hang on...give me two minutes and I'll amend it for you...


Edited by Richard H. (2008-02-08 04:49 PM)

Top
#185180 - 2008-02-08 05:01 PM Re: Loop : Desktop Shortcut Check [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Here you go - it take quite a bit longer to run (on my machine at least) so you might want to limit the scope a bit more:

Break ON
$=SetOption("Explicit","ON")


Dim $sTargets


$sTargets=udfGetTargets(%ALLUSERSPROFILE%)+@CRLF+udfGetTargets(%USERPROFILE%)


If Not InStr($sTargets,"xlicons")
"No XLICONS present - will install..."+@CRLF
EndIf


Function udfGetTargets($sPath)
Dim $asDirEntries
Dim $sLink


$asDirEntries=DirList($sPath+"\*.lnk", 2+4)



For Each $sLink in $asDirEntries
"Getting path from: "+$sLink+@CRLF
$udfGetTargets=$udfGetTargets+@CRLF+GetShortCutProperties($sLink,'Path')
Next
$udfGetTargets=SubStr($udfGetTargets,3)
EndFunction



This code gives me a much larger list which I can't post here as it has sensitive information

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 436 anonymous users online.
Newest Members
SERoyalty, mytar, Gabriel, Alex_Evos, Dansen
17869 Registered Users

Generated in 0.162 seconds in which 0.115 seconds were spent on a total of 12 queries. Zlib compression enabled.

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