Link to home
Start Free TrialLog in
Avatar of nstd-sts
nstd-sts

asked on

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

Avatar of zoofan
zoofan
Flag of United States of America image

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

Avatar of nstd-sts
nstd-sts

ASKER

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
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
Avatar of RobSampson
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.
My appologies, I thought you were refering to a vb script, dot net's not on my desktop yet.

zf
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?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rob

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

Regards,

Rob.
cleaning up, my apologies Rob, forgot about this one
No problem at all, thanks for the grade.

Rob.