CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2012
    Posts
    13

    cannot run a .lnk file completely

    Hello everybody ,

    I've a simple batch file and want to execute in VB6 :

    @echo off
    TASKKILL /IM explorer.exe /F
    start explorer

    It's very simple , I name this batch to perm.cmd. But for Windows 8 , it need administrator's right to execute this perm.cmd , so I made a shortcut of it named it to perm.lnk
    In this perm.lnk's property , I change it to run with administrator's right. So when I double click this perm.lnk , it runs fine.
    The 2 task line in the perm.cmd can both be executed.

    I write this perm.cmd in VB6 and name it as test.exe like this :

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    ByVal lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Dim sPath As String
    Dim sFName As String
    --------------------------------------------------------------------------------------------
    Private Sub Form_Load()
    '-- sPath may or may not end with \
    sPath = "D:\ABC"
    sFName = "perm.lnk"
    If Len(Dir(sPath & "\" & sFName)) = 0 Then
    MsgBox "File not found: " & sPath & "\" & sFName
    Else
    ShellExecute 0, "Open", sFName, "", sPath, 0
    End If
    End Sub

    I can use VB6 test.exe to run perm.lnk , it works , but it only execute the first line in the perm.cmd , i.e.

    TASKKILL /IM explorer.exe /F

    But the second line in the perm.cmd can't be execute , i.e.

    start explorer

    I feel very strange why I can run perm.lnk perfectly , but not the test.exe in VB6 ?

    Can anyone help me please ? Thanks a lot.

  2. #2
    Join Date
    Dec 2001
    Posts
    6,332

    Re: cannot run a .lnk file completely

    I suppose the run privileges for your test.exe file may be overriding that of the others.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured