Button Click no result - c#

I was following a tutorial on XDA [http://forum.xda-developers.com/showthread.php?t=2042227] in regards to setting up your own android ADB GUI Toolkit in C#. I have the GUI setup right as we speak and the code compiles correctly but when I click the install APK button it does not install the APK to my device.
private void InstallAPK_Click(object sender, EventArgs e)
{
var process = Process.Start("CMD.exe", "/c adb install " + textBox1.Text);
process.WaitForExit();
MessageBox.Show(".APK is Installed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
No errors are found in this code it all works but its not actually executing the ADB command as it is told to. - Any advice would be helpful!

You need to add quotation marks around the file name - otherwise it would not properly process file names containing spaces.

Related

C# Windows form Application With PowerShell Automation Commands Restrictions

I am trying to create an app that would setup bitlocker PIN Programmatically.
the app works as well as the PowerShell Command, However, I am unfortunately unable to execute it.
I am getting the following Error when Executing:
"Application Attempted to perform an operation not allowed by the security policy. To grant this application the required permissions, contact your system administrator or use Microsoft .Net Configuration Tool"
private void Submit_Click(object sender, EventArgs e)
{
if (PIN.Text.Length < 20)
{
MessageBox.Show("Passwords must be at least 20 characters long.");
return;
}
else if (PIN2.Text != PIN.Text)
{
MessageBox.Show("Password & Confirmation are not identical, Please ensure that both Passwords are the same");
return;
}
else
{
PowerShell ps = PowerShell.Create();
ps.AddCommand("$PIN = \"" + PIN.Text + "\" | ConvertTo-SecureString -AsPlainText -Force; Enable-BitLocker -MountPoint \"C:\" -PIN $PIN -TPMAndPinProtector -SkipHardwareTest");
ps.Invoke();
MessageBox.Show("Your Pre-Boot PIN has now been Setup - Please reboot after 30 Minutes and login with your PIN");
Application.Exit();
I have set assembly: SecurityRules(SecurityRuleSet.Level1) but issue remains.
is it a GPO that would need to be amended at all? or would i be able to bypass in the App somehow?
Have you tried making an actual PowerShell script file and then running the file?
take a look at this

Clicking a button on a windows from from a webform

I have created a windows form program that does some Business Intelligence but have subsequently needed to access this via a webform. I am fairly new to programming so I don't know what can be achieved here. But essentially I am wanting someone to go on to the net and when the user presses a button it sends a message to the windows form executable in a file and tells it to run and then press a button on the form, which runs a method to generate images of graphs. Is this possible?
Here is the relevant code.
In the webform I have this button.
protected void rolloutSmartSheets(object sender, EventArgs e)
{
string message = string.Format("Starting processes");
ltMessage.Text = message;
Process process = new Process();
process.StartInfo.FileName = #"P:\Visual Studio 2013\Projects\Smartsheet\SmartsheetAPI\obj\Debug\SmartSheetAPI.exe";
process.Start();
message = string.Format("Ended all processes");
ltMessage.Text = message;
}
That runs the executable but it opens the windows form and I imagine if the executable is sitting on another computer wouldn't that open on that computer? In which case i want it to tell it to press this button on the windows form which runs the method I need and then the user doesn't need to worry about it.
public void commitToDatabase_Click(object sender, EventArgs e)
{
commitToDataBase();
}
If you are able to have the clients install something in advance, you can provide this functionality using a custom protocol handler.
Example protocol handler from MSDN Article
HKEY_CLASSES_ROOT
alert
(Default) = "URL:Alert Protocol"
URL Protocol = ""
DefaultIcon
(Default) = "alert.exe,1"
shell
open
command
(Default) = "C:\Program Files\Alert\alert.exe" "%1"
Then add a link onto your webform like this
href="alert://test"
As long as the client has the handler installed, both in the registry and the executable file, it will run C:\Program Files\Alert\alert.exe, passing "test" to it as the first paramater.
You can easily change this to provide the ability to run the local graph generator, and pass any parameters from the webform you might need.

getting the full filenames from all top directory files in a specific directory and suppressing the occuring error

I met a not expected problem with getting just the top directory full filenames from a specific directory. C# throws an error and doesn't list anything in the specific directory.
But MS DOS has not a problem with my command: *"dir C:\windows\prefetch\*.pf"
Visual Basics 6 old "Dir Function" also does it without complaining.
The "Windows Explorer" opens it up and doesn't ask anything from me. Also "Nirsofts Tool Suit" lists it instantly without any problem. No one of this tools needs to run with special permissions, just a double click on the application icon and ready is the task.
I looked around and found nothing here, what would answer this weird problem. My user can access the directory, if I go with any other application into it, now there is the question why C# throws
an "Unauthorized Access Exception" which is totally weird, since I have access in this folder.
I don't want to elevate my application with admin permissions for it nor create extra a xml for it to run it with highest privileges. The not trustful yellow elevation box must be avoided.
Now my question: How it comes that I can not list the filenames in this folder when all other
applications can do that.
What code do I need if "Directory.GetFiles()" fails?
Is there any flag or property in the framework directory class which allows my application access to the files, whatever.
Here my code which fails (using System.IO):
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text.Substring(0, 0); //clear the textBox1
//Unauthorized access exception and yellow bar in this line
foreach(string FileX in Directory.GetFiles(Path.Combine(Environment.GetEnvironmentVariable("windir"), "prefetch"), "*.pf"))
{
textBox1.Text += FileX;
}
}
Did I understand correctly that you only need the File-names with directory-names.
This code works for me, no elevations needed.
private void button1_Click(object sender, EventArgs e)
{
string folder = #"C:\windows\prefetch";
string filemask = #"*.pf";
string[] filelist = Directory.GetFiles(folder, (filemask));
//now use filelist[i] for any operations.
}

Launching JAR with Process.Start: javaw.exe runs but "nothing happens"?

Given the code. when the button is clicked nothing happens , i get no debug message etc in visual studio. However if i were to double click the .jar file in its folder i am able to run it. Anyone have any idea why?
Looking at Task manager when the button is clicked. javaw.exe is created but nothing happens.
private void btnKinderPuzzle_Click(object sender, RoutedEventArgs e)
{
// Check if this program is opened
if (IsProcessOpen("MTPuzzle"))
{
MessageBox.Show("KinderPuzzle is already running", "Kinder Package", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
Process.Start(Directory.GetCurrentDirectory() + "\\Puzzle\\PuzzleGame\\MTPuzzle.jar");
}
}
Process.Start("java.exe",
Path.Combine("-jar " + Directory.GetCurrentDirectory(),
"Puzzle\\PuzzleGame\\MTPuzzle.jar"));
The path may be not correct. You might use instead
Process.Start(Path.Combine(Directory.GetCurrentDirectory(), "Puzzle\\PuzzleGame\\MTPuzzle.jar"));
If stills, then I think the problem in the setting of Java. To solve this potential problem, create a file run.cmd near your jar file and write this code into:
java -jar "MTPuzzle.jar"
Then, use Process.Start to start the file run.cmd

Problem with running exe file from c#

When I execute an exe file (PVFProject15.exe), it reads the data from an input file (inputFile.txt) and print the results in another file (outputFile.txt). The exe file works well when I double click it; It opens the console window which stays opened until the output file is created. However, when I run (PVFProject15.exe) from c#, the console window opens and closes very quickly and the output file is never created.
I would really appreciate your help since I have been working to fix this for a whole day and never found the answer. Here is my code below.
private void button1_Click(object sender, EventArgs e)
{
Process runFortran = new Process();
try
{
runFortran.StartInfo.FileName = "C:\\temp\\trial\\PVFProject15.exe";
runFortran.Start();
runFortran.WaitForExit();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
Thank you in advance.
Safaa
Probably PVFProject15.exe needs current directory to be set to C:\temp\trial
If PVFProject15.exe writes to file using relative path, look for outputFile.txt in directory from which you start your main program-bootstrapper.
I also meet with same problem, when I try start some .exe and .hta from my C# based software.
I start to looking for solution and answer of Mike Mozhaev get to me right direction.
In your code you need to use:
StartInfo.WorkingDirectory = Convert.ToString( System.IO.Directory.GetParent(appPath));
So code have to be like this:
if (File.Exists(appPath))
{
Process runProcess = new Process();
runProcess.StartInfo.WorkingDirectory = Convert.ToString( System.IO.Directory.GetParent(appPath));
runProcess.StartInfo.UseShellExecute= true;
runProcess.StartInfo.FileName = appPath;
runProcess.Start();
}

Categories