Registered: 2003-06-19
Posts: 103
Loc: Washinton DC, USA
So aside from using WSH, how could one read the target of a shortcut knowing the full path of the link? It would appear that Application.Shell and WMI could both do the task but I am having little success. I can easily use
code:
GetObject("WinMgmts:\root\cimv2").ExecQuery("Select * From Win32_ShortcutFile")
to enumerate all shortcuts within a computer, but I am having problems getting one specific shortcut. I have tried
code:
GetObject("WinMgmts:\root\cimv2").ExecQuery("Select * From Win32_ShortcutFile Where Name='C:\Documents and Settings\All Users\Start Menu\Programs\Startup\test.lnk'")
but it returns nothing instead of the shortcut. I understand that Application.Shell may also be able to do this so my ears are open to suggestion.
Registered: 2003-06-19
Posts: 103
Loc: Washinton DC, USA
It is against policy to READ the first message before posting a reply? I cannot use WSH which was in the FIRST 5 words of the post. I went on to ask if anybody knew how to access link properties using either WMI or an Explorer object. If you are a smart person and you can help me with this, please post. If your advise is, "why don't you use WSH" or, "why don't you use UDF X which uses WSH or is completely irrelivent" then I would highly suggest you go back to first grade and LEARN TO READ!
Sorry about getting so pissed off but I really wish people would read a post before responding.
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
quote:So aside from using WSH
does not say that you CANNOT use WSH. It rather implies that you are looking for alternative ways, e.g. using WMI, as you then go on with a WMI code fragment.
Secondly, there is not reason to get *** off as people try to help you. However, you might want to consider to first search the BBS for solutions to your questions. Then you might have discovered the referenced UDF that uses WSH to manipulate .LNK files and you could have said, "yeah, found that UDF, but I'd rather use WMI for this".
Also, WMI requires you to be very dilligent with regards to querying it. So, I have no idea whether you do proper error checking or use proper permissions to execute the query.
Oh, and I just used Google to look up some scripts doing what you're asking for by using just two keywords. The code used is very straight-forward. I'm pretty sure you know how to use a search engine and I'm also sure you are aware that the Microsoft website has extensive WMI documentation.
Oh, and we also prefer to not have such long lines inside quote tags as they make such threads hard to read.
[ 08. July 2003, 22:33: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.
Registered: 2003-06-19
Posts: 103
Loc: Washinton DC, USA
Seal, you are one of those people who needs to go back to first grade and not only learn to read, but understand what you are reading. I wouldn't have said 'aside from using wsh' if I could use WSH. Additionally, I did search the site, I did quiet a bit of searching. What did I find? I found that everything out there either uses wsh or doesn't help me one bit. Maybe rather then thinking you know everything you should assume you don't and go from there. With regards to WMI, I found a class that nobody on the KiXtart site appears to have used, that being Win32_ShortcutFile. I made some attempts to use it, as I explained in the post you still haven't read, but ran into a problem. I posted more then sufficient information for a WMI wiz out there to give me a little help. What I didn't count on was a bojo making the post look answered when it isn't. Now before you look like an even bigger idiot, would you please READ my post with OPEN eyes before responding again? Beyond that, if you are not posting code that uses WMI to read the target of a shortcut, you are not helping me or the site. I am NOT interesting in a mud fight with other bulletin board members. All I want is some working code delivered though clear, logical, and relivent (on point) posts. If I had wanted a WSH v. WMI debate, I would have asked for that.
As for the long lines, I would have though the site engine would be smart enough to wrap non- code lines. I will add -br-'s in the future.
I hate it when this kinda stuff happens ... Gaven, I dont think your justified in jumping all over one of our more respected and helpfull members (Jen's vote count speaks volumes). Lets try to keep things loose and friendly eh ? You can choose to take advise or ignore it altogether, Jen's certainly took the time out of his busy day to be helpfull ...
Registered: 2003-06-19
Posts: 103
Loc: Washinton DC, USA
I hear your point Shawn but I slightly disagree. While Jens may be a moderator, he does not walk on water. To be more on point, he, and others, quiet clearly posted responses after reading the subject and NOT the post. This bulletin board will no longer be helpful if it becomes a forum for people to hear themselves. I appreciate the fact that Jens read my post, but I am angry that he would half-ass it to the point of not reading the post. This is supposed to be a forum of intelligent programmers thus I submit that an intelligent person would read a post and respond accordingly.
[ 08. July 2003, 23:52: Message edited by: Gaven ]
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Gaven,
You still must remember one thing. We are all volunteers. If there was a mis-interpretation of the original question, then maybe clarification is needed. You will go further with patience rather than jumping all over people.
$colItems = GetObject("winmgmts:\root\cimv2").ExecQuery("Select * from Win32_ShortcutFile") For each $objItem in $colItems "Name: " + $objItem.Name ? ? Next
This returns the names of all shortcuts on my PC
One of these shorcuts is: c:\programs\msn\msn explorer.lnk
So I would expect this code to return only that shorcut: Script 2:
code:
$colItems = GetObject("winmgmts:\root\cimv2").ExecQuery("Select * from Win32_ShortcutFile where name='c:\programs\msn\msn explorer.lnk'") For each $objItem in $colItems "Name: " + $objItem.Name ? ? Next
Script 2 returns nothing, quite mysterious ??
Anyway, I don't think you should envestigate this way of checking shortcuts further, because it seems that winmgmts:\Win32_ShortcutFile expands and checks all propertys of all shortcuts on the computer. On a slow line this takes loong.
Gaven,
I'm just as mystified as you.
BUT: Yoy could have added further explaining post instead of attacking people who are trying to help you
Registered: 2003-06-19
Posts: 103
Loc: Washinton DC, USA
Erik, thank you. To everybody: for what it's worth I didn't jump down Jens throat. In fact, I would be more inclined to say Jens jumped down my throat with the first direct insult. I would encourage people to not get caught up on my hyperbole. I don't actually think anybody should go back to first grade, nor am I directly insulting the intelligence of anybody. We all do stupid things, but people need to be able to simply admit to the mistake and move on. What I think should have happened here is Jens second post should have not existed - there was simply no reason for it. He, as stated, didn't offer useless information. He did, however, throw gas on the fire which means this little "flame up" is his fault more then anyone else's. Now before anybody comments, read all above responses in their entirety. Don't skim over and think you know what going on.
quote: If you are a smart person and you can help me with this, please post. If your advise is, "why don't you use WSH" or, "why don't you use UDF X which uses WSH or is completely irrelivent" then I would highly suggest you go back to first grade and LEARN TO READ!
quote: What I didn't count on was a bojo making the post look answered when it isn't. Now before you look like an even bigger idiot, would you please READ my post with OPEN eyes before responding again?
quote: I appreciate the fact that Jens read my post, but I am angry that he would half-ass it to the point of not reading the post. This is supposed to be a forum of intelligent programmers thus I submit that an intelligent person would read a post and respond accordingly.
quote: He did, however, throw gas on the fire which means this little "flame up" is his fault more then anyone else's. Now before anybody comments, read all above responses in their entirety. Don't skim over and think you know what going on.
If I may. Perhaps you could look at this from another point of view. I know that it is often hard to accept or feel fault and I'm not trying to place fault on you, rather I'd like to make a little bit of an analogy.
Let's say that you join the Army and after training for 4 weeks as an Infantryman, they now ship you off to some hostile place where the Army is at War. They have you join a crew of Rangers that has been fighting together for 2 years now. They have established quite a bond with each other. Then when you show up, you have a new idea that you present to them, but the presentation didn't go as well as you planned. Somehow, accidentally it now appears as though you are attacking one of their long time buddies. Now all of the guys have started to form a disliking to you. At this point (in my humble opinion) you could do a couple things.
1. Apologize and hope that you could blend in with the guys in the near future (even if you felt you had done nothing wrong).
2. Ignore them and go about your merry way, realizing that in the future when your life might depend upon one of them, that they would not come to your rescue. (I know that programming is not the same life threatening circumstance here, but I’m trying to get a point across)
3. Continue to protest and acert your rights and feelings on the matter. (which in most cases would still garner ill feeling from the other guys).
What I'm trying to say is, as a new guy I personally think it would be easier and perhaps more prudent to suck it up. Yes you can continue to disagree or fight it, but bottom line is that as a new comer to this board it is difficult to "blow-up" and expect anyone to continue to help you. This has now become more a matter of social graces rather then "who is right".
[ 09. July 2003, 03:30: Message edited by: NTDOC ]
? 'Number shortcuts = '+$colShortcuts.count if $colShortcuts.count For each $objShortcut in $colShortcuts ? 'Name : ' +$objShortcut.Name ? 'Description : ' +$objShortCut.description ? '' Next else ? 'No matching shortcuts found.' endif
exit 0
However, I would recommed to check for the existance of the file via EXIST first as the WMI call will need to enumerate all shortcuts in order to filter them. The filecheck would speed up things if the shortcut does not exist.
_________________________
There are two types of vessels, submarines and targets.