Re: OSQL UserName and PWd
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Fri, 22 Sep 2006 13:52:35 +0200
"gopal" <gopal.srini@xxxxxxxxx> wrote in message
news:1158921953.475752.251360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Willy
|
| I had tried the foll code, seems its working okay, but i have couple of
| points to be clarified, the following is the code, can you pls verify
| the code..
|
| I want the password to be entered as ******, not as actual characters,
| i am getting the output as
|
In this case you'll have to turn-off the console echo mode. There is no
support for this in the FCL, so you'll have to PInvoke some console API's.
Following is a sample.
using ...
using System.Runtime.InteropServices;
public class class1
{
[DllImport("Kernel32")]
extern static IntPtr GetStdHandle(int inp);
[DllImport("Kernel32")]
extern static bool GetConsoleMode(IntPtr handle, ref uint mode);
[DllImport("Kernel32")]
extern static bool SetConsoleMode(IntPtr handle, uint mode);
static uint ENABLE_ECHO_INPUT = 0x0004;
static void Main() {
...
password = GetPasswordFromConsole();
string osqlArgs = String.Format("....
...
} // end Main
static string GetPasswordFromConsole() {
IntPtr hCon = GetStdHandle(-10);
uint oldMode = 0;
GetConsoleMode(hCon, ref oldMode);
uint newMode = oldMode & ~ENABLE_ECHO_INPUT;
SetConsoleMode(hCon, newMode);
// Prompt user to enter password
Console.Write("Enter password: ");
string pwd = Console.ReadLine();
Console.WriteLine();
SetConsoleMode(hCon, oldMode);
return pwd;
}
| Enter User:sa
| Enter Password:sa
| Process output: 1> 2> 3> (1 row affected)
| Process output: (1 row affected)
|
| i want to supress the 1>2>3 and want to display only the number of rows
| affected as
| 1 row affected
|
Well, just parse the returned string, but I'm affraid you will have to do it
yourself. Hint take a look at the String.Index and String.IndexOf and
String.Substring methods.
Willy.
Willy.
.
- References:
- OSQL UserName and PWd
- From: gopal
- Re: OSQL UserName and PWd
- From: Willy Denoyette [MVP]
- Re: OSQL UserName and PWd
- From: gopal
- Re: OSQL UserName and PWd
- From: Willy Denoyette [MVP]
- Re: OSQL UserName and PWd
- From: gopal
- OSQL UserName and PWd
- Prev by Date: Re: declare array with a default value?
- Next by Date: Re: declare array with a default value?
- Previous by thread: Re: OSQL UserName and PWd
- Next by thread: Nice exceptions.
- Index(es):
Relevant Pages
|
Loading