Wednesday, 15 September 2010

C# - Process.Start - using global variable as password - "cannot convert from 'string' to 'System.Security.SecureString' -



C# - Process.Start - using global variable as password - "cannot convert from 'string' to 'System.Security.SecureString' -

i designed login form , wanted username , password entered stored variables phone call in other forms (overall programme collection of .exe files , powershell scripts want run username , password entered in login form).

at start of programme created "global variables" using code:

class usernameglobalvariable { public static string var = ""; } class passwordglobalvariable { public static string var = ""; }

in login form stored username , password entered these global variables way:

private void usernametextbox_textchanged(object sender, eventargs e) { usernameglobalvariable.var = usernametextbox.text; } private void passwordtextbox_textchanged(object sender, eventargs e) { passwordglobalvariable.var = passwordtextbox.text; }

when want start process phone call using code (to run username , password stored login form):

string filename = "c:\\hdatools\\ping2.exe"; string arguments = ""; string domain = "vantage"; private void button2_click(object sender, eventargs e) { process.start( filename, arguments, usernameglobalvariable.var, passwordglobalvariable.var, domain); }

the main error on line passwordglobalvariable.var, error says

argument 4: cannot convert 'string' 'system.security.securestring'

i've tried different ways seek convert `passwordglobalvariable.var' secure string, or give string variable contents , render variable secure string. i've run out of ideas. in advance help.

argument 4: cannot convert 'string' 'system.security.securestring'

because var string , not securestring, look:

class passwordglobalvariable { public static string var = ""; }

so alter to:

class passwordglobalvariable { public static securestring var; }

and later on, alter passwordtextbox_textchanged event-handler convert password string securestring:

private void passwordtextbox_textchanged(object sender, eventargs e) { securestring password = new securestring(); foreach (char c in passwordtextbox.text.tochararray()) { password.appendchar(c); } passwordglobalvariable.var = password; }

a little side-note: refrain using var word because 1 can confused c#'s var contextual keyword.

c# security global-variables process.start securestring

No comments:

Post a Comment