I'm trying to run a Python script from a WPF application, but I can't figure out how to find the file on the client machine. I know ClickOnce installs the files to AppData\Local\, but that seems like a poor way to search for the script.
In my code, I'm starting a shell as follows:
var p = new Process();
p.StartInfo.FileName = #"C:\Python27\python.exe";
p.StartInfo.Arguments = String.Format("{0} {1}", ScriptName, args);
//p.StartInfo.WorkingDirectory = #"<path\to\project>";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
On my development machine, the WorkingDirectory parameter makes it all work if I set it to the project path because that's where the Python script resides.
I included the script in the ClickOnce file manifest and I've verified that it ends up in each version of the application deployment. I've also verified that the file ends up on the client machine in the obfuscated hierarchy, so everything is in place except I can't get my WPF application to actually run it. I could always copy the file to a known place on the machine, but that completely defeats the point of ClickOnce.
Any ideas would be greatly appreciated.
I got this to work, but I'm not 100% sure how. Regardless, here's what I did in case it helps someone else.
Don't set the process working directory (already commented out in my question)
Set the Python script properties as follows:
Build Action = Content
Copy to Output Directory = Copy Always
In the Publish tab under Project Properties, set the script to Include in Application Files.
With the above changes, my application deploys correctly on client machines.
Related
I have a question about passing the branch name to my code as a string.
So we are using a git repository and the branch number also refers to the staging environment where the build is placed. Meaning, if my branch is 001, my url is 001.test.myapplication.com.
I am writing automated tests which are executed on the staging environment of the branch. My question is, is it possible to pass the branch number to my code so I can make it part of the URL I want to test on?
I am using visual studio 2017, selenium and specflow.
I actually found a great solution which perfectly works. Sharing so in the future, others can use it too if they need to.
ProcessStartInfo startInfo = new ProcessStartInfo("git.exe");
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = "dir Here";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.Arguments = "rev-parse --abbrev-ref HEAD";
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
string branchname = process.StandardOutput.ReadLine();
The usual way to do this is to generate a C# file containing this information as part of your build step.
There are already several good answers here:
Embed git commit hash in a .Net dll
The git command in the earlier answer didn't work for me anymore in 2022. I use the following pre-build event in Visual Studio project properties:
git.exe branch --show-current > "$(ProjectDir)\Properties\BuildDate.txt"
echo %date% %time% >> "$(ProjectDir)\Properties\BuildDate.txt"
Define BuildDate.txt as an imported resource in the project's resource file, then use it like a regular resource string at runtime.
I have a .exe file which checks the system architecture and based on the system architecture it calls the corresponding msi file.
I am trying to run this exe file from C# using the code below
Process process = new Process();
process.StartInfo.FileName = "my.exe";
process.StartInfo.Arguments = "/quiet";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.WorkingDirectory = "path//to//exe//directory";
Console.WriteLine(process.StartInfo.WorkingDirectory);
process.Start();
process.WaitForExit();
The exe is getting invoked. i can see the application logs and there are no errors in the logs.
But the msi is not getting started or installed.
When I try to run the same exe file manually the msi is installed.
Note: There are other dependency files for this my.exe which are placed in the same directory.
Why am i not able to install the msi from C# program while i am able to do this manually.
I am running the VisualStudios in administrator mode.
You need to execute .exe (and msi) as an administrator.
To ensure that, use:
process.StartInfo.Verb = "runas"
Also, try it removing quiet arguments to see any possible errors.
Is "my.exe" installing your MSI if you call it, isn't it?
I got this resolved after i added Thread.Sleep(). before "process.WaitForExit()"
I am working on packaging up some installers for internal use. I have the uninstall working fine with a passive switch.
As for installation, the MSI's that do not have an EULA work perfectly with the passive switch showing progress.
The EXE's that contain an EULA are the problem.
I am trying to find a way to accept the EULA without user input - note I do not have access to changing the public properties of the EXE's to set the ACCEPTEULA=1
the base I am working with right now is...
start = new ProcessStartInfo();
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
start.Arguments = s.args; //curent argument /qn
start.FileName = tempDir + "/" + s.executable;
start.CreateNoWindow = true;
While this code works perfectly fine with the msi's it does not work with the exe's as they all contain EULAs.
When using an exe you need to preface /qn with /v making it:
setup.exe /v/qn
I'm having an issue with running slui.exe from a method in c#. I'm using the code:
ProcessStartInfo startInfo = new ProcessStartInfo(#"C:\Windows\System32\slui.exe");
Process p = new Process();
p.StartInfo = startInfo;
p.Start();
p.WaitForExit();
but I keep getting a Win32Exception: 'The system cannot find the file specified'.
If I change the ProcessStartInfo to: (#"C:\Windows\System32\cmd.exe") it will launch just fine.
Is there something with running slui.exe in this context that is breaking?
I'm certain that the file is in the directory specified, so I'm stumped as to what may be going wrong here.
Any ideas how to call slui.exe from a c# method?
Slui.exe is only available as a 64-bit program on Windows x64. Your hard-coded path c:\windows\system32 will get re-directed to c:\windows\syswow64 when you run as a 32-bit process. And thus won't find the file.
Project + Properties, Compile tab, change the Platform target setting to "AnyCPU". Repeat for the Release configuration. And use Environment.GetFolderPath() to ensure it still works when Windows isn't installed to c:\windows.
How to start XXX.bat file in IIS? I want to run this file..while i am executing in my development PC its perfectly running. But While I deployed in IIS its working and not executing .bat file
So please guide me how to do...My Code as follows
\\
string exefile = ConfigurationManager.AppSettings["exefile"]; //exefile="D:\\XX\\xxx.bat"
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(exefile);
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
\\
I would check security.
The user that "hosts" the IIS proccess does likely not have the rights to run exeute files outside the IIS folder.
Also posting a actual error message would be helpfull. On a side note if its Exepction is of type UnauthorizedAccessException then its very likely what i describe above.
I had this problem and for me it was the location of the bat file.
It had placed the bat file in it's own folder under the solution in Visual Studio but this meant IIS could not access it.
When I moved the bat file to the wwwroot folder everything worked as expected.