can i install the .exe file without user interaction - c#

Can I install the .exe file without user interaction (means without click on the next or install button)
I have write the code to call .exe file but, it doesn't install silently in background.
Process p = new Process();
p.StartInfo.FileName = #"C:\Downloads\teamViewer.exe";
p.StartInfo.Arguments = "/S";
p.Start();
p.StartInfo.CreateNoWindow = true;
p.WaitForExit();
Why exe not run in background, with this code?

You can do a silent install with the EXE you download from the website.
You have to use the one that it extracts into your
%temp%\TeamViewer\VersionX\TeamViewer_.exe
As of version 7 %temp%\TeamViewer\Version7\TeamViewer_.exe. This one supports the /S argument, but there is another problem : UAC confirmation dialog and as far as I know you can't bypass this with code (unless your app is already running with admin privileges. You can use an application manifest for that).

Related

Error (Possible Permissions Issue) When using Process.Start in C#

I'm trying to start an application called snort from a C# application, using System.Diagnostics.Process, and I need to capture its output. To achieve this, I've used the code below.
When I try to run this, I get an error which is related to loading the configuration file. I get this same error if I try to manually run the exe from a CMD without administrator privileges, so I think this is a permissions issue for the forked process, but I'm not entirely sure of that. However, I have tried the following, to no avail:
I have added to the C# application manifest (the C# application is definitely running as administrator).
I have tried using a username and password with Process.StartInfo
However, the error still remains. Also, for clarity: The process is started, I am receiving output in My OutputHandler method, etc -- the issue is with the forked exe, it is having a problem reading the specified configuration file.
The sample code is as follows:
var process = new Process();
process.StartInfo.FileName = #"C:\Snort\bin\snort.exe";
process.StartInfo.Arguments = #"-A console -i2 -c C:\Snort\etc\snort.conf -l C:\Snort\log\ -K ascii";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
This does start the required process, but as I mention that process (snort) then outputs an error when trying to read the configuration file (the same error I get if I try to manually run the same process from a CMD without admin rights--hence why I think the issue might be permissions-based).
Can anyone suggest anything else I might try to get around this. I do need to capture output, so (if I understand it correctly) the 'runas' verb doesn't help.
Thanks for your time.
I explored a few option and tried to continue on the path of permission and changed the application manifest file permission and replaced the standard permission file with:
requestedExecutionLevel level="requireAdministrator" uiAccess="false"
This did not change anything.
I am using windows 8.1 and when I visited the properties of the snort.exe file I changed the compatibility and run the application compatible with win 7 and ticked the box to run as administrator, it is now working fine.
snort.exe properties
Many Thanks to everybody

Calling a .exe as Admin from within my code in Program Files folder

I have a C# application which calls an .exe file. This executable file must be started with administrator rights. But I don't want to run my application with admin rights.
I use the following code for that:
ProcessStartInfo procStartInfo = new ProcessStartInfo("foo.exe");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
procStartInfo.Verb = "runas";
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
proc.WaitForExit();
If I put my application in no specific folder, everything works fine, when calling the executable, the user is asked to run it as admin. But when I put my application in the "Program Files" folder and start it, when calling the execution file, there is NO question to run it as admin. And because of that, execution fails.
I'm using Windows 7 and the executable file is not lying in the "Program Files" folder. Is there a way to always run this file as admin but not my application?
Just add a manifest to the target application stating that it should be run as admin. The responsibility for that generally lies with the application being started, not the application which starts it.
An exception would be cases like Notepad being called to open a shared configuration file, but you haven't provided enough details to determine that.
Just Add a new Application manifest file in your project and
change this <requestedExecutionLevel> as
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Cannot launch PSEXEC

I have this very simple program
Process process = new Process();
process.StartInfo.FileName = #"psexec";
process.Start();
But when I run it the debug says "The system cannot find the file specified"
If I have the same program and change "psexec" by "Notepad", it works and opens notepad.
Process process = new Process();
process.StartInfo.FileName = #"notepad";
process.Start();
This is weird because I have my psexec in the System32 and if run "psexec" using Windows-Run, it works.
Thank you in advance for any help.
Update: I specify the full path #="C:\Windows\System32\PSexec.exe" and It doesnt work. But If I move Psexec to, as example #"D:\psexec.exe" it works!!
Why coud this happen?
Running programs from c:\windows\system32 is troublesome on a 64-bit operating system. The workaround is Project + Properties, Build tab, change Platform target to AnyCPU. Or to copy the file also to c:\windows\syswow64.
Or to just not put it in the Windows directory, it is not an operating system specific file that belongs there. The appropriate place is the same directory as your EXE.
You can learn more about the File System Redirector in this MSDN article.
try specify the full path of 'psexec'
there is any property 'WorkingDirectory', which might help.

How to install on remote PC with psexec with my c# code

I'm trying to install some software remotely from our domain server to all the PC's in the office.
I know the code to install it silently on the local computer and have tried various things that I've found while searching to install it remotely when pressing a button in my app but I can't get it to work. This is my local code and it works:
Process SR = new Process();
SR.StartInfo.FileName = "X:\\Teklastructures\\Tekla Structures Releases\\18.0\\TeklaStructures180SR3x64Software.exe";
SR.StartInfo.Arguments = "/s /v\"/qn INSTALLDIR=C:\\TeklaStructures /lvoicewarmupx C:\\teklaSRinstall.log";
SR.Start();
SR.WaitForExit();
SR.Close();
I've been trying to use psexec because I've read that it should do what I want. I believe one problem is that the software is on mapped drive X. So how can I install it remotely? Maybe look at this instead?
"\\server\\d\\Teklastructures\\Tekla Structures Releases\\18.0\\TeklaStructures180SR3x64Software.exe"
This is what I've tried with putting PsExec.exe on the C drive of the server:
Process p = new Process();
p.StartInfo.FileName = "C:\\PsExec.exe";
string args = "/s /v\"/qn INSTALLDIR=C:\\TeklaStructures /lvoicewarmupx C:\\teklaSRinstall.log";
p.StartInfo.Arguments = #"\\COMP14 -accepteula -i -s X:\Teklastructures\Tekla Structures Releases\18.0\TeklaStructures180SR3x64Software.exe " + args;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
p.Close();
Any help to install software remotely would be appreciated. Perhaps there's a better way?
You must copy the installer exe to the computer where you want to install it, and then use psexec to run it there. You cannot run the installer exe from a different machine that where you want it to be installed to.

c# application doesn't perform batch file command correctly

public void runBatchfile(String batchfilename)
{
try
{
ProcessStartInfo processInfo = new ProcessStartInfo(batchfilename);
processInfo.UseShellExecute = false;
Process batchProcess = new Process();
batchProcess.StartInfo = processInfo;
batchProcess.StartInfo.CreateNoWindow = true;
batchProcess.Start();
batchProcess.WaitForExit();
}
catch (Exception r) { }
}
runBatchfile(#"c:\lol.bat");
lol.bat contains these 2 lines
dir c:\ /s /b > c:\filelist.txt
exit
and when I run my code all it does is creating a filelist.txt file, but doesn't actually perform the rest of the command, which does work if I manually insert it into CMD.
Btw I've tried making the extension .cmd and I also tried without the exit command, without any other results.
please help me :)
On my Windows 7 64-bit machine with Visual Studio 2010, running this code straight from the IDE doesn't do anything whatsoever.
On a hunch that it might have something to do with permission to write to the root directory of drive C:, I tried running the .exe directly from an Explorer window with admin rights (right-click, Run as Administrator) and that worked.
I'd say it's a permission problem.
Maybe you could redirect the output to a file located elsewhere?
update:
I changed the batch file so that the dir command gets redirected to my desktop and it runs just fine.
I've had issues with this as well when calling from C#. The workaround that I usually use is to physically allow it to show the window when running the command. Not sure why this makes a difference but it has worked for me in the past.

Categories

Resources