요래 저래 회사에서 이것저것 일을 하고있었는데, 뜸금없는 일이 추가가 되었습니다.
프로젝트라고 하기에는 너무 작고, 오랫만에 VB를 잡자니 너무 오랜시간동안 쉬었고...
C로 해야하나 Java로 해야하나.. 하다가 역시 개발하기가 쉬운건 VB인지라..
이번에는 바로가기 아이콘을 만들어볼 예정입니다.
개발을 하다보니 걸리는게 두가지였는데, 아이콘과, 관리자 권한이었습니다.
웹사이트 바로가기 아이콘을 만드는 부분이었는데..
사이트 주소로만 가져오자니 원하는 아이콘을 받아 올 수가 없는 점이 있었다라는 것
C:\ 드라이브에 폴더를 생성시키고, 아이콘 파일을 다운로드했을 때 운영체제에 따라 권한 제약이 걸리는건 아닐지..
요리조리 머리를 굴리다가..
C:\Users\CurrentUserName 안에다가 폴더를 생성하고 받음 되지 않을까 하고...
☆ 설정
메뉴 > 프로젝트 > 참조추가 > COM > Micorsoft Scripting Runtime 추가
☆ 선언부
Option Explicit On
Imports Scripting
Imports System.IO
Imports System.Net
Public Class Main
Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal _
lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal _
lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
☆ 현재 로그인한 사용자 이름 구하기
Dim userName As String
userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name
Dim startPoint As Integer = userName.IndexOf("\") + 1, endPoint As Integer = (userName.Length - startPoint)
userName = userName.Substring(startPoint, endPoint)
☆ 아이콘을 받을 폴더 생성
Public Function makeFolder(ByVal userName)
Dim path As String = "C:\Users\" & userName & "\FolderName"
Dim exists As Boolean
exists = System.IO.Directory.Exists(path)
If (Not exists) Then
System.IO.Directory.CreateDirectory(path)
End If
Return path
End Function
☆ 아이콘 다운로드
Public Function getFavicon(ByVal dirPath)
Dim exists As Boolean
Dim iconPath As String = dirPath & "\favicon.ico"
exists = System.IO.Directory.Exists(iconPath)
If (Not exists) Then
Dim httpclient = New WebClient
AddHandler httpclient.DownloadFileCompleted, AddressOf Downloaded
httpclient.DownloadFileAsync(New Uri("http://iconURL"), (iconPath))
End If
Return iconPath
End Function
☆ 바로가기 아이콘 만들기
Public Sub CreateShortCut(ByVal folderPath, ByVal iconPath)
Dim WshShell As Object
Dim strDesktop As Object
Dim oUrlLink As Object
WshShell = CreateObject("WScript.Shell")
Dim CheckFile As New FileSystemObject
Dim target As String = siteURL ''ex) http://moelcano.tistory.com
strDesktop = WshShell.SpecialFolders("Desktop")
If (folderPath = "Desktop") Then
strDesktop = WshShell.SpecialFolders("Desktop")
End If
If (folderPath = "Favorites") Then
strDesktop = WshShell.SpecialFolders("Favorites")
End If
oUrlLink = WshShell.CreateShortcut(strDesktop & "\FileName.lnk")
oUrlLink.TargetPath = target
oUrlLink.WindowStyle = 1
'oUrlLink.Hotkey = "CTRL+SHIFT+F"
oUrlLink.IconLocation = iconPath
oUrlLink.Description = "Description"
oUrlLink.WorkingDirectory = strDesktop
oUrlLink.TargetPath = target
oUrlLink.Save()
oUrlLink = Nothing
End Sub
와 같이 작성하시면 원하는 바로가기 아이콘을 만드실 수 있습니다.
기타 궁금사항은 댓글 부탁드립니다~