Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Impersonation & CScript problem.

Impersonation & CScript problem.

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasewindows-adminhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan S
    wrote on last edited by
    #1

    Hello, I've been trying to execute CSCRIPT.EXE through my asp.net application to execute some IIS admin scripts. To do this, CSCRIPT.EXE has to be ran by an administrator. // Put user code to initialize the page here WindowsImpersonationContext x = NetworkSecurity.ImpersonateUser("MACHINE_NAME_WOULD", "Administrator", "ADMINISTRATOR_PASSWORD_WOULD_GO_HERE", LogonType.LOGON32_LOGON_INTERACTIVE, LogonProvider.LOGON32_PROVIDER_DEFAULT); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "cscript.exe"; proc.StartInfo.Arguments = "c:\windows\system32\iisweb.vbs /query"; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; proc.Start(); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Additional code if you want to try it out for yourself: public enum LogonType : int { LOGON32_LOGON_INTERACTIVE = 2, LOGON32_LOGON_NETWORK = 3, LOGON32_LOGON_BATCH = 4, LOGON32_LOGON_SERVICE = 5, LOGON32_LOGON_UNLOCK = 7, LOGON32_LOGON_NETWORK_CLEARTEXT = 8, // Only for Win2K or higher LOGON32_LOGON_NEW_CREDENTIALS = 9 // Only for Win2K or higher }; public enum LogonProvider : int { LOGON32_PROVIDER_DEFAULT = 0, LOGON32_PROVIDER_WINNT35 = 1, LOGON32_PROVIDER_WINNT40 = 2, LOGON32_PROVIDER_WINNT50 = 3 }; class SecuUtil32 { [DllImport("advapi32.dll", SetLastError=true)] public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr TokenHandle); [DllImport("kernel32.dll", CharSet=CharSet.Auto)] public extern static bool CloseHandle(IntPtr handle); [DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)] public extern static bool DuplicateToken(IntPtr ExistingTokenHandle, int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle); } /// /// Summary description for NetworkSecurity. /// public class NetworkSecurity { public NetworkSecurity() { // // TODO: Add constructor logic here // } public static WindowsImpersonationContext

    M 1 Reply Last reply
    0
    • D Dan S

      Hello, I've been trying to execute CSCRIPT.EXE through my asp.net application to execute some IIS admin scripts. To do this, CSCRIPT.EXE has to be ran by an administrator. // Put user code to initialize the page here WindowsImpersonationContext x = NetworkSecurity.ImpersonateUser("MACHINE_NAME_WOULD", "Administrator", "ADMINISTRATOR_PASSWORD_WOULD_GO_HERE", LogonType.LOGON32_LOGON_INTERACTIVE, LogonProvider.LOGON32_PROVIDER_DEFAULT); System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo.FileName = "cscript.exe"; proc.StartInfo.Arguments = "c:\windows\system32\iisweb.vbs /query"; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.UseShellExecute = false; proc.Start(); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Response.Write(proc.StandardOutput.ReadLine()); Additional code if you want to try it out for yourself: public enum LogonType : int { LOGON32_LOGON_INTERACTIVE = 2, LOGON32_LOGON_NETWORK = 3, LOGON32_LOGON_BATCH = 4, LOGON32_LOGON_SERVICE = 5, LOGON32_LOGON_UNLOCK = 7, LOGON32_LOGON_NETWORK_CLEARTEXT = 8, // Only for Win2K or higher LOGON32_LOGON_NEW_CREDENTIALS = 9 // Only for Win2K or higher }; public enum LogonProvider : int { LOGON32_PROVIDER_DEFAULT = 0, LOGON32_PROVIDER_WINNT35 = 1, LOGON32_PROVIDER_WINNT40 = 2, LOGON32_PROVIDER_WINNT50 = 3 }; class SecuUtil32 { [DllImport("advapi32.dll", SetLastError=true)] public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr TokenHandle); [DllImport("kernel32.dll", CharSet=CharSet.Auto)] public extern static bool CloseHandle(IntPtr handle); [DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)] public extern static bool DuplicateToken(IntPtr ExistingTokenHandle, int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle); } /// /// Summary description for NetworkSecurity. /// public class NetworkSecurity { public NetworkSecurity() { // // TODO: Add constructor logic here // } public static WindowsImpersonationContext

      M Offline
      M Offline
      manishgour
      wrote on last edited by
      #2

      hi, did you check this article located at http://support.microsoft.com/default.aspx?scid=kb;EN-US;q306158#4 You need to give Grant the "Act as part of the operating system" privilege to the ASPNET account. HTH, Manish

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups