本文介绍了符号链接visual studio 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 我需要在vb.net中创建一个符号链接,我已经知道我需要提升已经完成的权限,但我不知道从哪里去的 这是我到目前为止: 进口 System.Text Imports System.IO Imports System.Runtime.InteropServices 公开 类主要< dllimport( kernel32.dll)> _ 私有 共享 功能 CreateSymbolicLink( ByVal lpSymlinkFileName As String , ByVal lpTargetFileName 作为 字符串, ByVal dwFlags 作为 整数)作为 布尔 结束 功能 私有 Sub StartBtn_Click ( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 StartBtn.Click 尝试 CreateSymbolicLink(SteamFrom,SteamTo, 1 ) Application.DoEvents() Catch ex As Exception MsgBox(ex .ToString) 返回 结束 尝试 MsgBox( 完成) 结束 Sub 结束 类 解决方案 在这里是一个工作样本: Imports System.Text Imports System.IO Imports System.Runtime.InteropServices Module Module1 < dllimport( kernel32.dll,> _ 私有 功能 CreateSymbolicLink( ByVal lpSymlinkFileName 作为 字符串, ByVal lpTargetFileName 作为 字符串, ByVal dwFlags 作为 整数)作为 整数 结束 功能 < dllimport( kernel32.dll,> 私有 功能 FormatMessage( ByVal dwFlags 作为 整数, ByVal lpSource As 字符串, ByVal dwMessageId 正如 整数, ByVal dwLanguageId 正如 整数, ByVal lpBufferas As StringBuilder, ByVal nSize As 整数, ByVal 参数()作为 字符串)作为 整数 结束 功能 私人 函数 GetLastDllErrorMessage( ByVal errNumber 作为 整数)作为 字符串 Dim strLastErrorMessage As 新 StringBuilder( 255 ) FormatMessage( 4096 , Nothing ,errNumber, 0 ,strLastErrorMessage,strLastErrorMessage.Capacity, Nothing ) 返回 strLastErrorMessage.ToString 结束 功能 Sub Main() Dim SteamFrom = < path to ==new =link =be =created => Dim SteamTo = < path to =an =existing =file => Const SYMLINK_FLAG_DIRECTORY As 整数 = 1 Const SYMLINK_FLAG_FILE As 整数 = 0 尝试 如果 CreateSymbolicLink(SteamFrom,SteamTo,SYMLINK_FLAG_FILE)= 1 然后 MsgBox( 完成 ,MsgBoxStyle.Information) Else MsgBox(GetLastDllErrorMessage(Err.LastDllError),MsgBoxStyle.Critical) 结束 如果 Catch ex As 异常 MsgBox(ex.ToString,MsgBoxStyle.Critical) 结束 尝试 结束 Sub 结束 模块 < / 路径 > < / 路径 > 请记住,两个文件都必须在同一个驱动器中,操作系统必须是NT。 如果要链接到文件夹而不是文件,请使用常量SYMLINK_FLAG_DIRECTORY而不是SYMLINK_FLAG_FILE。 i need to create a symbolic link in vb.net, i already know i need to elevate permissions which i already completed but i have no clue where to go from therehere is what i have so far:Imports System.TextImports System.IOImports System.Runtime.InteropServicesPublic Class Main <dllimport("kernel32.dll")> _ Private Shared Function CreateSymbolicLink(ByVal lpSymlinkFileName As String, ByVal lpTargetFileName As String, ByVal dwFlags As Integer) As Boolean End Function Private Sub StartBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartBtn.Click Try CreateSymbolicLink(SteamFrom, SteamTo, 1) Application.DoEvents() Catch ex As Exception MsgBox(ex.ToString) Return End Try MsgBox("Done") End SubEnd Class 解决方案 Here it is a working sample:Imports System.TextImports System.IOImports System.Runtime.InteropServicesModule Module1 <dllimport("kernel32.dll",> _ Private Function CreateSymbolicLink(ByVal lpSymlinkFileName As String, ByVal lpTargetFileName As String, ByVal dwFlags As Integer) As Integer End Function <dllimport("kernel32.dll",> Private Function FormatMessage( ByVal dwFlags As Integer, ByVal lpSource As String, ByVal dwMessageId As Integer, ByVal dwLanguageId As Integer, ByVal lpBufferas As StringBuilder, ByVal nSize As Integer, ByVal Arguments() As String) As Integer End Function Private Function GetLastDllErrorMessage(ByVal errNumber As Integer) As String Dim strLastErrorMessage As New StringBuilder(255) FormatMessage(4096, Nothing, errNumber, 0, strLastErrorMessage, strLastErrorMessage.Capacity, Nothing) Return strLastErrorMessage.ToString End Function Sub Main() Dim SteamFrom = "<path to="" the="" new="" link="" be="" created="">" Dim SteamTo = "<path to="" an="" existing="" file="">" Const SYMLINK_FLAG_DIRECTORY As Integer = 1 Const SYMLINK_FLAG_FILE As Integer = 0 Try If CreateSymbolicLink(SteamFrom, SteamTo, SYMLINK_FLAG_FILE) = 1 Then MsgBox("Done", MsgBoxStyle.Information) Else MsgBox(GetLastDllErrorMessage(Err.LastDllError), MsgBoxStyle.Critical) End If Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Critical) End Try End SubEnd Module</path></path>Remember that both files need to be in the same drive and OS must be NT.If you want to link to a folder instead a file, use the constant SYMLINK_FLAG_DIRECTORY instead of SYMLINK_FLAG_FILE. 这篇关于符号链接visual studio 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 03:14