|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Winform: Call a vbscript with elevated privilegesI am making a .NET 2.0 WinForms application.
It lets a "normal" user select one or more scripts to be run with Admin (sort of) privileges. And their actions get logged in a database. How do I run a script as another user? It's not super secret stuff we are talking about. Embedding the name and password of the Admin (sort of) account is enough. I saw this piece of code for calling calc.exe. How do I modify it to use a different user account? ms-help://MS.VSCC.v80/MS.MSDN.vAug06.en/ws_wminet_conc/html/b40d2a05-e631-4a09-97cb-881d452dc432.htm thx /jim Have a look at the StartupInformation you can pass into Process.Start. Here
you can specify username/password. --- Dominick Baier, DevelopMentor http://www.leastprivilege.com Show quoteHide quote > I am making a .NET 2.0 WinForms application. > > It lets a "normal" user select one or more scripts to be run with > Admin (sort of) privileges. And their actions get logged in a > database. > > How do I run a script as another user? > > It's not super secret stuff we are talking about. Embedding the name > and password of the Admin (sort of) account is enough. > > I saw this piece of code for calling calc.exe. How do I modify it to > use a different user account? > ms-help://MS.VSCC.v80/MS.MSDN.vAug06.en/ws_wminet_conc/html/b40d2a05-e > 631-4a09-97cb-881d452dc432.htm > > thx > /jim Dominick Baier wrote:
> Have a look at the StartupInformation you can pass into Perfect ! Thx a bunch.> Process.Start. Here you can specify username/password. /jim Dominick Baier wrote:
> Have a look at the StartupInformation you can pass into I am now switching to an ASP.NET web-based solution.> Process.Start. Here you can specify username/password. I have the files for the solution on a network-share. The following code works fine when I am in Visual Studio 2005 and hit F5. It uses the builtin http:\\localhost:1417 to run the app. My testscript echoes back the currentUsername. And it returns the supplied username. Perfect. But when I copy the solution to c:\inetpub\wwwroot and start a browser and goes to localhost/myapp it bombs with: Titlebar: "cscript.exe - Program error" Text: Failed to initialize program correctly (0xc0000142). Click ok to close the program." Dim myProcess As New Process Dim mypass As New System.Security.SecureString Dim output As String For Each ch As Char In "MyPassword" mypass.AppendChar(ch) Next With myProcess.StartInfo .Domain = MYDOMAIN .FileName = "c:\windows\system32\cscript.exe" .Arguments = "//Nologo " & PATH & "TestScript.vbs HelloWorld" .UserName = "MyUserName" .Password = mypass .UseShellExecute = False .RedirectStandardOutput = True End With myProcess.Start() output = myProcess.StandardOutput.ReadToEnd() myProcess.WaitForExit() tia /jim OK. Since supplying Process.Start with username/password didn't work, I
tried another approach: Impersonation via LogonUser. So I have 1. <code to start impersonation using LogonUser, and Impersonate> 2. my code to Process.Start as before, but this time without specifying a username/password. 3. <code to stop impersonation> but now I get this output: Microsoft Windows scripting version 5.6 (etc... the banner-info) followed by "Windows Script Host"... "Can't find script engine 'VBScript' for 'C:\test.vbs'." If I move 2 up before 1 & 3 the code works fine. c:\test.vbs is executed. The only "solutions" to this problem is reinstalling wscript or updating to the newest version, og regserver /s vscript.dll But that is on PCs where scripts doesn't work. It works ok. Just not when impersonating. /jim addendum.... If I go to a dosprompt and do
runas cmd.exe and supply the username/password I get a dosprompt and is logged in as the superuser. I can then do cscript.exe c:\test.vbs and it runs ok. So it shouldn't be a question of insufficient rights. /jim
FullTrust on network drive
Unhandled exception vs handled (security issue) Why am I getting errors when I want to rebuild the TreeView contro Login error when opening a deployed project User creation.... Forms Authentication with Active Directory, login control crashes Impersonation testing Security Exception Is there a function that I can call to validate a domain? How to show the windows 'Connect To' dialog from C# |
|||||||||||||||||||||||