none
VB Form Application and Resource Files RRS feed

  • Question

  • Hi,

    I have a simple VB form application. On Button 1 click, I am using Shell command to run a script (.bat or Powershell script file) located on my computer.

    Now I want to "add" this file into the application and use it /call it when required... supported?

    I tried to add a file by Project > Add Existing > Browse to the required file.

    This file is now visible under Solution Explorer, but how to use this /execute it?

    Wednesday, March 11, 2020 10:07 AM

Answers

  • Unfortunately that will not do it, to run a several lines script, have to write so many lines.

    Will focusing on OneDrive upload /download instead.

    • Marked as answer by -OSD- Thursday, March 19, 2020 7:36 AM
    Wednesday, March 18, 2020 4:00 PM

All replies

  • You add it as resource, then you can extract it then execute it.

    For example, with a "test.bat" file added as a resource named "test" =>

    Dim sBatFile = My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData + "\test.bat"
    Dim sBatFileContent As String = My.Resources.test
    My.Computer.FileSystem.WriteAllText(sBatFile, sBatFileContent, False, System.Text.Encoding.ASCII)
    Process.Start(sBatFile)

    Wednesday, March 11, 2020 10:34 AM
  • Thanks for answer, but I don't want to extract the file and access it from the local hard disk. Rather, looking for more portable workaround (if possible).
    Wednesday, March 11, 2020 1:02 PM
  • Then use classes like PowerShell Class for example for ps scripts


    • Edited by Castorix31 Wednesday, March 11, 2020 1:11 PM
    Wednesday, March 11, 2020 1:11 PM
  • Hmm, I understand what you recommended, but there will be several file types besides PowerShell, for example .bat and even pictures .png and videos .mp3 etc.

    Seems like what I am asking is not supported?

    Wednesday, March 11, 2020 1:32 PM
  • Hi -OSD-,

    Thanks for your feedback.

    >>I don't want to extract the file and access it from the local hard disk.

    Did you consider using OneDrive to store resources?

    Check the following references:

    Access/Download File OneDrive using vb.Net, is it possible..?

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, March 12, 2020 2:16 AM
    Moderator
  • I have not checked this yet, but using OneDrive, doesn't means if users needs to configure the OneDrive to access the files?
    Friday, March 13, 2020 2:25 PM
  • Hi -OSD-,

    How is the question going? Did you test suggestions in the reference?

    Here's another reference you can refer to:

    Getting a file listing of a OneDrive folder

    Please let me know if you need further assistance.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 17, 2020 6:27 AM
    Moderator
  • OSD,

    I guess you misunderstand the resource files. There are 2 types of that, both named .RESX

    One for developing time from which data is included at run time in the .Exe and one for Forms Language part.

    You can add a Powerpoint script as String inside the internal Resource part of VB.

    For that you go to Project and choose Project settings. 

    Than there opens a pane and in the left tab there is a part for resources and in that a part for strings. 

    You can use it in your program with My.Resources.NameYouGaveIt


    Success
    Cor

    Tuesday, March 17, 2020 12:25 PM
  • Hi -OSD-,

    How is the question going? Did you test suggestions in the reference?

    Here's another reference you can refer to:

    Getting a file listing of a OneDrive folder

    Please let me know if you need further assistance.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Hi,

    I checked the link you refereed and some other (googling) but seems like I wasn't able to find a "working" solution that someone has shared to upload to OneDrive account using VB /CS (without configuring OneDrive on the machine). Correct me if I understood wrong or failed to express what I am looking for. 


    • Edited by -OSD- Tuesday, March 17, 2020 7:42 PM
    Tuesday, March 17, 2020 6:26 PM
  • OSD,

    I guess you misunderstand the resource files. There are 2 types of that, both named .RESX

    One for developing time from which data is included at run time in the .Exe and one for Forms Language part.

    You can add a Powerpoint script as String inside the internal Resource part of VB.

    For that you go to Project and choose Project settings. 

    Than there opens a pane and in the left tab there is a part for resources and in that a part for strings. 

    You can use it in your program with My.Resources.NameYouGaveIt


    Success
    Cor

    Hi Core,

    Could you elaborate what you exactly meant by String and Resource Files?

    See below screenshot, how I can access .PS1 and .PDF files?

    Tuesday, March 17, 2020 7:50 PM

  • See below screenshot, how I can access .PS1 and .PDF files?

    Not PDF, I wrote scripts (text strings). Although you can past as well images in that. (In the value and you have to give the name for the identifier in my.resources.GivenName

    Success
    Cor


    Tuesday, March 17, 2020 8:18 PM
  • Ok, Now I used "String" as copy C:\SampleFile1.txt C:\SampleFile2.txt and named in "Copy".

    How I can run this command with Shell or Process.Start? 

    My.Resources.Copy

    Tuesday, March 17, 2020 9:26 PM
  • Ok, Now I used "String" as copy C:\SampleFile1.txt C:\SampleFile2.txt and named in "Copy".

    How I can run this command with Shell or Process.Start? 

    My.Resources.Copy

    Something like

    process.start(my.resources.copy) 



    Success
    Cor


    Tuesday, March 17, 2020 9:54 PM
  • System.ComponentModel.Win32Exception: 'The system cannot find the file specified'


    Unfortunately it didn't worked. I am getting file not found but I have made sure that file is present and accessible. Further, when the same command is used in command prompt is perform the task intended, so no issues with file or command.

    Command is: copy C:\SampleFile1.txt C:\SampleFile2.txt

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Process.Start(My.Resources.Command1)
            Process.Start(My.Resources.Command2)
    
        End Sub
    End Class

    Tuesday, March 17, 2020 11:08 PM
  • For example =>

            Dim pCmd As New ProcessStartInfo("cmd")
            pCmd.WindowStyle = ProcessWindowStyle.Hidden
            pCmd.Arguments = "/c " + My.Resources.Command11
            Process.Start(pCmd)

    Tuesday, March 17, 2020 11:35 PM
  • Unfortunately that will not do it, to run a several lines script, have to write so many lines.

    Will focusing on OneDrive upload /download instead.

    • Marked as answer by -OSD- Thursday, March 19, 2020 7:36 AM
    Wednesday, March 18, 2020 4:00 PM
  • Unfortunately that will not do it, to run a several lines script, have to write so many lines.

    Will focusing on OneDrive upload /download instead.

    I don't see why you don't want to extract to temporary files to execute them : it is very usual

    Most of applications use temporary files (Office and others)

    Wednesday, March 18, 2020 4:12 PM