WSH in VB.Net Express???? RRS feed

  • Question

  • Hello,

       I'm trying to do multiple things that seem rather tedious and or difficult with VB.NET Express.

    1. Run part of the code as an administrator
    2. Read/write NTFS permissions on files/folders
    3. Map Network Drive

    I can do all of these fairly easily with VBScript and WSH.  I was wondering if there is a way to access WSH from within VBScript or if it would be easier for me to have the VB program create the vbscript (WSH), run it, then delete it.



    Thursday, February 23, 2006 4:16 AM


All replies

  • Just an FYI, you're more likely to have all your questions answered if you split them up into different posts.

    For question #3 there are a couple different ways to do this. The below example uses an API function call:


    If you need to impersonate a user see the following:

    WindowsIdentity.Impersonate Method

    You might have to do a little bit of digging concerning question #2. I haven't worked with the new security classes in .NET but the following may get you started:


    Not sure how you were easily able to perform these tasks in VBScript unless you were using the FileSystemObject and ADSI (which you can also still use under Visual Basic).

    Thursday, February 23, 2006 1:32 PM
  • Thanks for the links and info.  Perhaps I should rephrase the question though.

    Of those three itmes in the prior post I want to know about doing them with WSH.

    Can I access WSH from VB.NET?

    Since WSH already has the capabilities to somewhat easily handle the NTFS, Map drives, and Run As I was just wondering if I could access and use the WSH objects from within VB.NET.


    Thursday, February 23, 2006 10:13 PM

  • If you already have a WSH script file then you should be able to execute it from VB.NET. It won't actually run in .NET, but will be executed by the script processor.

    Is this what you want to do?

    Friday, February 24, 2006 2:19 AM
  • Could you kindly give us some snipplet in how vb.net calls vbscript to run in a separate process? Thx.
    Wednesday, March 1, 2006 6:55 PM

  • Have you tried using the Process.Start method to launch a VBScript file (.vbs)?
    Wednesday, March 1, 2006 8:33 PM
  • I was trying to perform the prior action from within VB without calling an external script.

    I had a couple thoughts on this.

    1. I could try and figure out all the API Calls and such.  Not being a programmer this was a good sized learning curve.  I got confused reading the impersonate bit.
    2. I could try and use the scripting objects directly in VB.  Didn't know to what extent they were/are supported.
    3. I could get all the info I need and then hav VB write a VBS/WSH Script file on the fly and then have VB run it.  This way I could have one exe and that's it.

    I have realized that I can use most script command directly in VB.  I can use the createobject to grab FileSystemObject, WScript.Shell, etc.  I'm just trying to see what all functionality I have.  I'm hoping that since I can write a WSH script to perform everything I wanted to do that I can do the same from within VB. 

    There is one thing I have noticed.  Even though the objects are created successfully and work with some tests that I have done... The IntelliCode thingy doesn't pop up the objects options.  Is there a way I can use the WScript, FSO, etc and have the IntelliCode do the popup like it does for everything else?

    Wednesday, March 1, 2006 10:05 PM

  • If Intellisense isn't working for you it sounds like you're late binding to the objects. To support Intellisense you have to early bind by adding the COM library references to your project and then explicitly declaring the objects by their data type in code.

    Thursday, March 2, 2006 2:36 AM
  • How do I do what you're talking about?  Right now I'm just doing the following

    Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click

    Dim sh, fso
    sh = CreateObject(
    fso = CreateObject(

    End Sub


    Thursday, March 2, 2006 3:09 AM

  • See the below article. It describes how to add the COM reference to your project and declare the objects to support early binding and Intellisense.

    Drives and Directories and Files! Oh, My!


    Thursday, March 2, 2006 12:56 PM
  • Thanks for the link.  I should be able to use the easier WSH objects to most of what I want.  WSH doesn't handle the NTFS permissions too well but I did find a free COM component that does.


    Thursday, March 2, 2006 1:44 PM

  • Yeah, if you're using WSH then ADSI is the most commonly used object library. My guess is that the COM component you found probably makes it a bit easier. However, if you're interested in a bit more info you can check out the article below.

    Scripting NTFS permisions with ADSI (Part 1)

    Microsoft introduced the System.Security.AccessControl namespace in 2005 to handle this.


    Thursday, March 2, 2006 5:24 PM