G
Guest
Hi
I am trying to develop an web application that should use netsh dhcp to show information about our dhcp scope. The problem is that our dhcp server is different from our IIS (iis6).
I am trying to do this command via impersonation but I can't get the permissons to be right. I constantly get permission denied.
Below are the code used to execute the command and impersonation, is there anyone who know how to solve thos problem?
Best Regards Henrik Alstersjö
<Code>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If LogonUser(Session("User"), "RD", Session("Passw"), 3, LOGON32_PROVIDER_DEFAULT, token) = True Then
Dim tomte As String
Dim oImpContext As System.Security.Principal.WindowsImpersonationContext
oImpContext = System.Security.Principal.WindowsIdentity.Impersonate(token)
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString)
Dim proc As New System.Diagnostics.Process()
proc.StartInfo.FileName = "netsh"
proc.StartInfo.Arguments = "dhcp server \\semldsw2dhc078 show scope"
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
TextBox1.Text = proc.StandardOutput.ReadToEnd.ToString
proc.Close()
proc.Dispose()
oImpContext.Undo()
Else
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString)
TextBox1.Text = "Det gick fel"
End If
End Sub
Private Declare Auto Function LogonUser Lib "advapi32.dll" ( _
ByVal lpszUsername As String, _
ByVal lpszDomain As String, _
ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, _
ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) As Boolean
Const LOGON32_LOGON_INTERACTIVE As Long = 2
Const LOGON32_LOGON_NETWORK As Long = 3
Const LOGON32_PROVIDER_DEFAULT As Long = 0
Const LOGON32_PROVIDER_WINNT50 As Long = 3
Const LOGON32_PROVIDER_WINNT40 As Long = 2
Const LOGON32_PROVIDER_WINNT35 As Long = 1
Dim token As IntPtr
</Code>
I am trying to develop an web application that should use netsh dhcp to show information about our dhcp scope. The problem is that our dhcp server is different from our IIS (iis6).
I am trying to do this command via impersonation but I can't get the permissons to be right. I constantly get permission denied.
Below are the code used to execute the command and impersonation, is there anyone who know how to solve thos problem?
Best Regards Henrik Alstersjö
<Code>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If LogonUser(Session("User"), "RD", Session("Passw"), 3, LOGON32_PROVIDER_DEFAULT, token) = True Then
Dim tomte As String
Dim oImpContext As System.Security.Principal.WindowsImpersonationContext
oImpContext = System.Security.Principal.WindowsIdentity.Impersonate(token)
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString)
Dim proc As New System.Diagnostics.Process()
proc.StartInfo.FileName = "netsh"
proc.StartInfo.Arguments = "dhcp server \\semldsw2dhc078 show scope"
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
TextBox1.Text = proc.StandardOutput.ReadToEnd.ToString
proc.Close()
proc.Dispose()
oImpContext.Undo()
Else
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString)
TextBox1.Text = "Det gick fel"
End If
End Sub
Private Declare Auto Function LogonUser Lib "advapi32.dll" ( _
ByVal lpszUsername As String, _
ByVal lpszDomain As String, _
ByVal lpszPassword As String, _
ByVal dwLogonType As Integer, _
ByVal dwLogonProvider As Integer, _
ByRef phToken As IntPtr) As Boolean
Const LOGON32_LOGON_INTERACTIVE As Long = 2
Const LOGON32_LOGON_NETWORK As Long = 3
Const LOGON32_PROVIDER_DEFAULT As Long = 0
Const LOGON32_PROVIDER_WINNT50 As Long = 3
Const LOGON32_PROVIDER_WINNT40 As Long = 2
Const LOGON32_PROVIDER_WINNT35 As Long = 1
Dim token As IntPtr
</Code>