|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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! |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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.... |
||||||||
|
|
|||||||
ok, will try this wednessday.. will post the results here.. thx for your replies so far! |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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! |
||||||||
|
|
|||||||
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.. |
||||||||
|
|
|||||||
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! |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
jup i want to verify if a user has the shortcuts to powerpoint, exel and word on his desktop.. if not copy them over |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Glenn, Shouldn't this be Case instr($Path, 'Word.exe') or are you doing something else? |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
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:
|
||||||||
|
|
|||||||
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!! |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Here is the code to do it, don't forget to include the GetShortCutProperties udf.
|
||||||||
|
|
|||||||
thx for your reply Richard, i got it to work with the script above |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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... |
||||||||
|
|
|||||||
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:
This code gives me a much larger list which I can't post here as it has sensitive information |