Shotcut van een map maken

Status
Niet open voor verdere reacties.

old Hippy

Gebruiker
Lid geworden
24 mei 2008
Berichten
911
Hallo allemaal

Ik ben bezig met een app en wil graag een snelkoppeling maken van een door mij gekozen map.
en deze op mijn bureaublad plaatsen.

Iemand die mij op weg kan helpen?

Had dit maar het werkt niet.


Code:
 Sub CreateShortcut(ByVal filePath As String, ByVal ShortcutDirectory As String, ByVal Descrpition As String)
        Try
            Dim myShortcut As IWshShortcut
            Dim wsh As New WshShell
            Dim str As String = My.Computer.FileSystem.GetDirectoryInfo(Dir).Name.Replace(My.Computer.FileSystem.GetDirectoryInfo(Dir).Name, Nothing)

            myShortcut = CType(wsh.CreateShortcut(ShortcutDirectory & "\" & str & ".lnk"), IWshShortcut)


            With myShortcut
                .TargetPath = filePath
                .Description = Descrpition
                .WindowStyle = 1
                .IconLocation = filePath & ", 0"
                .Save()
            End With

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub



    Private Sub BT_Maakshotcut_Click(sender As System.Object, e As System.EventArgs) Handles BT_Maakshotcut.Click
        If Not OpenFileDialog2.ShowDialog = Windows.Forms.DialogResult.Cancel Then

        End If
    End Sub

    Private Sub BT_Shctcutpath_Click(sender As System.Object, e As System.EventArgs) Handles BT_Shctcutpath.Click
        If Not FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            CreateShortcut(OpenFileDialog2.FileName, FolderBrowserDialog1.SelectedPath, "Descrpition")
        End If    End Sub
 
Laatst bewerkt:
Deze code werkt met programma's en documenten maar niet voor directories
En dat wil ik graag!

Code:
 Sub CreateShortcut(ByVal filePath As String, ByVal ShortcutDirectory As String, ByVal Descrpition As String)
        Try
            Dim myShortcut As IWshShortcut
            Dim wsh As New WshShell
            Dim str As String = My.Computer.FileSystem.GetFileInfo(filePath).Name.Replace(My.Computer.FileSystem.GetFileInfo(filePath).Name, Nothing)
            myShortcut = CType(wsh.CreateShortcut(ShortcutDirectory & "\" & str & ".lnk"), IWshShortcut)
            With myShortcut
                .TargetPath = filePath
                .Description = Descrpition
                .WindowStyle = 1
                .IconLocation = filePath & ", 0"
                .Save()
            End With

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub BT_Maakshotcut_Click(sender As System.Object, e As System.EventArgs) Handles BT_Maakshotcut.Click
        If Not OpenFileDialog2.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            CreateShortcut(OpenFileDialog2.FileName, FolderBrowserDialog1.SelectedPath, "My Map")
        End If
    End Sub

    Private Sub BT_Shctcutpath_Click(sender As System.Object, e As System.EventArgs) Handles BT_Shctcutpath.Click
        If Not FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            ' CreateShortcut(OpenFileDialog2.FileName, FolderBrowserDialog1.SelectedPath, "My Map")
        End If
    End Sub
 
Hallo allemaal

Ik ben weer wat verder kan nu een snelkoppeling op het bureaublad maken van een door mij gekozen map.
Maar wil nog graag dat de naam van die map word ingevuld.
Nu moet ik deze nog vooruit in de textbox zetten.
Iemand een Idee ????
Hier de gebruikte code


Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            Dim wsh As Object = CreateObject("WScript.Shell")
            wsh = CreateObject("WScript.Shell")
            Dim MyShortcut, DesktopPath

            ' Read desktop path using WshSpecialFolders object
            DesktopPath = wsh.SpecialFolders("Desktop")
            MyShortcut = wsh.CreateShortcut(DesktopPath & "\" & TextBox1.Text & ".lnk")

            ' Set shortcut object properties and save it
            MyShortcut.TargetPath = wsh.ExpandEnvironmentStrings(FolderBrowserDialog1.SelectedPath)
            MyShortcut.WorkingDirectory = wsh.ExpandEnvironmentStrings(FolderBrowserDialog1.SelectedPath)
            MyShortcut.WindowStyle = 4
            'Use this next line to assign a icon other then the default icon for the exe
            'MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings("path to a file with an embeded icon", icon index number)
            'Save the shortcut
            MyShortcut.Save()
        End If
    End Sub
 
Hallo is opgelost

Hier de oplossing voor wie het ook wil.
om te testen form met button

Code:
Imports IWshRuntimeLibrary
Imports System.IO

Public Class Form1

    Private Property dirCSV As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            Dim wsh As Object = CreateObject("WScript.Shell")
            wsh = CreateObject("WScript.Shell")
            Dim MyShortcut, DesktopPath, MyShortcutName
            ' Read desktop path using WshSpecialFolders object
            DesktopPath = wsh.SpecialFolders("Desktop")
            MyShortcutName = FolderBrowserDialog1.SelectedPath
            MyShortcutName = Microsoft.VisualBasic.Right(MyShortcutName, Len(MyShortcutName) - InStrRev(MyShortcutName, "\"))
            MyShortcut = wsh.CreateShortcut(DesktopPath & "\" & MyShortcutName & ".lnk")
            ' Set shortcut object properties and save it
            MyShortcut.TargetPath = wsh.ExpandEnvironmentStrings(FolderBrowserDialog1.SelectedPath)
            MyShortcut.WorkingDirectory = wsh.ExpandEnvironmentStrings(FolderBrowserDialog1.SelectedPath)
            MyShortcut.WindowStyle = 4
            'Use this next line to assign a icon other then the default icon for the exe
            'MyShortcut.IconLocation = WSHShell.ExpandEnvironmentStrings("path to a file with an embeded icon", icon index number)
            'Save the shortcut
            MyShortcut.Save()
        End If
    End Sub

   
End Class
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan