VB.net component process1 provide password

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DrAvi
    New Member
    • May 2010
    • 3

    VB.net component process1 provide password

    I'm trying to open MS Access application (open as independent application, I don't need to read date from it to my VB...) from my VB.net form and to provide MS Access the password.
    I tried to use vb.net component process1 but I couldn’t write the password without vb.net errors.

    The simple code I used:

    Code:
    Me.Process1.StartInfo.FileName = "c:\dummy.mdb"
    Me.Process1.StartInfo.Password = "1234" – (The error is: "Value of type string cannot be converted to system.security.securestring")
    Me.Process1.Start()
    How can I solve it?
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    I don't mean to sound condescending here, but read and understand the error. "1234" is a string, and Me.Process1.Sta rtInfo.Password is a SecureString.

    I'm going to go out on a limb here and suggest looking in to System.Security .SecureString. I'll wager a significant amount that you need to be instantiating a secure string instead of a straight string

    Beware this code example assumes that you have already got the string in memory. This is inherently insecure and should be avoided where possible. Given the assumption that you probably already have the string in memory, I'm not too concerned about the security implications of building the SecureString from the string. You really should instantiate it long hand though, passing each char in as the user types it so that the password doesn't exist anywhere in memory in a readable format:

    Code:
    Shared Process1 As New Process()
    
    Private Shared Function CreateSecureString(ByVal str As String) As SecureString
      Dim s = New SecureString()
      Array.ForEach(Of Char)(str.ToCharArray(), Function(c) Do
        s.AppendChar(c)
      End Function)
      Return s
    End Function
    Private Shared Sub Main(ByVal args As String())
      Using s = CreateSecureString("1234")
        Process1.StartInfo.FileName = "C:\Dummy.mdb"
        Process1.StartInfo.Password = CreateSecureString("1234")
        Process1.Start()
      End Using
    End Sub

    Comment

    • DrAvi
      New Member
      • May 2010
      • 3

      #3
      Hi,

      Thank you for your answer my friend.
      You are not being condescending; it is me being totally green with VB.net. I usually work with Access and VBA. VBA and VB.net are similar but different… I saw and understood the error msg, but didn’t know how to resolve it.

      I've tried to use your suggestion, but there still is an error msg in this line:
      Array.ForEach(O f Char) (str.ToCharArra y(), Function(c) do s.AppendChar(c) End Function)

      The "do" creates the error, suggesting that "expression expected".
      Again, the solution may be simple, but I can't find my hands and legs here with the language differences….

      Regards,
      DrAvi

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        Originally posted by DrAvi
        Hi,

        Thank you for your answer my friend.
        You are not being condescending; it is me being totally green with VB.net. I usually work with Access and VBA. VBA and VB.net are similar but different… I saw and understood the error msg, but didn’t know how to resolve it.

        I've tried to use your suggestion, but there still is an error msg in this line:
        Array.ForEach(O f Char) (str.ToCharArra y(), Function(c) do s.AppendChar(c) End Function)

        The "do" creates the error, suggesting that "expression expected".
        Again, the solution may be simple, but I can't find my hands and legs here with the language differences….

        Regards,
        DrAvi
        What version of .NET are you running? It probably has to do with the version you're using not supporting lambda expressions. Let me code it a different way to avoid that:

        Code:
        Private Shared Function CreateSecureString(ByVal str As String) As SecureString
            Dim s = New SecureString
            For Each c As Char In str
                s.AppendChar(c)
            Next
            Return s
        End Function

        Comment

        • DrAvi
          New Member
          • May 2010
          • 3

          #5
          The new code solved the previous error msg. now, new one came.. :)

          The situation is this: The file I'm trying to open is MDB or Accdb, not EXE. When I'm trying to open MDB application with process1, without password, and without the above line codes, the MDB application gets open. from that I understand that process1 can hadle opening MDB applications.

          When I'm adding the code above I'm getting errors. Using the code as it is returns the following error: "The Process object must have the UseShellExecute property set to false in order to start a process as a user"

          Ok, so I added a line – Process1.StartI nfo.UseShellExe cute = False
          But now, new error: "The specified executable is not a valid Win32 application"

          Ok again, I added to the code the full path of access, changing the fileName line to:
          Process1.StartI nfo.FileName = "C:\Program Files\Microsoft Office\Office12 \MSACCESS.EXE c:\dummy.mdb"
          And now, surprise, new error: win32Exception was unhandled – wrong file name, directory name or syntax

          My goodness… all I need is to open a simple MDB application
          (Oh, I'm running the code on visual basic 2008 express edition)

          Comment

          Working...