Skip to main content

VBScript for URL link creation


We had a need to create URL link of our project on users's desktop using a script. First stage the users had enough rights on their PC's so we included the required icon file also with the script and passed the following VBScript to users to click on it to create the desktop icon link.

' Definie shell object
Set objWSHShell = WScript.CreateObject("Wscript.Shell")
strDesktop = objWSHShell.SpecialFolders("Desktop")
' Copy the icon file to windows
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFileCopy = objFSO.GetFile( objWSHShell.CurrentDirectory&"\icon.ico")
objFileCopy.Copy ("C:\WINDOWS\system32\")
' Define link properties and create link
strShortcutName = "Log In" ' Shortcut Name - Edit for the wanted name
strShortcutPath = "http://thesystem.com/Login.aspx" ' Link URL - Edit to the wanted URL
strIconPath = "C:\WINDOWS\system32\icon.ico"
Set objShortcut = objWSHShell.CreateShortcut(strDesktop & "\" & strShortcutName & ".lnk")
objShortcut.TargetPath=strShortcutPath
objShortcut.IconLocation=strIconPath
objShortcut.Save

' Quit Script
WScript.Quit

But later the user access rights has been limited and were blocked accessing system folder, the link creator didn't created the link with supplied icon file. As the icon file is copied to the system folder. So the updated script would not use supplied icon file, but make use of existing system icon.

' Definie shell object
Set objWSHShell = WScript.CreateObject("Wscript.Shell")
strDesktop = objWSHShell.SpecialFolders("Desktop")

' Define link properties and create link
strShortcutName = "LogIn" ' Shortcut Name - Edit for the wanted name
strShortcutPath = "http://thesystem.com/Login.aspx" ' Link URL - Edit to the wanted URL
strIconPath = "c:\windows\system32\shell32.dll,44"
Set objShortcut = objWSHShell.CreateShortcut(strDesktop & "\" & strShortcutName & ".lnk")
objShortcut.TargetPath=strShortcutPath
objShortcut.IconLocation=strIconPath
objShortcut.Save

' Quit Script
WScript.Quit

Now the icon shown from system.

Comments

Popular posts from this blog

MySQL Dump cronjob on linux server

Creating mysql dump for production databases is very important. In case of any failure or malefic attack on DB, The only way to restore to previous state is by having proper mysql dump file. Follows an example mysql dump shell script with auto naming with dumping time stamp. Its important to create the shell scripts in unix mode, if you create on a PC, It'll add some unwanted character encoding, and it'll lead to some erroneous response on the script. #!/bin/bash today=`date +%Y%m%d%H%M` backup="cmtdbbackup-$today.sql" mysqldump -u user -ppassword mydb > /apps/mysql_dump/$backup Its important to create the shell script carefully. No spaces, unless its required. in between -u and user name, there is a space, but no space between -p and password. As per the usage of system, we can decide on which interval the cronjob could be set. normally the format of a crontab entry is like the following. * * * * * /apps/scripts/scheduled_job.sh >> /dev/null 2>...

VBScript for compressing files in a folder and send on FTP

This is a simple vbscript compression script. works flawlessly on text files even bigger than 15GB. We have a SSIS data generation package installed on our DB server which generates huge data files for data mining operations for current year, current month. The below scripts are doing the rest; compress the files and FTP to the data mining server location.   '====================================================== ' Function : Zip datamart CSV, CTL files to local server for archive purposes. '====================================================== Function WindowsZip(sFile, sZipFile, szPath, szDate)   Set oZipShell = CreateObject("WScript.Shell")    Set oZipFSO = CreateObject("Scripting.FileSystemObject")   Set LogFile = oZipFSO.CreateTextFile(szPath & "\Logs\log_" & szDate & ".log", true)   LogFile.WriteLine("=======================================")   LogFile.WriteLine(Now & " - Com...