Solved

Shortcuts and Files

Posted on 1997-06-21
12
344 Views
Last Modified: 2008-02-26
Hi there...I am useing Visual Basic 5.0 Professional, and would like to know how to do the following :

1) Create a program group, and shortcut file on the start menu (say, "My Program" - group...and "Program" - .lnk file to start program, in that group.

2) How do you copy a file using VB...say, "File1.txt" in C:\Windows to "File2.txt" in C:\My Program...or something like that.

Thanks,
Oreg
0
Comment
Question by:oreg
  • 6
  • 6
12 Comments
 
LVL 1

Expert Comment

by:quekky
Comment Utility
look at the example program used by VB's make installation program
0
 

Author Comment

by:oreg
Comment Utility
Telling me WHERE to look might help, I looked it over, which modules/forms contain what I want, and what is the code I want?
0
 
LVL 1

Expert Comment

by:quekky
Comment Utility
I can't remember where it is, but it is around the program that auto-creates installation file for you, in the VB directory
VB 3.0 and 4.0 have this program, I think 5.0 should have
0
 
LVL 1

Expert Comment

by:quekky
Comment Utility
just look around VB's directory, it's a directory with a lot BAS, FRM and 1 project file and the codes are quite long and diffucuilt to understand
0
 

Author Comment

by:oreg
Comment Utility
Sorry, I am basically new to VB, and I looked through it, and most of it looked garbage to me...how about a small example like in my question...does not have to be fancy, just work.


0
 
LVL 1

Expert Comment

by:quekky
Comment Utility
for the shortcut, you have to wait til i get back to school and copy the souce code to you

as for the copying,
    Name "c:\file1.txt" As "c:\file2.bak"

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:oreg
Comment Utility
For that 'name' command, will it COPY, or rename?
0
 
LVL 1

Expert Comment

by:quekky
Comment Utility
it just copy
to delete the file later, use KILL
0
 

Author Comment

by:oreg
Comment Utility
Okay, Name and Kill are nice.   What about that code for creating a program group, and icons in that group?


0
 

Author Comment

by:oreg
Comment Utility
Sorry, It seems you cannot, or will not answer this question.
0
 
LVL 1

Accepted Solution

by:
quekky earned 40 total points
Comment Utility
this is to create groups and links in win 3.x and win 95
very blur, some functions are not not included, but you can guess from the name

i can e-mail you this if you give me your address

------------------------------cut--------------------------------
   Begin VB.Label lblDDE
      AutoSize        =   -1  'True
      BorderStyle     =   1  'Fixed Single
      Caption         =   "This label is used for DDE connection to the Program Manager"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   15
      TabIndex        =   0
      Top             =   1515
      Visible         =   0   'False
      Width           =   4485
   End


sub main()
    If fCreateGroup Then
        strGroupName = gstrAppName
        If gstrAppExe = "" Then
            strGrpPath = Left$(gstrAppName, InStr(gstrAppName, gstrSEP_EXT)) & strEXT_GRP
        Else
            strGrpPath = Left$(gstrAppExe, InStr(gstrAppExe, gstrSEP_EXT)) & strEXT_GRP
        End If
'        strGroupName = "StartUp"
'        strGrpPath = "StartUp" & strEXT_GRP
        '
        'Go ahead and create the main program group
        '
        CreateOSProgramGroup frmSetup1, strGroupName, strGrpPath
        fMainGroupWasCreated = True
    End If

    If gstrAppExe <> "" Then
        '
        'Create the main application icon or link
        '
        CreateOSLink frmSetup1, gsDest.strAppDir & gstrAppExe, "", gstrAppName
    End If
end sub

'-----------------------------------------------------------
' setup.bas
'-----------------------------------------------------------

Declare Function OSfCreateShellGroup Lib "STKIT432.DLL" Alias "fCreateShellFolder" (ByVal lpstrDirName As String) As Long
Declare Function OSfCreateShellLink Lib "STKIT432.DLL" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String) As Long
Declare Function OSfRemoveShellLink Lib "STKIT432.DLL" Alias "fRemoveShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String) As Long
Private Declare Function OSGetLongPathName Lib "STKIT432.DLL" Alias "GetLongPathName" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long


' SUB: CreateOSProgramGroup
'
' Calls CreateProgManGroup under Windows NT or
' CreateShellGroup under Windows 95
'-----------------------------------------------------------
'
Sub CreateOSProgramGroup(frm As Form, ByVal strFolderName As String, ByVal
strGroupPath As String)
#If Win32 And LOGGING Then
    If TreatAsWin95() Then
        CreateShellGroup strFolderName
    Else
#End If
        CreateProgManGroup frm, strFolderName, strGroupPath
#If Win32 And LOGGING Then
    End If
#End If
End Sub

'-----------------------------------------------------------
' SUB: CreateShellGroup
'
' Creates a new program group off of Start>Programs in the
' Windows 95 shell if the specified folder doesn't already exist.
'
' IN: [strFolderName] - text name of the folder.
'                      This parameter may not contain
'                      backslashes.
'                      ex: "My Application" - this creates
'                        the folder Start>Programs>My Application
'     [fLog] - Whether or not to write to the logfile (default
'                is true if missing)
'-----------------------------------------------------------
'
#If Win32 And LOGGING Then
Sub CreateShellGroup(ByVal strFolderName As String, Optional ByVal fLog)
    If IsMissing(fLog) Then
        fLog = True
    End If

    ReplaceDoubleQuotes strFolderName

    'Save this folder name for use with the next call
    'to CreateShellLink()
    mstrLastCreatedShellGroup = strFolderName

    If strFolderName = "" Then
        Exit Sub
    End If

    If fLog Then
        NewAction gstrKEY_SHELLFOLDER, """" & strFolderName & """"
    End If

Retry:

    Dim fSuccess As Boolean
    fSuccess = OSfCreateShellGroup(strFolderName)
    If fSuccess Then
        If fLog Then
            CommitAction
        End If
    Else
        Select Case (MsgError(ResolveResString(resCANTCREATEPROGRAMGROUP, "|1", strFolderName), vbRetryCancel Or vbExclamation, gstrTitle))
        Case vbCancel
            ExitSetup frmSetup1, gintRET_EXIT
            GoTo Retry
        End Select

        GoTo Retry
    End If
End Sub

'-----------------------------------------------------------
' SUB: CreateProgManGroup
'
' Creates a new group in the Windows program manager if
' the specified groupname doesn't already exist
'
' IN: [frm] - form containing a label named 'lblDDE'
'     [strGroupName] - text name of the group
'     [strGroupPath] - file system name of the group file,
'                      ex: 'c:\windows\myapp.grp'.  Under
'                      Win32, this parameter is passed, but
'                      it is ignored.
'     [fLog] - Whether or not to write to the logfile (default
'                is true if missing)
'-----------------------------------------------------------
'
Sub CreateProgManGroup(frm As Form, ByVal strGroupName As String, ByVal strGroupPath As String, Optional ByVal fLog)
    '
    'Call generic progman DDE function with flag to add a group
    '
    If IsMissing(fLog) Then
        fLog = True
    End If

    'Save the group name for use in logging on the next call to CallProgManItem
    mstrLastCreatedShellGroup = strGroupName

    'Perform the DDE to create the group
    PerformDDE frm, strGroupName, strGroupPath, gstrNULL, mintDDE_GRPADD, fLog
End Sub

'-----------------------------------------------------------
' SUB: PerformDDE
'
' Performs a Program Manager DDE operation as specified
' by the intDDE flag and the passed in parameters.
' Possible operations are:
'
'   mintDDE_ITEMADD:  Add an icon to the active group
'   mintDDE_GRPADD:   Create a program manager group
'
' IN: [frm] - form containing a label named 'lblDDE'
'     [strGroup] - name of group to create
'     [strTitle] - title of icon or group
'     [strCmd] - command line for icon/item to add
'     [intDDE] - ProgMan DDE action to perform
'-----------------------------------------------------------
'
Sub PerformDDE(frm As Form, ByVal strGroup As String, ByVal strCmd As String, ByVal strTitle As String, ByVal intDDE As Integer, ByVal fLog As Boolean)
    Const strCOMMA$ = ","
    Const strRESTORE$ = ", 1)]"
    Const strENDCMD$ = ")]"
    Const strSHOWGRP$ = "[ShowGroup("
    Const strADDGRP$ = "[CreateGroup("
    Const strREPLITEM$ = "[ReplaceItem("
    Const strADDITEM$ = "[AddItem("

    Dim intIdx As Integer        'loop variable

    SetMousePtr gintMOUSE_HOURGLASS

    '
    'Initialize for DDE Conversation with Windows Program Manager in
    'manual mode (.LinkMode = 2) where destination control is not auto-
    'matically updated.  Set DDE timeout for 10 seconds.  The loop around
    'DoEvents() is to allow time for the DDE Execute to be processsed.
    '

    Dim intRetry As Integer
    For intRetry = 1 To 20
        On Error Resume Next
        frm.lblDDE.LinkTopic = "PROGMAN|PROGMAN"
        If Err = 0 Then
            Exit For
        End If
        DoEvents
    Next intRetry

    frm.lblDDE.LinkMode = 2
    For intIdx = 1 To 10
      DoEvents
    Next
    frm.lblDDE.LinkTimeout = 100

    On Error Resume Next

    If Err = 0 Then
        Select Case intDDE
        Case mintDDE_ITEMADD
            'The item will be created in the most-recently created group
            #If Win32 And LOGGING Then
                'Write the action to the logfile
                If fLog Then
                    NewAction gstrKEY_PROGMANITEM, """" & strGroup & """" & ", " & """" & strTitle & """"
                End If
            #End If
            frm.lblDDE.LinkExecute strREPLITEM & strTitle & strENDCMD
            Err = 0
            frm.lblDDE.LinkExecute strADDITEM & strCmd & strCOMMA & strTitle &
            Err = 0
            frm.lblDDE.LinkExecute strADDITEM & strCmd & strCOMMA & strTitle & String$(3, strCOMMA) & strENDCMD
        Case mintDDE_GRPADD
            #If Win16 Then
                frm.lblDDE.LinkExecute strADDGRP & strGroup & strCOMMA & strCmd & strENDCMD
            #Else
                ' Win32
                #If LOGGING Then
                    'Write the action to the logfile
                    If fLog Then
                        NewAction gstrKEY_PROGMANGROUP, """" & strGroup & """"
                    End If
                #End If
                frm.lblDDE.LinkExecute strADDGRP & strGroup & strENDCMD
            #End If
            frm.lblDDE.LinkExecute strSHOWGRP & strGroup & strRESTORE
        End Select
    End If


    '
    'Disconnect DDE Link
    '

    frm.lblDDE.LinkMode = 0
    frm.lblDDE.LinkTopic = ""


    SetMousePtr gintMOUSE_DEFAULT

    #If Win32 And LOGGING Then
        If fLog Then
            CommitAction
        End If
    #End If

    Err = 0
End Sub

'-----------------------------------------------------------
' SUB: CreateOSLink
'
' Calls CreateProgManItem under Windows NT or
' CreateFolderLink under Windows 95.
'
' If fLog is missing, the default is True.
'-----------------------------------------------------------
'
Sub CreateOSLink(frm As Form, ByVal strLinkPath As String, ByVal strLinkArguments As String, ByVal strLinkName As String, Optional ByVal fLog)
    If IsMissing(fLog) Then
        fLog = True
    End If

#If Win32 And LOGGING Then
    If TreatAsWin95() Then
        CreateShellLink strLinkPath, strLinkArguments, strLinkName, fLog
    Else
#End If
        #If Win32 Then
            strLinkPath = GetShortPathName(strLinkPath)
        #End If
        CreateProgManItem frm, strLinkPath & " " & strLinkArguments, strLinkName, fLog
#If Win32 And LOGGING Then
    End If
#End If
End Sub

'-----------------------------------------------------------
' SUB: CreateShellLink
'
' Creates (or replaces) a link in either Start>Programs or
' any of its immediate subfolders in the Windows 95 shell.
'
' IN: [strLinkPath] - full path to the target of the link
'                     Ex: 'c:\Program Files\My Application\MyApp.exe"
'     [strLinkArguments] - command-line arguments for the link
'                     Ex: '-f -c "c:\Program Files\My Application\MyApp.dat"
-q'
'     [strLinkName] - text caption for the link
'     [fLog] - Whether or not to write to the logfile (default
'                is true if missing)
'
' OUT:
'   The link will be created in the most recent folder created
'   by a call to CreateShellGroup.  If this function has
'   never been called, then the link will be created directly
'   in the Start>Programs menu, and not in any subfolder.

'-----------------------------------------------------------
'
#If Win32 And LOGGING Then
Sub CreateShellLink(ByVal strLinkPath As String, ByVal strLinkArguments As String, ByVal strLinkName As String, Optional ByVal fLog)
    If IsMissing(fLog) Then
        fLog = True
    End If

    If fLog Then
        NewAction gstrKEY_SHELLLINK, """" & mstrLastCreatedShellGroup & """" & ", " & """" & strLinkName & """"
    End If

    ReplaceDoubleQuotes strLinkName

Retry:

    Dim fSuccess As Boolean
    fSuccess = OSfCreateShellLink(mstrLastCreatedShellGroup & "", strLinkName, strLinkPath, strLinkArguments & "") 'the path should never be enclosed in double quotes
    If fSuccess Then
        If fLog Then
            CommitAction
        End If
    Else
        Select Case (MsgError(ResolveResString(resCANTCREATEPROGRAMICON, "|1", strLinkName), vbAbortRetryIgnore Or vbExclamation, gstrTitle))
        Case vbAbort
            ExitSetup frmSetup1, gintRET_ABORT
            GoTo Retry
        Case vbRetry
            GoTo Retry
        Case vbIgnore
            If fLog Then
                AbortAction
            End If
        End Select
    End If
End Sub
#End If

' SUB: CreateProgManItem
'
' Creates (or replaces) a program manager icon in the active
' program manager group
'
' IN: [frm] - form containing a label named 'lblDDE'
'     [strCmdLine] - command line for the item/icon,
'                    Ex: 'c:\myapp\myapp.exe'
'                    Note:  If this path contains spaces
'                      or commas, it should be enclosed
'                      with quotes so that it is properly
'                      interpreted by Windows (see AddQuotesToFN)
'     [strIconTitle] - text caption for the icon
'     [fLog] - Whether or not to write to the logfile (default
'                is true if missing)
'
' PRECONDITION: CreateProgManGroup has already been called.  The
'               new icon will be created in the group last created.
'-----------------------------------------------------------
'
Sub CreateProgManItem(frm As Form, ByVal strCmdLine As String, ByVal strIconTitle As String, Optional ByVal fLog)
    '
    'Call generic progman DDE function with flag to add an item
    '
    If IsMissing(fLog) Then
        fLog = True
    End If
    PerformDDE frm, mstrLastCreatedShellGroup, strCmdLine, strIconTitle, mintDDE_ITEMADD, fLog
End Sub

0
 

Author Comment

by:oreg
Comment Utility
I was not totally happy by this answer, but okay.  I wanted more of a small example using the code.  Thanks anyhow
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now