View Full Version : As could access the command line of a shortcut?
Solmos
03-20-2008, 03:50 PM
As could access the command line of a shortcut?
thx!!
jassing
03-23-2008, 01:29 AM
As could access the command line of a shortcut?
thx!!
I'm guessing you want to break down the properties of a .lnk file?
Check here:
http://wsh2.freeweb.hu/ch10b.html
for some useful info -- you'd need to combine that with LuaCom
http://www.icynorth.com/luacom/index.html
If that doesn't get you going -- let me know and I'll give it a go in my spare time.
-josh
Solmos
03-23-2008, 02:23 AM
Yes, get shortcut properties
needed, target shortcut and command line shorcut.
please, create one example.
very thanks
jassing
03-23-2008, 11:38 AM
Yes, get shortcut properties
needed, target shortcut and command line shorcut.
please, create one example.
very thanks
Sorry -- I could have sworn wsh had a "getshortcut" method; but it doesn't... Let me try to figure something out for you... "stay tuned".
-josh
RizlaUK
03-23-2008, 01:41 PM
this may help
Here's a quick console app to show how to do this from C#. You'll first need to add a reference to the 'Windows Script Host Object Model' to your project which should be listed on the COM tab of the AddReference dialog in VS.
using System;
using IWshRuntimeLibrary;
namespace WshShortcutDemo
{
class Program
{
static void Main()
{
// enter full path to existing shortcut file in next line
string linkPathName = @"c:\SomeShortcutFile.lnk";
WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(linkPathName);
Console.WriteLine("Target path is {0}",link.TargetPath);
Console.WriteLine("Working directory is {0}",link.WorkingDirectory);
Console.ReadLine();
}
}
}
source:
http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=48404
it seems you access the .lnk file by using the "CreateShortcut" method and access the "TargetPath" or "Arguments" by useing the properties
jassing
03-23-2008, 03:27 PM
Yes, get shortcut properties
needed, target shortcut and command line shorcut.
please, create one example.
very thanks
Here's a sample that works -- I knew wsh could do it... I just got thrown becuase it's only method was "CreateShortcut" not "GetShortcut".. Anyway; you'll need the LuaCOM plugin (as indicated previously)
local tFile = Dialog.FileBrowse(true, "open link", _DesktopFolder, "Link files (*.lnk)|*.lnk", "", ".lnk", false, true);
if File.DoesExist(tFile[1]) then
local oWSH = luacom.CreateObject("wscript.shell");
local oShortCut = oWSH:CreateShortcut( tFile[1] ) ;
local cPath = oShortCut.TargetPath;
Dialog.Message("Target", tFile[1].."\r\n points to\r\n".. cPath );
oShortCut = nil;
oWSH = nil;
collectgarbage();
end
RizlaUK
03-23-2008, 03:43 PM
and arguments
local tFile = Dialog.FileBrowse(true, "open link", _DesktopFolder, "Link files (*.lnk)|*.lnk", "", ".lnk", false, true);
if File.DoesExist(tFile[1]) then
local oWSH = luacom.CreateObject("wscript.shell");
local oShortCut = oWSH:CreateShortcut( tFile[1] ) ;
local cPath = oShortCut.TargetPath;
local Args = oShortCut.Arguments
Dialog.Message("Target", tFile[1].."\r\n points to\r\n".. cPath.."\r\n\r\nArguments: "..Args );
oShortCut = nil;
oWSH = nil;
collectgarbage();
end
more info
http://msdn2.microsoft.com/en-us/library/at5ydy31.aspx
Solmos
03-23-2008, 04:23 PM
jassing detec s good the targetshortcut, but not command line
RizlaUK this code not work. If target shorcut contain command line, return nothing
and arguments
local tFile = Dialog.FileBrowse(true, "open link", _DesktopFolder, "Link files (*.lnk)|*.lnk", "", ".lnk", false, true);
if File.DoesExist(tFile[1]) then
local oWSH = luacom.CreateObject("wscript.shell");
local oShortCut = oWSH:CreateShortcut( tFile[1] ) ;
local cPath = oShortCut.TargetPath;
local Args = oShortCut.Arguments
Dialog.Message("Target", tFile[1].."\r\n points to\r\n".. cPath.."\r\n\r\nArguments: "..Args );
oShortCut = nil;
oWSH = nil;
collectgarbage();
end
more info
http://msdn2.microsoft.com/en-us/library/at5ydy31.aspx
EDIT:
work in this case:
C:\Documents and setting\-user-\Deskcop\your.lnk
return: real routhe and command line, work OK
but in this case:
C:\Documents and setting\-user-\Main menu\Programs\star\your.lnk
return nothing, NOT work
RizlaUK
03-23-2008, 04:26 PM
it worked in my test, are you sure you selected the right file ?
Solmos
03-23-2008, 04:29 PM
work in one case, and fails in other case :huh
jassing
03-23-2008, 04:36 PM
it worked in my test, are you sure you selected the right file ?
I was able to replicate his issue with one .lnk file I found...
Trying to figure out what's going on with it....
jassing
03-23-2008, 04:42 PM
I don't know why; but on the link I replicate the 'failure' -- adding this line of code worked.
I added it after the File.DoesExist() line
tFile[1] = File.GetShortName( tFile[1] );
Solmos
03-23-2008, 05:01 PM
I don't know why; but on the link I replicate the 'failure' -- adding this line of code worked.
I added it after the File.DoesExist() line
tFile[1] = File.GetShortName( tFile[1] );
Yes, and this code work's
thx!!:yes
jassing
03-23-2008, 05:23 PM
Yes, and this code work's
thx!!:yes
You're welcome. The help file is great; but that one is just odd -- I just took a guess on the short file name to see if it would help -- and it did.
I'll probably file a "bug report" on it tomorrow.
Solmos
03-24-2008, 04:30 AM
NEW BUG
on this shortcut:
Target= C:\WINDOWS\Installer\your.msi
Bug: show message error:
attempt to index local 'oShortCut' (a nil value)
rexzooly
03-24-2008, 04:37 AM
NEW BUG
on this shortcut:
Target= C:\WINDOWS\Installer\your.msi
Bug: show message error:
attempt to index local 'oShortCut' (a nil value)
Target= "C:\WINDOWS\Installer\your.msi"
or might be
Target= "C:\\WINDOWS\\Installer\\your.msi"
unless thats what is says you just put it fast i not sure.
Solmos
03-24-2008, 04:40 AM
Not... sorry
The bug is reading file lnk,
the name of file .lnk is = ".lnk"
No name
filename=".lnk"
Target=C:\Windows\Installer\your.msi
function fails
rexzooly
03-24-2008, 04:43 AM
Not... sorry
The bug is reading file lnk,
the name of file .lnk is = ".lnk"
No name
filename=".lnk"
Target=C:\Windows\Installer\your.msi
function fails
or ok i am sorry i am still lost how to do this my self as i want to run the SUF uninstaller that user xml via the lnk still not found away.
sorry :(
Solmos
03-24-2008, 05:34 AM
More tests:
if delete this line of code:
tFile[1] = File.GetShortName( tFile[1] );
in:
C:\documents and settings\-user\deskcop\.lnk WORK
but in:
C:\Documents and Settings\-user\star menu\program\star\.lnk FAIL
----------------
if include tFile[1] = File.GetShortName( tFile[1] ); in the code:
show error message: attempt to index local 'oShortCut' (a nil value)
jassing
03-24-2008, 10:16 AM
More tests:
if delete this line of code:
tFile[1] = File.GetShortName( tFile[1] );
in:
C:\documents and settings\-user\deskcop\.lnk WORK
but in:
C:\Documents and Settings\-user\star menu\program\star\.lnk FAIL
----------------
if include tFile[1] = File.GetShortName( tFile[1] ); in the code:
show error message: attempt to index local 'oShortCut' (a nil value)
Then I think you answered your own question -- it appears the code is not consistient in the communicaiton between WSH & LUACom. (using vb; it works consistiently)
If the 1st try yeilds NIL -- try again w/ the short path -- test the result to nil and rerun.
see if this works for you
Solmos
03-27-2008, 02:05 PM
:yes:yes:yes
Excellent Worm!!
Very thanks
It proves in depth later
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.