Access problems with System.Diagnostics.Process in webservice

Posted by Martin on Stack Overflow See other posts from Stack Overflow or by Martin
Published on 2010-04-29T10:32:48Z Indexed on 2010/04/29 10:37 UTC
Read the original article Hit count: 380

Filed under:
|

Hello everyone. I have problems with executing a process in a webservice method on a Windows Server 2003 machine. Here is the code:

        Dim target As String = "C:\dnscmd.exe"
    Dim fileInfo As System.IO.FileInfo = New System.IO.FileInfo(target)
    If Not fileInfo.Exists Then
        Throw New System.IO.FileNotFoundException("The requested file was not found: " + fileInfo.FullName)
    End If

    Dim startinfo As New System.Diagnostics.ProcessStartInfo("C:\dnscmd.exe")
    startinfo.UseShellExecute = False
    startinfo.Arguments = "\\MYCOMPUTER /recordadd mydomain.no " & dnsname & " CNAME myhost.mydomain.no"
    startinfo.UserName = "user1"
    Dim password As New SecureString()
    For Each c As Char In "secretpassword".ToCharArray()
        password.AppendChar(c)
    Next
    startinfo.Password = password
    Process.Start(startinfo)

I know the process is being executed because i use processmonitor.exe on the server and it tells me that c:\dnscmd.exe is called with the right parameters Full command line value from procmon is: "C:\dnscmd.exe" \MYCOMPUTER /recordadd mydomain.no mysubdomain CNAME myhost.mydomain.no The user of the created process on the server is NT AUTHORITY\SYSTEM.

BUT, the dns entry will not be added! Here is the weird thing: I KNOW the user (user1) I authenticate with has administrative rights (it's the same user I use to log on the machine with), but the user of the process in procmon says NT AUTHORITY\SYSTEM (which is not the user i use to authenticate).

Weirdest: If i log on to the server, copy the command line value read from the procmon logging, and paste it in a command line window, it works!

Reading procmon after this shows that user1 owns the dnscmd process.

Why doesn't user1 become owner of the process started with system.diagnostics.process?

Is the reason why the command doesn't work?

© Stack Overflow or respective owner

Related posts about dns

Related posts about .NET