franzp
franzp

Reputation: 109

Run cmd and install framework

I want to run my app on another PC. But if there's not installed .net 3.5 I can't run it. I found solution to run cmd and detect whether its 3.5 or not. If not it will start install. but if I start my app there just start cmd but without my argument that is if exist \"%WINDIR%\\Microsoft.Net\\Framework\\v3.5\" goto end start /wait .\\Framework\\dotnetfx.exe /q /norestart\. and then I want to close immediately cmd . Any suggestions?

public class CmdRun
{
    public CmdRun()
    {
        string cmdMessage ="if exist \"%WINDIR%\\Microsoft.Net\\Framework\\v3.5\" goto end start /wait .\\Framework\\dotnetfx.exe /q /norestart\" :end";
        System.Diagnostics.Process.Start("CMD.exe",cmdMessage);
    }

    public static void CmdRunFunc()
    {
        System.Diagnostics.Process process = new System.Diagnostics.Process();
        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
        startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        startInfo.FileName = "cmd.exe";
        startInfo.Arguments = "if exist \"%WINDIR%\\Microsoft.Net\\Framework\\v3.5\" goto end start /wait .\\Framework\\dotnetfx.exe /q /norestart\" :end";
        process.StartInfo = startInfo;
        process.Start();
    }
}

Upvotes: 0

Views: 583

Answers (2)

Zein Makki
Zein Makki

Reputation: 30042

Alternative Solution:

Go to Solution Explorer > Right Click your project > Properties > Publish > Prerequisites > Choose .NET 3.5 and then choose to download automatically.

Then Publish your Application ( Build > Publish - Solution Name )

This will force the application to download and install .NET 3.5.

Upvotes: 3

Kenneth
Kenneth

Reputation: 28737

This code is quite useless. If it runs, it means that .NET is already installed, so there' no need to check for it anymore.

You should probably just make a batch file that does the check and either launches the .NET installer or launches the app. Something along these lines:

if exist \"%WINDIR%\\Microsoft.Net\\Framework\\v3.5\" goto end 
start /wait .\\Framework\\dotnetfx.exe /q /norestart\" 
:end
start .\\myapp.exe

Upvotes: 2

Related Questions