Visual Studio call embedded bat file

Posted on 2011-10-11
Last Modified: 2012-05-12
I have a Visual Studio 2010 program that has an embedded .bat, .xml and .exe used to setup a wireless network. If I place the .bat, .exe and .xml in the running directory of the complied program, and use System.Diagnostics.Process.Start("xxx.bat"), the bat correctly calls the exe and xml files and configures the wireless network. Now no matter what I do I can not get it to call the embedded bat file.

Any help would be greatly appreciated
Question by:schmittg25
    LVL 83

    Accepted Solution

    The embedded file is only visible to your program not Windows. You need to write this file to disk somewhere and then execute it.

    Author Comment

    oh.... how could I do that?
    LVL 83

    Expert Comment

    You can read the embeded file as stream and then write that stream to disk

    Use the following function

    Public Function ExtractResourceToDisk(ByVal ResourceName As String, ByVal FileToExtractTo As String) As Boolean
        Dim s As System.IO.Stream = System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(ResourceName)
        Dim ResourceFile As New System.IO.FileStream(FileToExtractTo, IO.FileMode.Create)
        Dim b(s.Length) As Byte
        s.Read(b, 0, s.Length)
        ResourceFile.Write(b, 0, b.Length - 1)
        ResourceFile = Nothing
    End Function

    Open in new window


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now