USB密钥安装程序 [英] Usb Key Installer

查看:72
本文介绍了USB密钥安装程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我从一个完全菜鸟入手.

Let me start up with im a complete noob.

我正在尝试在vb中创建一个软件,该软件基本上删除了Usb密钥上的所有内容

Im trying to create a software in vb that basically deleted everything on a Usb key

然后使用相同的Usb密钥从我的网站下载文件,将其解压缩并删除zip文件.  

then download a file from my website on that same Usb key extracts it and deletes the zip file.  

我可以使用USB密钥X:\

i got everything to actually work but using a specific path for my Usb key X:\

我刚刚意识到那条路径会根据您插入钥匙的PC的不同而改变.

i just realized then that that path get changed depending on the Pc you are plugging the key.

经过几天尝试找出不使用Usb密钥路径的方法,我似乎找不到任何东西

after a couple days of trying to figured out how to do this not using the Usb key path i cant seem to find to find anything

这是我的代码的副本,对您的帮助将不胜感激

here is a copy of my code any help would be greatly appreciated

导入System.Net
导入System.IO
导入System.IO.Compression


公共课程表格1
   公开WithEvents下载As WebClient
   私有子Button1_Click(作为对象发送,作为EventArgs发送)处理Button1.Click
      下载=新的WebClient
       download.DownloadFileAsync(New Uri("http://thekeytoit.com/update/update.zip"),"X:\ update.zip")
       MsgBox(下载完成",MsgBoxStyle.Information)
       MsgBox(下载失败",
   结束子


   受保护的子Button2_Click_1(作为对象发送者,作为EventArgs发送者)处理Button2.Click
      字符串为Dim的路径="X:\"
       DeleteDirectory(路径)
   结束子

   私人子DeleteDirectory(路径为字符串)
      如果Directory.Exists(path)然后
           '从目录中删除所有文件
          对于每个文件路径,作为Directory.GetFiles(path)中的字符串
                             File.Delete(文件路径)
          下一个
           '删除所有子目录
          对于每个目录,如Directory.GetDirectories(path)中的字符串
                             DeleteDirectory(dir)
          下一个
          试试
                             '删除目录
                             Directory.Delete(路径)
          异常捕获

          结束尝试

      如果结束

   结束子

   私有子Button2_Click(作为对象发送,作为EventArgs发送)

   结束子
    Public Sub ChooseFolder()

   结束子

   私有子Folder FolderBrowserDialog1_HelpRequest(作为对象发送,作为EventArgs发送)处理FolderBrowserDialog1.HelpRequest

   结束子

Imports System.Net
Imports System.IO
Imports System.IO.Compression


Public Class Form1
    Public WithEvents download As WebClient
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        download = New WebClient
        download.DownloadFileAsync(New Uri("http://thekeytoit.com/update/update.zip"), "X:\update.zip")
        MsgBox("Download Complete", MsgBoxStyle.Information)
        MsgBox("Download Failed",
    End Sub


    Protected Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        Dim path As String = "X:\"
        DeleteDirectory(path)
    End Sub

    Private Sub DeleteDirectory(path As String)
        If Directory.Exists(path) Then
            'Delete all files from the Directory
            For Each filepath As String In Directory.GetFiles(path)
                File.Delete(filepath)
            Next
            'Delete all child Directories
            For Each dir As String In Directory.GetDirectories(path)
                DeleteDirectory(dir)
            Next
            Try
                'Delete a Directory
                Directory.Delete(path)
            Catch ex As Exception

            End Try

        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs)

    End Sub
    Public Sub ChooseFolder()

    End Sub

    Private Sub FolderBrowserDialog1_HelpRequest(sender As Object, e As EventArgs) Handles FolderBrowserDialog1.HelpRequest

    End Sub

推荐答案

让我从一个完全菜鸟入手.

Let me start up with im a complete noob.

我正在尝试在vb中创建一个软件,该软件基本上删除了Usb密钥上的所有内容

Im trying to create a software in vb that basically deleted everything on a Usb key

然后使用相同的Usb密钥从我的网站下载文件,将其解压缩并删除zip文件.  

then download a file from my website on that same Usb key extracts it and deletes the zip file.  

我可以使用USB密钥X:\

i got everything to actually work but using a specific path for my Usb key X:\

我才意识到那条路径会根据您插入钥匙的PC的不同而改变.

i just realized then that that path get changed depending on the Pc you are plugging the key.

经过几天尝试找出不使用Usb密钥路径的方法,我似乎找不到任何东西

after a couple days of trying to figured out how to do this not using the Usb key path i cant seem to find to find anything

这是我的代码的副本,对您的帮助将不胜感激

here is a copy of my code any help would be greatly appreciated

导入System.Net
导入System.IO
导入System.IO.Compression


公共课程表格1
   公开WithEvents下载As WebClient
   私有子Button1_Click(作为对象发送,作为EventArgs发送)处理Button1.Click
      下载=新的WebClient
       download.DownloadFileAsync(New Uri("http://thekeytoit.com/update/update.zip"),"X:\ update.zip")
       MsgBox(下载完成",MsgBoxStyle.Information)
       MsgBox(下载失败",
   结束子


   受保护的子Button2_Click_1(作为对象发送者,作为EventArgs发送者)处理Button2.Click
      字符串为Dim的路径="X:\"
       DeleteDirectory(路径)
   结束子

   私人子DeleteDirectory(路径为字符串)
      如果Directory.Exists(path)然后
           '从目录中删除所有文件
          对于每个文件路径,作为Directory.GetFiles(path)中的字符串
                             File.Delete(文件路径)
          下一个
           '删除所有子目录
          对于每个目录,如Directory.GetDirectories(path)中的字符串
                             DeleteDirectory(dir)
          下一个
          试试
                             '删除目录
                             Directory.Delete(路径)
          异常捕获

          结束尝试

      如果结束

   结束子

   私有子Button2_Click(作为对象发送,作为EventArgs发送)

   结束子
    Public Sub ChooseFolder()

   结束子

   私有子Folder FolderBrowserDialog1_HelpRequest(作为对象发送,作为EventArgs发送)处理FolderBrowserDialog1.HelpRequest

   结束子

Imports System.Net
Imports System.IO
Imports System.IO.Compression


Public Class Form1
    Public WithEvents download As WebClient
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        download = New WebClient
        download.DownloadFileAsync(New Uri("http://thekeytoit.com/update/update.zip"), "X:\update.zip")
        MsgBox("Download Complete", MsgBoxStyle.Information)
        MsgBox("Download Failed",
    End Sub


    Protected Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        Dim path As String = "X:\"
        DeleteDirectory(path)
    End Sub

    Private Sub DeleteDirectory(path As String)
        If Directory.Exists(path) Then
            'Delete all files from the Directory
            For Each filepath As String In Directory.GetFiles(path)
                File.Delete(filepath)
            Next
            'Delete all child Directories
            For Each dir As String In Directory.GetDirectories(path)
                DeleteDirectory(dir)
            Next
            Try
                'Delete a Directory
                Directory.Delete(path)
            Catch ex As Exception

            End Try

        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs)

    End Sub
    Public Sub ChooseFolder()

    End Sub

    Private Sub FolderBrowserDialog1_HelpRequest(sender As Object, e As EventArgs) Handles FolderBrowserDialog1.HelpRequest

    End Sub

忘记代码的结尾

私有子Button3_Click(作为对象发送,作为EventArgs发送)处理Button3.Click
      试试
           ZipFile.ExtractToDirectory("X:\ update.zip","X:\")
           MsgBox(更新完成",MsgBoxStyle.Information)
           My.Computer.FileSystem.DeleteFile("X:\ update.zip")

      异常捕获

      结束尝试


   结束子



   私有子TextBox1_TextChanged(作为对象发送,作为EventArgs发送)

   结束

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Try
            ZipFile.ExtractToDirectory("X:\update.zip", "X:\")
            MsgBox("Update Completed", MsgBoxStyle.Information)
            My.Computer.FileSystem.DeleteFile("X:  \update.zip")

        Catch ex As Exception

        End Try


    End Sub



    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)

    End Sub


这篇关于USB密钥安装程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆