{"id":1017,"date":"2018-10-22T14:14:19","date_gmt":"2018-10-22T14:14:19","guid":{"rendered":"http:\/\/www.budus.it\/Blog\/?p=1017"},"modified":"2019-09-09T09:05:10","modified_gmt":"2019-09-09T09:05:10","slug":"vbs-creare-collegamento-windows-shortcut-in-visual-basic","status":"publish","type":"post","link":"https:\/\/www.budus.it\/Blog\/vbs-creare-collegamento-windows-shortcut-in-visual-basic\/","title":{"rendered":"VBS: Creare Collegamento Windows (Shortcut) in Visual Basic"},"content":{"rendered":"<p>Incollo qui il sorgente di un Visual Basic Script per Windows che consente di creare sul Desktop di Windows un collegamento.<\/p>\n<p>Pu\u00f2 essere lanciato da DOS, quindi, da un comune file batch. Richiede 8 parametri, ovvero:<\/p>\n<ol>\n<li>Nome del Link (cio\u00e8 del file .lnk)<\/li>\n<li>Target (cio\u00e8 il programma da lanciare)<\/li>\n<li>Argomenti (da passare al Target, facoltativi)<\/li>\n<li>Working Directory (la cartella dalla quale lanciare il Target)<\/li>\n<li>Descrizione del Link<\/li>\n<li>Combinazione Tasti Scelta Rapida (facoltativa)<\/li>\n<li>Icona<\/li>\n<li>Codice Stile Finestra che pu\u00f2 avere 3 valori: 1, 2 e 3<\/li>\n<\/ol>\n<p>Con il valore &#8220;1&#8221;, in stile finestra, si ottiene la memorizzazione dello stato della finestra, con 2 \u00e8 massimizzata e con 3 minimizzata ad icona.<\/p>\n<p>Questo il sorgente del file che io ho chiamato &#8220;make_windows_link.vbs&#8221;:<\/p>\n\n\n<pre class=\"wp-block-code\"><code>'********************************************************************************\n' UDA'Software 2018\n' VERSIONE 2018-11-19\n'\n' QUESTO SCRIPT HA LO SCOPO DI CREARE UN LINK WINDOWS PER L'AVVIO DI UN\n' PROGRAMMA.\n'\n' PER FUNZIONARE NECESSITA CHE VENGANO SPECIFICATI, IN PRECISO ORDINE, I SEGUENTI\n' PARAMETRI:\n'\n' 1) NOME DEL LINK (SENZA ESTENSIONE, VIENE AGGIUNTA IN AUTOMATICO)\n' 2) TARGET\n' 3) ARGOMENTI\n' 4) WORKING DIRECTORY (Directory di lancio)\n' 5) DESCRIZIONE LINK\n' 6) COMBINAZIONE TASTI SCELTA RAPIDA\n' 7) ICONA\n' 8) CODICE STILE FINESTRA (DESCRIZIONE FORNITA DA Microsoft):\n' \n'    1 - activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position.\n'    3 - Activates the window and displays it as a maximized window.\n'    7 - Minimizes the window and activates the next top-level window.\n' \n' 9) PERCORSO DOVE CREARE IL LINK (EX: %PUBLIC%\\Desktop )\n'\n' ESEMPIO:\n'\n' make_windows_link.vbs \"Link Guida Windows\" \"C:\\Windows\\winhlp32.exe\" \"\" \"C:\\Windows\" \"Lancio della Guida\" \"CTRL+ALT+SHIFT+H\" \"C:\\Windows\\winhlp32.exe\" 1\n' make_windows_link.vbs \"Link Guida Windows\" \"C:\\Windows\\winhlp32.exe\" \"\" \"C:\\Windows\" \"Lancio della Guida\" \"CTRL+ALT+SHIFT+H\" \"C:\\Windows\\winhlp32.exe\" 1 \"%PUBLIC%\\Desktop\"\n'\n'********************************************************************************\nDim sLinkName \t\t\t' 0 Nome del Link\nDim sTargetPath\t\t\t' 1 Target del link\nDim sArguments\t\t\t' 2 Argomenti del target\nDim sWorkingDirectory\t' 3 Working Directory\nDim sDescription\t\t' 4 Descrizione del Link\nDim sHotKey\t\t\t\t' 5 Combinazione Tasti Scelta Rapida\nDim sIconLocation\t\t' 6 Icona da utilizzare\nDim iWindowStyle \t\t' 7 Stile Finestra\n\n'********************************************************************************\niExitCode = 1\t' PER DEFAULT IL CODICE DI USCITA E' ERRORE GENERICO\n\nSet args = WScript.Arguments\n\nIf args.Count &lt; 8 Then\n\tMsgBox \"Procedura invocata senza gli 8 parametri previsi.\", vbOKOnly &amp; vbCritical, \"ERRORE\"\n\twscript.Quit(iExitCode)\nEnd If\n\n' Associazione parametri\nsLinkName = args.Item(0)\nsTargetPath = args.Item(1)\nsArguments = args.Item(2)\nsWorkingDirectory = args.Item(3)\nsDescription = args.Item(4)\nsHotKey = args.Item(5)\nsIconLocation = args.Item(6)\niWindowStyle = args.Item(7)\n\n'********************************************************************************\nSet oShell = CreateObject(\"WScript.Shell\")\nSet fso = CreateObject(\"Scripting.FileSystemObject\")\n\n'********************************************************************************\nsDesktopPath = oShell.SpecialFolders(\"Desktop\")\n\nIf args.Count >= 9 Then\n\tsDesktopPath = args.Item(8)\n\t\n\tIf Not fso.FolderExists(sDesktopPath) Then\n\t\tDebug.Write \"Cartella \" + sDesktopPath + \" inesistente\"\n\t\tiExitCode = 3\n\t\tWScript.Quit(iExitCode)\n\tEnd If\nEnd If\n\n'********************************************************************************\nSet oLink = oShell.CreateShortcut(sDesktopPath + \"\\\\\" + sLinkName + \".lnk\")\noLink.TargetPath = sTargetPath\noLink.Arguments = sArguments\noLink.WorkingDirectory = sWorkingDirectory\noLink.Description = sDescription\noLink.HotKey = sHotKey\noLink.IconLocation = sIconLocation\noLink.WindowStyle = iWindowStyle\noLink.Save()\n\n'********************************************************************************\nIf fso.FileExists(sDesktopPath + \"\\\\\" + sLinkName + \".lnk\") Then\n\tiExitCode = 0\nElse\n\tiExitCode = 2\nEnd If\n\n'********************************************************************************\n' USCITA\n' CODICI DI USCITA: 0 = OK \/ 1 = ERRORE ARGOMENTI \/ 2 = ERRORE FILE\nWScript.Quit(iExitCode)\n'********************************************************************************\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Va preso e copiato dentro un file con estensione &#8220;.vbs&#8221; (ex: make_windows_link.vbs ); lo si pu\u00f2 creare anche con Blocco Note o qualsiasi altro editor di testo ASCII.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Per usarlo lo si pu\u00f2 lanciare da un file batch (.bat) o qualsiasi altra cosa possa eseguire comandi del sistema operativo; a titolo di esempio incollo un file batch che lo lancia e che ci si pu\u00f2 personalizzare sostituendo i vari &#8220;%1&#8221;, &#8220;%2&#8221;, ecc&#8230; con quello che si vuole:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@echo OFF\ntitle Creazione Icona %5\nrem %1 : Nome del Link\nrem %2 : Target\nrem %3 : Parametri\nrem %4 : Cartella Partenza\nrem %5 : Descrizione\nrem %6 : Hotkey\nrem %7 : Icona\nECHO Creazione Icona %5\nmake_windows_link.vbs\" %1 %2 %3 %4 %5 %6 %7 3 %8\nIF NOT \"%ERRORLEVEL%\"==\"0\" (\n\tECHO ********************************************************************************\n\tECHO ATTENZIONE: NON RISULTA POSSIBILE CREARE L'ICONA: \n\tECHO             %5\n\tECHO.\n\tECHO PARAMETRI:\n\tECHO.\n\tECHO 1 : %1\n\tECHO 2 : %2\n\tECHO 3 : %3\n\tECHO 4 : %4\n\tECHO 5 : %5\n\tECHO 6 : %6\n\tECHO 7 : %7\n\tECHO 8 : %8\n\tECHO.\n\tECHO ********************************************************************************\n)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Incollo qui il sorgente di un Visual Basic Script per Windows che consente di creare sul Desktop di Windows un collegamento. Pu\u00f2 essere lanciato da DOS, quindi, da un comune file batch. Richiede 8 parametri, ovvero: Nome del Link (cio\u00e8 del file .lnk) Target (cio\u00e8 il programma da lanciare) Argomenti (da passare al Target, facoltativi) &hellip; <a href=\"https:\/\/www.budus.it\/Blog\/vbs-creare-collegamento-windows-shortcut-in-visual-basic\/\" class=\"more-link\">Leggi tutto<span class=\"screen-reader-text\"> &#8220;VBS: Creare Collegamento Windows (Shortcut) in Visual Basic&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57],"tags":[99,250,98],"class_list":["post-1017","post","type-post","status-publish","format-standard","hentry","category-development","tag-script","tag-vbs","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/posts\/1017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/comments?post=1017"}],"version-history":[{"count":4,"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/posts\/1017\/revisions"}],"predecessor-version":[{"id":1141,"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/posts\/1017\/revisions\/1141"}],"wp:attachment":[{"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/media?parent=1017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/categories?post=1017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.budus.it\/Blog\/wp-json\/wp\/v2\/tags?post=1017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}