0

Tell me, in the program it is necessary to use the password of one of the users to start the program, but when I use the value of the variable with the password, the following error occurs: cannot convert from string to System.Secure.Security.SecureString; the value must be obtained from the variable, and not entered from the keyboard.




using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Security;

public class Example
{
    public static void Main()
    {
        string password = "password";

        try
        {
            Process.Start("Notepad.exe", "MyUser", password, "MYDOMAIN");
        }
        catch (Win32Exception e)
        {
            Console.WriteLine(e.Message);
        }

    }
}
9
  • why don't you search "c# convert string to securestring"? And why do you start notepad with a password? Commented Jan 27, 2023 at 4:36
  • learn.microsoft.com/en-us/dotnet/api/… Commented Jan 27, 2023 at 4:37
  • You are passing incorrect argument... look at the documentation of Process.Start. The 4th argument to this method is System.Security.SecureString password but you are passing MYDOMAIN instead. that's why you are getting this error. Commented Jan 27, 2023 at 4:38
  • @Chetan In 1st, 2nd and 4th arguments, ill write values from variables. The values ​​that I wrote in the code example are conditional Commented Jan 27, 2023 at 4:53
  • how that makes a difference? the 4th argument need to be of type SecureString and you are passing a string in the code. the arguments need to be passed with correct type. You need to read the documentation of the method from the link I shared and also go thru the suggested questions as duplicates to solve your problem. Commented Jan 27, 2023 at 5:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.