As could access the command line of a shortcut?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Solmos
    New Member
    • Aug 2006
    • 355

    As could access the command line of a shortcut?

    As could access the command line of a shortcut?

    thx!!
  • jassing
    Indigo Rose Customer
    • Jan 2001
    • 3124

    #2
    Originally posted by Solmos View Post
    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:

    for some useful info -- you'd need to combine that with LuaCom


    If that doesn't get you going -- let me know and I'll give it a go in my spare time.
    -josh

    Comment

    • Solmos
      New Member
      • Aug 2006
      • 355

      #3
      Yes, get shortcut properties

      needed, target shortcut and command line shorcut.

      please, create one example.

      very thanks

      Comment

      • jassing
        Indigo Rose Customer
        • Jan 2001
        • 3124

        #4
        Originally posted by Solmos View Post
        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

        Comment

        • RizlaUK
          Indigo Rose Customer
          • May 2006
          • 5552

          #5
          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:


          it seems you access the .lnk file by using the "CreateShortcut" method and access the "TargetPath" or "Arguments" by useing the properties
          Embrace change in your life, you never know, it could all work out for the best

          Comment

          • jassing
            Indigo Rose Customer
            • Jan 2001
            • 3124

            #6
            Originally posted by Solmos View Post
            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)

            Code:
            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

            Comment

            • RizlaUK
              Indigo Rose Customer
              • May 2006
              • 5552

              #7
              and arguments

              Code:
              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
              Embrace change in your life, you never know, it could all work out for the best

              Comment

              • Solmos
                New Member
                • Aug 2006
                • 355

                #8
                jassing detec s good the targetshortcut, but not command line

                RizlaUK this code not work. If target shorcut contain command line, return nothing

                Originally posted by RizlaUK View Post
                and arguments

                Code:
                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
                Last edited by Solmos; 03-23-2008, 03:27 PM.

                Comment

                • RizlaUK
                  Indigo Rose Customer
                  • May 2006
                  • 5552

                  #9
                  it worked in my test, are you sure you selected the right file ?
                  Embrace change in your life, you never know, it could all work out for the best

                  Comment

                  • Solmos
                    New Member
                    • Aug 2006
                    • 355

                    #10
                    work in one case, and fails in other case

                    Comment

                    • jassing
                      Indigo Rose Customer
                      • Jan 2001
                      • 3124

                      #11
                      Originally posted by RizlaUK View Post
                      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....

                      Comment

                      • jassing
                        Indigo Rose Customer
                        • Jan 2001
                        • 3124

                        #12
                        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

                        Code:
                        tFile[1] = File.GetShortName( tFile[1] );

                        Comment

                        • Solmos
                          New Member
                          • Aug 2006
                          • 355

                          #13
                          Originally posted by jassing View Post
                          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

                          Code:
                          tFile[1] = File.GetShortName( tFile[1] );
                          Yes, and this code work's

                          thx!!:yes

                          Comment

                          • jassing
                            Indigo Rose Customer
                            • Jan 2001
                            • 3124

                            #14
                            Originally posted by Solmos View Post
                            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.

                            Comment

                            • Solmos
                              New Member
                              • Aug 2006
                              • 355

                              #15
                              NEW BUG

                              on this shortcut:

                              Code:
                              Target= C:\WINDOWS\Installer\your.msi

                              Bug: show message error:

                              Code:
                              attempt to index local 'oShortCut' (a nil value)

                              Comment

                              Working...
                              X