Re: VBscript and impersonation



Joe Kaplan wrote:
Are you using .NET 1.x or 2.0?

2.0

Impersonation does not extend to the
credentials used for new process creation, so that is why that isn't
working.

ok.

However, in .NET 2.0 that Start method now takes
credentials to solve this problem.

Do you mean Process.Start ? That doesn't work either. As you can see from my
example.

/jim


Joe K.


I've tried to run a VBscript with elevated privileges, but with no
success.
My code works fine, except if I try to run it using impersonation.

Have anyone made it work ? Will you try it on your installation to
see if it works? Shouldn't take more than a few minutes.

I have used the "Impersonation" setting in web.config.
I have tried Process.Start and specified username/password in
StartupInformation

When supplying username/password to Process.Start it calls an
unmanaged API, LogonUser, so I also tried calling that directly.

But vbscript simply won't start.
It gives me this error:
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'."

or "application failed to initialize properly (0x0000142)"

Googling for these suggested installing the latest version of
vbscript, or re-installing, or messing with registry-keys but
nothing helped. This is the code for a webform with a label and a button:
Protected Sub knpCommit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles knpCommit.Click
Dim myProcess As New Process
Dim output As String

With myProcess.StartInfo
.FileName = "c:\windows\system32\cscript.exe"
.Arguments = "c:\TestScript.vbs"
.UseShellExecute = False
.RedirectStandardOutput = True
End With

myProcess.Start()
Me.Label1.Text = "efter start"
output = myProcess.StandardOutput.ReadToEnd()
myProcess.WaitForExit()
Me.Label1.Text = output

myProcess.Dispose()

End Sub

With this in web.comfig it fails:
<identity impersonate="true" userName="myDomain\myUserName"
password="MyPassWord" />

This is the script in c:\TestScript.vbs:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\ScriptLog.txt", 2)

Set WshNetwork = WScript.CreateObject("WScript.Network")
objFile.WriteLine WshNetwork.UserName
objFIle.Close
WScript.Echo "Testscript 1: Username: " & WshNetwork.UserName


.


Quantcast