Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

Hope you are all doing well, i have been battlign with an issue for a while now, when i update all other attributes in ad using this code it works , however for the terminal services profile (which is built into AD ) with an array, i get a an erro as such

Unspecified error

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Runtime.InteropServices.COMException: Unspecified error


my code is like the following:
VB
Dim LDAPUser = "domain\Administrator"
Dim LDAPPass = "MyPassword"
Dim CurrentComputerADLocation = "CN=User\, Test,OU=Users,DC=domain,DC=net"
Dim User As New System.DirectoryServices.DirectoryEntry("" + CurrentComputerADLocation + "", LDAPUser, LDAPPass)
        Dim ProDir = "\\\\FILESERVERTEST\\UserData$\\TestUser1"
        Dim RDProfile = "\\\\FILESERVERTEST2\\RD_tsprofiles$\\"
             Try
            User.InvokeSet("TerminalServicesProfilePath", "" + RDProfile + "")
            User.InvokeSet("TerminalServicesHomeDirectory", "" + ProDir + "")
            User.InvokeSet("TerminalServicesHomeDrive", "H:")
            User.CommitChanges()
            User.Close()
            LabelStatus.ForeColor = System.Drawing.ColorTranslator.FromHtml("#256fe8")
            LabelStatus.Text = "User Account has been successfully labelled"
        Catch InvOpEx As InvalidOperationException

            Console.WriteLine(InvOpEx.Message)
            LabelStatus.Text = InvOpEx.Message
        End Try



i have even tried an invokeSet statement like this but still get same error

<br />
User.InvokeSet("TerminalServicesProfilePath", new object[] {RDProfile})<br />
User.InvokeSet("TerminalServicesHomeDirectory", new object[] {ProDir})<br />
User.InvokeSet("TerminalServicesHomeDrive", new object[] {"H:"})<br />


can anyone show me where i am going wrong please

any and all help is always appreciated

Thanks
Robert

What I have tried:

i have even tried an invokeSet statement like this but still get same error

VB
User.InvokeSet("TerminalServicesProfilePath", new object[] {RDProfile})
User.InvokeSet("TerminalServicesHomeDirectory", new object[] {ProDir})
User.InvokeSet("TerminalServicesHomeDrive", new object[] {"H:"})
<pre>
Posted
Comments
[no name] 23-May-17 14:18pm    
Catch whatever the exception is and find out exactly what it is. Until you do that, you can't fix it.
Member 12758480 23-May-17 14:24pm    
thanks i have got a Catch InvOpEx As InvalidOperationException which prints to a label but it doesnt show anything :(

do i have my catch statement in the wrong place ?
thanks
Member 12758480 23-May-17 14:37pm    
The only reason i ask about my catch statement is , as it is not displaying anything. the error screen only shows the problem of currently being on the following line

User.InvokeSet("TerminalServicesProfilePath", "" + RDProfile + "")
[no name] 23-May-17 15:39pm    
No you are catching the wrong exception.
Member 12758480 23-May-17 14:44pm    
thanks for your insight here, it is really appreciated, i got it to show me some sort of error code now

Error HRESULT E_FAIL has been returned from a call to a COM component.

but i dont find anything useful.

my catch statement is as follows :
       Catch

            Dim InterEx As New System.Runtime.InteropServices.COMException

            LabelStatus.Text = InterEx.Message.ToString 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900