VB script to extract contents to a created network folder

I am creating a visual basic script and need some help.

I have a form with a open file button.  I can get the button to Open and browse to the file you want to open.  The file is going to be symantec antivirus updates.  What I want to happen is once the file is selected, I want it to extract the contents to a network share with a folder created with the name of the file.
I know the command for a batch script to extract the contents is
symantecfilename.exe /extract \\servername\share

Thanks
We are running this on Windows XP Boxes

LVL 1
nstd-stsAsked:
Who is Participating?
 
RobSampsonCommented:
Hi, your Button_Click event that handles Open.Click, you could try code like this, but I'm not really familiar with .NET, so hopefully it works!
:
'===============
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Open.Click
      ' Reset the file names for the Open File dialog box and for the Media Player.
      OpenFileDialog1.FileName = ""
      ' Display the Open File dialog box.
      intResult = OpenFileDialog1.ShowDialog()
                      
      If intResult = 0 Then
            Exit Sub
      End If
      
      Shell("cmd /c start /w /y """ & OpenFileDialog1.FileName & """", vbHide)
End Sub
'==================

Regards,

Rob.
0
 
zoofanCommented:
Since you already have the file name your script needs to drop the extension and make the folder then shell the extraction. as follows

    Set objFso = CreateObject("Scripting.FileSystemObject")
    Set objWshshell = WScript.CreateObject("WScript.Shell")
    NewFolder = Left(YourNameFromButtun,(Len(YournameFromButton) - 4))
    strDestdir = InputBox("Enter the shared folder name.") & "\" & NewFolder & "\" &  YournameFromButton
    If Not objFSO.FolderExists(strDestdir & "\" & NewFolder) Then
                  objFSO.CreateFolder(strDestdir & "\" & NewFolder)
      End If
      strCommand = "Symantecfilename.exe /extract" &  strDestdir
      return = objWshShell.Run(strCommand, 0, True)
      If return <> 0 Then
      MsgBox "There was an error extracting the update"
      Else
      MsgBox "Extraction complete"
      End If

if you have problems let me know.

Posting what you already have could help smooth incorperating this into it as well.

zf

0
 
nstd-stsAuthor Commented:
Here is the code, I havent used vb in years and I am just coping from Visual Studio.   Also, the file name is going to change every time I import a file.

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Open = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.FileName = "OpenFileDialog1"
        Me.OpenFileDialog1.SupportMultiDottedExtensions = True
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(12, 21)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(156, 20)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = "Symantec 64 Bit Auto Update"
        '
        'Open
        '
        Me.Open.Location = New System.Drawing.Point(12, 59)
        Me.Open.Name = "Open"
        Me.Open.Size = New System.Drawing.Size(75, 23)
        Me.Open.TabIndex = 1
        Me.Open.Text = "Open"
        Me.Open.UseVisualStyleBackColor = True
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(12, 88)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75, 23)
        Me.Button1.TabIndex = 2
        Me.Button1.Text = "Start"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(582, 320)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Open)
        Me.Controls.Add(Me.TextBox1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Open As System.Windows.Forms.Button
    Friend WithEvents Button1 As System.Windows.Forms.Button

End Class
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
nstd-stsAuthor Commented:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub FolderBrowserDialog1_HelpRequest(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Open.Click
        ' Reset the file names for the Open File dialog box and for the Media Player.
        OpenFileDialog1.FileName = ""
        ' Display the Open File dialog box.
        OpenFileDialog1.ShowDialog()
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Shell("cmd /c start /w /y C:\test.bat", vbHide)
    End Sub
End Class
0
 
RobSampsonCommented:
So you are using Shell to run the test.bat file......you can use the same method to run the extraction:
strDestDir = "C:\ExtractedFiles"
Shell("Symantecfilename.exe /extract " &  strDestdir, vbHide)

Will that do what you need?

Rob.
0
 
zoofanCommented:
My appologies, I thought you were refering to a vb script, dot net's not on my desktop yet.

zf
0
 
nstd-stsAuthor Commented:
If I do use the shell comands.  When I Use the Open file button, how do I pass the name of the file that I opened to the shell command or the batch file?
0
 
nstd-stsAuthor Commented:
Rob

Thanks, I added my info into that and everything works.  
Thanks for all the help everyone
0
 
RobSampsonCommented:
That's great.  If that helped you solve it, please don't forget to accept an answer and close the question.

Regards,

Rob.
0
 
nstd-stsAuthor Commented:
cleaning up, my apologies Rob, forgot about this one
0
 
RobSampsonCommented:
No problem at all, thanks for the grade.

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.