?
Solved

VB script to extract contents to a created network folder

Posted on 2007-08-01
11
Medium Priority
?
327 Views
Last Modified: 2013-11-25
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

0
Comment
Question by:nstd-sts
  • 5
  • 4
  • 2
11 Comments
 
LVL 12

Expert Comment

by:zoofan
ID: 19611179
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
 
LVL 1

Author Comment

by:nstd-sts
ID: 19611898
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
 
LVL 1

Author Comment

by:nstd-sts
ID: 19611918
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Expert Comment

by:RobSampson
ID: 19614667
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
 
LVL 12

Expert Comment

by:zoofan
ID: 19615344
My appologies, I thought you were refering to a vb script, dot net's not on my desktop yet.

zf
0
 
LVL 1

Author Comment

by:nstd-sts
ID: 19616018
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
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 19622329
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
 
LVL 1

Author Comment

by:nstd-sts
ID: 19627122
Rob

Thanks, I added my info into that and everything works.  
Thanks for all the help everyone
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19636108
That's great.  If that helped you solve it, please don't forget to accept an answer and close the question.

Regards,

Rob.
0
 
LVL 1

Author Comment

by:nstd-sts
ID: 19982116
cleaning up, my apologies Rob, forgot about this one
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 19988272
No problem at all, thanks for the grade.

Rob.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question