简体   繁体   中英

Send Parameters to an exe file (Executable) c# or create executable file c# in memory

I am making a web and desktop application in C# for my elementary students, so that they can log onto the web and download the program for their classes. Both the web and the application will be found in Azure Storage.

The application I created is very small since it only takes care of downloading and executing the necessary dll where the forms with the classes and exams will be.

The problem I have is that I want the login data (username and / or password) to be sent as parameters in the application so that they don't have to log in again in the desktop application.

I tried to make the application read cookies in some way, but discard this idea because it depends a lot on the browser.

The other and more understandable idea is to create a web service that generates the executable file (exe) in memory (it has to be in memory because I don't have write and read access to disk, I'm using Azure Storage and Azure Service) and it Download using filestream or something similar.

I found this example but this necessarily needs a directory to generate the exe file, is it possible to generate the exe file in memory?

Or if it is possible to pass parameters to a compiled exe file.

Public Sub generateFile ()
    Dim codeProvider As New VBCodeProvider ()
    Dim icc As ICodeCompiler = codeProvider.CreateCompiler
    Dim Output As String = "C: \ Program Files \ MyApp.exe"


    Dim parameters As New CompilerParameters ()
    Dim results As CompilerResults

    'Make sure we generate an EXE, not a DLL
    parameters.GenerateExecutable = True
    parameters.OutputAssembly = Output
    parameters.CompilerOptions = ("/ target: winexe" & "" & "/ win32icon:" & "" "") & "C: \ Program Files \ MyIcons \ Icon.ico" & "" ""

    results = icc.CompileAssemblyFromSource (parameters, txtCode.Text)

    If results.Errors.Count> 0 Then
        'There were compiler errors
        Dim CompErr As CompilerError
        For Each CompErr In results.Errors
            MessageBox.Show (
                "Line number" & CompErr.Line &
                ", Error Number:" & CompErr.ErrorNumber &
                ", '" & CompErr.ErrorText & ";" &
                Environment.NewLine & Environment.NewLine)
        Next
    Else

        'Successfull Compile
        MessageBox.Show ("Your file is successfully generated!", "Success")
    End if
End Sub

The desktop application is small, it is only responsible for downloading and executing the last dll contained in a directory in azure storage, the classes and forms will be in these dll.

Thanks so much for reading. I apologize for my English, I'm from Argentina

The problem I have is that I want the login data (username and / or password) to be sent as parameters in the application so that they don't have to log in again in the desktop application.

This is not a simple thing to do. Here are the steps I would recommend along with the User Experience.

  1. User Logins To Web Site
  2. User Downloads Installer
  3. User Starts Installer

    a. During installation, application registers a custom URI Scheme Registering an Application to a URI Scheme

Now the following is the same regardless if it's after installation or the user is executing the application.

  1. User Starts Application (or Installer does)
  2. Application launches a browser to Login
  3. User Logs In and Browser redirects to your custom URI Scheme with credentials (NOT username/password) so your application can now authenticate when it downloads whatever.

This is very common. Applications like GotoMeeting, Slack, Discord and a variety of others all do the same thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM