none
how to create shortcut with variable path RRS feed

  • Question

  • hello,


    im working in a simple program which create 5 shortcuts of 5 diff apps already installed in the pc at once

    my issue is, i want this app to work on 120+ schools since they use same apps but the path of those apps diff in each school since i need to grab the shortcuts from the server of the school


    this is what i wrote so far and its working for me


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim WshShell As WshShellClass = New WshShellClass
    
            Dim DesktopFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
    
            Dim SiSMain As IWshRuntimeLibrary.IWshShortcut
    
            Dim Results As IWshRuntimeLibrary.IWshShortcut
    
            Dim Reports As IWshRuntimeLibrary.IWshShortcut
    
            Dim ARW As IWshRuntimeLibrary.IWshShortcut
    
            Dim SCH As IWshRuntimeLibrary.IWshShortcut
    
            SiSMain = CType(WshShell.CreateShortcut(DesktopFolder & "\SisMain.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            SiSMain.TargetPath = "C:\SIS_PACKAGE\sis\sis_main.exe"  'Specify target file full path
    
            SiSMain.IconLocation = "C:\SIS_PACKAGE\sis\sis_main.exe"
    
            SiSMain.Save()
    
            Results = CType(WshShell.CreateShortcut(DesktopFolder & "\Results.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            Results.TargetPath = "C:\SIS_PACKAGE\result\result.exe"  'Specify target file full path
    
            Results.IconLocation = "C:\SIS_PACKAGE\result\result.exe"
    
            Results.Save()
    
            Reports = CType(WshShell.CreateShortcut(DesktopFolder & "\Reports.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            Reports.TargetPath = "C:\SIS_PACKAGE\rep\rep.exe"  'Specify target file full path
    
            Reports.IconLocation = "C:\SIS_PACKAGE\rep\rep.exe"
    
            Reports.Save()
    
            ARW = CType(WshShell.CreateShortcut(DesktopFolder & "\ARW.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            ARW.TargetPath = "C:\SIS_PACKAGE\arw\arw_util.exe"  'Specify target file full path
    
            ARW.IconLocation = "C:\SIS_PACKAGE\arw\arw_util.exe"
    
            ARW.Save()
    
            SCH = CType(WshShell.CreateShortcut(DesktopFolder & "\SCH.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            SCH.TargetPath = "C:\SIS_PACKAGE\sch_sec\new_sec_sch.exe"  'Specify target file full path
    
            SCH.IconLocation = "C:\SIS_PACKAGE\sch_sec\new_sec_sch.exe"
    
            SCH.Save()
    
    
        End Sub

    as you can see the path atm is c:\.... but in the clients im going to use this program in, the path will be something like this : \\172.xx.xxx.09

    SiSMain.TargetPath = "\\172.xx.xxx.09\SIS_PACKAGE\sis\sis_main.exe"  'Specify target file full path

    which is the server of the school


    i didnt decide how im gonna fill this, maybe i will ask the user to enter the ip himself or just make slide menu or whatever

    my question is how to make the path variable for this. im sorry if the question is messy, please feel free to ask me if you didnt get what i mean


    Tuesday, September 4, 2018 4:02 AM

All replies

  • Hi,

    As you said, there are 120+ schools, so the IP of each school's server is different, so it is best to fill in this TargetPath yourself, create a TextBox, and fill in the TargetPath on the TextBox.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 4, 2018 5:50 AM
  • thank you for ur reply, i got it working atm by doing this:

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
            Dim WshShell As WshShellClass = New WshShellClass
    
            Dim DesktopFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
    
            Dim SiSMain As IWshRuntimeLibrary.IWshShortcut
    
            Dim Results As IWshRuntimeLibrary.IWshShortcut
    
            Dim Reports As IWshRuntimeLibrary.IWshShortcut
    
            Dim ARW As IWshRuntimeLibrary.IWshShortcut
    
            Dim SCH As IWshRuntimeLibrary.IWshShortcut
    
            Dim schoolip As String
    
    
            schoolip = TextBox1.Text
    
    
    
            SiSMain = CType(WshShell.CreateShortcut(DesktopFolder & "\Sis Main.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            SiSMain.TargetPath = ("\\" & schoolip & "\SIS_PACKAGE\sis\sis_main.exe")  'Specify target file full path
    
            SiSMain.IconLocation = ("\\" & schoolip & "\SIS_PACKAGE\sis\sis_main.exe")
    
            SiSMain.Save()
    
            Results = CType(WshShell.CreateShortcut(DesktopFolder & "\Results.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            Results.TargetPath = ("\\" & schoolip & "\SIS_PACKAGE\result\result.exe")  'Specify target file full path
    
            Results.IconLocation = ("\\" & schoolip & "\SIS_PACKAGE\result\result.exe")
    
            Results.Save()
    
            Reports = CType(WshShell.CreateShortcut(DesktopFolder & "\Reports.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            Reports.TargetPath = ("\\" & schoolip & "\SIS_PACKAGE\rep\rep.exe")  'Specify target file full path
    
            Reports.IconLocation = ("\\" & schoolip & "\SIS_PACKAGE\rep\rep.exe")
    
            Reports.Save()
    
            ARW = CType(WshShell.CreateShortcut(DesktopFolder & "\ARW MAIN.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            ARW.TargetPath = ("\\" & schoolip & "\SIS_PACKAGE\arw\arw_rpt.exe")  'Specify target file full path
    
            ARW.IconLocation = ("\\" & schoolip & "\SIS_PACKAGE\arw\arw_rpt.exe")
    
            ARW.Save()
    
            SCH = CType(WshShell.CreateShortcut(DesktopFolder & "\SCH MAIN.lnk"), IWshRuntimeLibrary.IWshShortcut)
    
            SCH.TargetPath = ("\\" & schoolip & "\SIS_PACKAGE\sch_sec\new_sec_sch.exe")  'Specify target file full path
    
            SCH.IconLocation = ("\\" & schoolip & "\SIS_PACKAGE\sch_sec\new_sec_sch.exe")
    
            SCH.Save()
    
    
        End Sub

    is there anything else u think i can do better? is it possible to let the user only enter part of the ip address since the ip should be like this 172.xx.xxx.9 all the times, i know it is possible but i would know if its possible to change the looking of the textbox to look like an ip where i can make first and last domains fixed/constant and ask the user to only fill the variable part.

    Tuesday, September 4, 2018 3:42 PM
  • also, i tried to change the icon for some of those apps by using .ico files but i didnt manage to do so, not sure what im missing

    it didnt work when i put the .ico file path in the command of .IconLocation as shown here. sadly, only one app has an icon of its .exe file which i managed to get its icon by putting the path of the .exe file in the .IconLocation command instead of putting the icon path

    example:

    SiSMain.IconLocation = ("\\" & schoolip & "\SIS_PACKAGE\sis\sis.ico")

    Tuesday, September 4, 2018 3:53 PM
  • is there anything else u think i can do better? is it possible to let the user only enter part of the ip address since the ip should be like this 172.xx.xxx.9 all the times, i know it is possible but i would know if its possible to change the looking of the textbox to look like an ip where i can make first and last domains fixed/constant and ask the user to only fill the variable part.

    Hi,

    I think that as long as the IP address is correct.

    I don't have a server here, I want to ask if your code works.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, September 5, 2018 3:19 AM
  • thank you for your replies

    yes the code works well now, only issue i have at the moment is 2 apps not getting the icon because the .exe file has no icon even tho there is .ico file in the folder but not sure if i can do anything more tbh because it is working and not broken so i will keep it as it is for now

    Friday, September 7, 2018 1:35 PM
  • Hi,

    Right click on your project name and select Properties. There is an icon in the Application, Choose an image in ICO format.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 10, 2018 5:45 AM