I have a C# program that needs to spawn a .BAT command file during its execution. No problem. I can just use (for example)...
System.Diagnostics.Process.Start("PublishFeed.bat", "file.xml");
...in order to run the cmd with a parameter. In the debugger, this works fine. However, when I run the executable in production, Windows pops up a dialog box that says "Do you want to open this file? Name: PublishFeed.bat Type: Unknown File Type.
If I click OK, it runs fine.
Why is this dialog appearing? Seems especially odd for it to claim Unknown File Type, when clicking OK seems to run the BAT file with no problem.
thanks all!
P.S. Yes, I can probably remove the need for the BAT file, but I would still like to understand the issue.
I think the most reliable way to do this is to just speficy to open that batch with cmd:
System.Diagnostics.Process.Start("cmd", "/c PublishFeed.bat file.xml");
Related
I stumbled upon a problem with which I need some help!
When a process is executed from within a Windows application that runs directly, the call to Process.Start opens up the webpage to the default browser.
But when the same Windows application is run through a Setup Project, Process.Start does not open the URL.
You can download the VS solution from here:
https://pxstorage.blob.core.windows.net/pub/TestSetup.zip
Unfortunately, due to the nature of the problem, it was meaningless to append code snippets.
To replicate the issue:
Build the solution
Expected behavior: Run the SetupHelper project and click the Button, and you should see your default browser opening the URL.
Unexpected behavior: Right-click the TestSetup project, click Install and follow the steps. After a popup message, the SetupHelper window will show up, but by clicking the Button, the URL does not open.
Any help would be much appreciated!
Remarks:
I run it as Administrator.
I already use UseShellExecute = true
The problem is that when the Windows application is run from a Setup Project, the Process.Start method does not open the URL.
One possible solution would be to use the Process.StartInfo.UseShellExecute property and set it to true. This will cause the process to be started using the ShellExecute method instead of the CreateProcess method.
Process.StartInfo.UseShellExecute = true;
Process.Start("http://www.google.com");
Due to some circumstances, I was ask to develop a page that uses Process in .Net C# to call the function through command prompt.
The code works perfectly Fine on visual studio, but when deployed on an IIS server. the Process doesn't seems to work, I've debugged and find out the process itself works. but the open Babel command doesn't work, i did double check and the identity i supply with should be alright, i did even supply it with admin privilege but still doesn't work. it doesn't even pop or error, it just simply ignored it and go through the commands.
I put the command into a .bat file, with some extra command to test if the .bat works. everything is fine until the command with open babel, then process just doesn't seem react with the command.
obabel %1 -O %2 --gen2d
this is the command i supply it with, %1 is the input file while %2 is the output file name. A very simple conversion. Note: everything is fine, just only the open babel command got ignored in the entire file. and I've tried to supply it with admin privilege, still doesn't work. the open babel can be used if directly used with command prompt on the server, or through visual studio. but it doesn't work if i deployed it through IIS server.
Found the solution, after all kinds of modification.
it seems like i have to provide a physical path to Open Babel.exe in the .bat file, and same as the parameter file i supply it with.
It's risky solution, but at least it solves the problem.
I am trying to run/debug a project and im getting this error. I have never seen this before!
Severity Code Description Project File Line Suppression State
Error Unable to copy file "obj\Debug\Side_Project.exe" to
"bin\Debug\Side_Project.exe". The process cannot access the file
'bin\Debug\Side_Project.exe' because it is being used by another
process. Side_Project
As the error states it cannot copy the file because its in use. its as simple as that.
Make sure the file isn't actually running, Check Task Manager.
Make sure it isnt being locked by your virus checker.
Also try restarting visual studio
If worst comes to worst restart your pc
Job done, happy debugging
This means the program is still opened. Check if it is running in the background, open task manager or force kill it with Command Prompt
command:
C:>Taskkill /IM Side_Project.exe /F
or by PID
C:>Taskkill /PID (PID HERE) /F
View your PID by opening a list of running tasks with
C:>tasklist
See if that works.
I'm writing a small program to fix compatibility issues with a 16-bit program. This fix is to close explorer.exe, as explorer overrides some of the palettes in the program. Afterwards, we reopen explorer.
When using a .bat file, it works:
#ECHO OFF
taskkill /f /IM explorer.exe
EmStraditionX.exe
start /B explorer.exe
This method isn't ideal, as it requires extra files to download. For the sakes of simplicity, assume that it is impossible for me to distribute more than the C# compatibility program.
My first thought was to just Process.Start("explorer.exe"), but this did not work, and instead just opened the 'Libraries' folder in an explorer window, without making the taskbar visible again.
I then tried to use the same command as the batch file, except like this: Process.Start("cmd.exe", "/C start /B explorer.exe"), which again did not work.
Does anyone know how I can reopen the taskbar from C#?
Thanks,
Ruirize.
Use:
Process.Start(Environment.SystemDirectory + "\\..\\explorer.exe");
Putting the full path will make it work
Martyn
Do you use also "Run As Administrator" function in compatibility options?
If you do - you will start explorer from another session and you cant see window,that is running in other (administrator) session.
Is it possible to find out whether your current .Net app has been launched using a shortcut or a Clickonce application reference (*.appref-ms) file? If so, how?
Some background: I am running into an issue using Microsoft Clickonce in which I cannot pass command line arguments to the application. It seems that this is the way the technology works by design. I was exploring different ways of passing this parameter; one of them was to have a set of different Clickonce Start Menu shortcuts.
Try testing out the ApplicationDeployment.IsNetworkDeployed property. I know this will be true if it is a ClickOnce app but I'm not sure if it will be false in your situation.
I'm not sure what an "application reference file" is; do you mean like double-clicking the EXE file in Explorer or running the file from a command line?
There isn't any a priori way to detect how your program was started. The usual workaround is to configure the shortcut file to pass a parameter on the command line. Then, check for the existence of that parameter at run time. If you find it there, assume the program was started from a shortcut. The key to this approach is the fact that you can't include a parameter when double-clicking the EXE file in Explorer, so if you find a command-line parameter, you know the program wasn't started that way.