473,796 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticaly checking a shortcuts properties?

I want to write a quick and simple programme to update a shortcut on
about 20 peoples workstations. They will all have the same shortcut, so
I thought the simplest way would be to create the shortcut on one
computer and just copy it to their desktops.

However I would like to add two extra features to this.

1.
I would like to log when the users use the programme. I will just
create a network text file and append a line each time the program is
run.

2.
I would like to record what the shortcut was pointing to before it was
replaced, if indeed it existed? This is the part I'm not sure about.
(I've tried opening a .lnk file in notepad but its not plain text so i
cant just extract the info from the text file)

Could you please advise,

Thanks,

Gary-

Dec 15 '06 #1
4 12476
Hi,
1.
I would like to log when the users use the programme. I will just
create a network text file and append a line each time the program is
run.
Be careful with this, you can potentially have 20 clients trying to write to
the same file at the same time, you would need to check for concurrency
issues. I would go for other solution like using the event log for this.
2.
I would like to record what the shortcut was pointing to before it was
replaced, if indeed it existed? This is the part I'm not sure about.
(I've tried opening a .lnk file in notepad but its not plain text so i
cant just extract the info from the text file)
google the structure of the lnk file.
--
Ignacio Machin
machin AT laceupsolutions com
Dec 15 '06 #2
Hi,
>2.
I would like to record what the shortcut was pointing to before it was
replaced, if indeed it existed? This is the part I'm not sure about.
(I've tried opening a .lnk file in notepad but its not plain text so i
cant just extract the info from the text file)

google the structure of the lnk file.
WSH might be useful as well. It can be referenced on the COM tab as
"Windows Script Host Object Model" and provides an interface for managing a
shortcut file.

--
Dave Sexton
Dec 15 '06 #3
Gary,

Ignacio and Dave already replied with helpful tips, but regarding your
question #2, I want to give more information and some C# code.

Firstly, shortcuts or "shell links" as they are also called can be
manipulated using the COM objects in SHELL32.DLL, and there exists the
IShellLink interface and the ShellLinkObject object, the latter of which is
very useful. If you are using Visual Studio, you can simply add a reference
to the COM library "Microsoft Shell Control And Automation" or to
SHELL32.DLL directly, and then use the following code:

----------------------------
public string GetShortcutTarg etFile(string shortcutFilenam e)
{
string pathOnly = System.IO.Path. GetDirectoryNam e(shortcutFilen ame);
string filenameOnly = System.IO.Path. GetFileName(sho rtcutFilename);

Shell32.Shell shell = new Shell32.ShellCl ass();
Shell32.Folder folder = shell.NameSpace (pathOnly);
Shell32.FolderI tem folderItem = folder.ParseNam e(filenameOnly) ;
if (folderItem != null)
{
Shell32.ShellLi nkObject link =
(Shell32.ShellL inkObject)folde rItem.GetLink;
return link.Path;
}
return ""; // not found
}
----------------------------

Then, you could use the above code simply like this:

----------------------------
private void button1_Click(o bject sender, EventArgs e)
{
string shortcut = "C:\\Shortc ut to notepad.exe.lnk ";
MessageBox.Show (GetShortcutTar getFile(shortcu t));
}
----------------------------

Finally, if you are interested in the file format, you can go to
http://www.wotsit.org/ and then search for "LNK". You will find three useful
documents. Finally, ShellLinkObject is documented here:

http://msdn2.microsoft.com/en-gb/library/ms630347.aspx

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethi s.dystopia.fi
http://www.saunalahti.fi/janij/
Dec 15 '06 #4
Thankyou all very much, i'm lucky to have the benefit of your expansive
knowledge!

Gary.

Jani Järvinen [MVP] wrote:
Gary,

Ignacio and Dave already replied with helpful tips, but regarding your
question #2, I want to give more information and some C# code.

Firstly, shortcuts or "shell links" as they are also called can be
manipulated using the COM objects in SHELL32.DLL, and there exists the
IShellLink interface and the ShellLinkObject object, the latter of which is
very useful. If you are using Visual Studio, you can simply add a reference
to the COM library "Microsoft Shell Control And Automation" or to
SHELL32.DLL directly, and then use the following code:

----------------------------
public string GetShortcutTarg etFile(string shortcutFilenam e)
{
string pathOnly = System.IO.Path. GetDirectoryNam e(shortcutFilen ame);
string filenameOnly = System.IO.Path. GetFileName(sho rtcutFilename);

Shell32.Shell shell = new Shell32.ShellCl ass();
Shell32.Folder folder = shell.NameSpace (pathOnly);
Shell32.FolderI tem folderItem = folder.ParseNam e(filenameOnly) ;
if (folderItem != null)
{
Shell32.ShellLi nkObject link =
(Shell32.ShellL inkObject)folde rItem.GetLink;
return link.Path;
}
return ""; // not found
}
----------------------------

Then, you could use the above code simply like this:

----------------------------
private void button1_Click(o bject sender, EventArgs e)
{
string shortcut = "C:\\Shortc ut to notepad.exe.lnk ";
MessageBox.Show (GetShortcutTar getFile(shortcu t));
}
----------------------------

Finally, if you are interested in the file format, you can go to
http://www.wotsit.org/ and then search for "LNK". You will find three useful
documents. Finally, ShellLinkObject is documented here:

http://msdn2.microsoft.com/en-gb/library/ms630347.aspx

Hope this helps!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
ja***@removethi s.dystopia.fi
http://www.saunalahti.fi/janij/
Dec 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1388
by: Colin Sheppard | last post by:
Hello, Does anyone have some suggestions on how to use VBA to Spell Check (and Grammar Check) Custom Properties of a entity/file? For example, I may wish to have a form that contains text boxes which contain text destined for a Customer Property. I would like to spell check that text box BEFORE adding it to the custom property. (It would also be nice that it could be incorporated in such a way
0
1242
by: Steve Noveman | last post by:
Hi, I need to programmaticaly create and configure a new virtual directory on IIS6.0. The virtual directory path is a network share. Therefore, I need to set up this network's Security Credentials (User name and Password). Which metabase properties correspond to these parameters? Thanks,
0
1187
by: Mark Broadbent | last post by:
Hope somebody could point me in the right direction. 1. I want to be able to drag and drop a file or a shortcut from a folder (from outside the app) and drop it on the apps form. 2. From this I need to examine said file or shortcuts properties. point 1 is the particularly tricky bit. point 2 I think I might be ok with (although not sure if examining a shortcuts properties would be the same as a file) Thx,
3
2137
by: cleo | last post by:
In VB6 my practice was to set control properties at Run Time rather than Design Time. I found setting property values in the code provided better documentation, since much of this was hidden - and if there were problems with a control dll setting values were preserved and not "lost" to the domain of searching code using a DOS editor. However, as I start work in VB.Net I'm questioning if I should continue my practice of avoiding Design...
4
1156
by: Tarun Mistry | last post by:
Hi everyone. I want to perform some login checking in one of my webforms to decide on what content to show, is this possible? Should i be doing this differently (btw im a new .net programmer moving from PHP). So depending on the value of x and y (defined in my code behind) i want todo something like this in the code. <% if(x > y) {%> <p>HELLO WORLD</p>
11
11263
by: cindy | last post by:
I have a form, has javascript registered so a modal pops up. Button click will close form. Now I need to do an update with modal form data before it closes. I can put a second button and register the onclick attribute of the second button to the javascript to close the form after user clicks upload button click upload do the update to database then programmatically click the second button the use on onclick attribute that sees the...
5
6561
by: PAzevedo | last post by:
With ToolStripMenuItem objects i created a 'Tools' menu and from that menu droped an Item to which i assigned a ShortcutKey of 'Keys.Control | Keys.E', and the shortcut doesn't work. This ToolStripMenuItem is inside a Form, i tryed with different shortcuts and some work, some don't. For instance, 'Keys.Control | Keys.R' doesn't work either. Is anyone familiar with this problem? MenuStrip msMenu = new MenuStrip(); msMenu.Parent = this;
1
3944
by: gwest | last post by:
I'm trying to read the properties on Windows Shortcuts such as the 'Target:', 'Run" and 'Target Type:'. DSOFile doesn't give access to these attributes (is it just for OLE files?). Anyone know how I can do this? Thanks!
4
2497
by: David Jackson | last post by:
Hello, I've been asked to write a sort of "desktop clean-up" utility. Requirements are simple: iterate through the shortcuts (*.lnk files) on the currently logged-on user's desktop, and delete each link whose TargetPath property no longer exists. Iterating through the shortcuts on the desktop is easy enough using Directory.GetFiles(*.lnk)
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.