VBscript and impersonation



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


.



Relevant Pages

  • Re: vbs or jscript?
    ... JavaScript and DHTML since 1995. ... This is done in 100% JScript, ... VBScript is ugly, is unstructured, has bad error handling, awkward ... Using VBScript you will be stuck with IE and windows scripting. ...
    (microsoft.public.scripting.wsh)
  • Re: VBscript and impersonation
    ... Can you tell if it is actually starting cscript with the correct user ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ... But vbscript simply won't start. ... Microsoft Windows scripting version 5.6 (etc... ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: VBscript and impersonation
    ... credentials used for new process creation, so that is why that isn't ... in .NET 2.0 that Start method now takes credentials to ... But vbscript simply won't start. ... Microsoft Windows scripting version 5.6 (etc... ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Best Beginners book
    ... After you get a book, and have learned a basic amount of VBScript, I ... highly recommend downloading and using Microsoft's Windows Scripting ... Host Documention found in MS's technet area (sorry I don't have a ...
    (microsoft.public.scripting.vbscript)
  • Re: vbs output to txt file
    ... Easiest is to code the VBScript to echo output to the console, ... Set objFSO = CreateObject ... should set that object to Nothing at the end of the script. ...
    (microsoft.public.scripting.wsh)