c-sharp's class does not outputs anything

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Locked
Message
Author
WiVi71
Posts: 19
Joined: 06 Jan 2020 02:33

c-sharp's class does not outputs anything

#1 Post by WiVi71 » 04 Oct 2020 16:54

Since VBScript's Sendkey doesn't support UTF-8 characters, I am making a code uses C-Sharp's SendKeys.SendWait.
Also, to prevent malicious use, I am adding simple passwords checks.

but there was a problem while doing this.

Code: Select all

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;

class CheckEncodedKey
{
	static void ChkKeynArg(string[] args)
	{
		Console.WriteLine("hello");
		System.Environment.Exit(50);  
	}
}
// https://www.c-sharpcorner.com/forums/sendingenter-in-console-project
class TextSendKeys
{
	[DllImport("user32.dll")]
	static extern bool SetForegroundWindow(IntPtr hWnd);

	static void Main()
	{
		Process[] procs = Process.GetProcessesByName("cmd");
		foreach(Process proc in procs)
		{
		  if (proc.MainWindowTitle == "a")
		  {
			  SetForegroundWindow(proc.MainWindowHandle);
			  SendKeys.SendWait("ab~cde~");
		  }
		}
	}
}
In this code, class CheckEncodedKey does not echos, does not exits, and does not outputs exit code.
I want to put the code below to check the password in this part.

Code: Select all

		if (args.Length > 1)
		{
			string EncodedKey = "password";
			string EncodedArg = args[1];
			if (String.Equals(EncodedKey, EncodedArg))
			{
				// Console.WriteLine(args.Length)
			}
			else
			{Environment.Exit(1);}
		}
		else
			Environment.Exit(1);
What is the problem with this code?

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: c-sharp's class does not outputs anything

#2 Post by Squashman » 04 Oct 2020 19:48

This forum is mostly dedicated to Windows Batch files and we extend other scripting languages (Vbscript, Jscript, Powershell) with the Windows Operating System. I am closing this thread until the moderators can discuss if we are going to allow questions on other programming languages.

Locked